diff options
| author | 2026-02-21 11:33:40 +0800 | |
|---|---|---|
| committer | 2026-02-21 11:33:40 +0800 | |
| commit | 6cdf75c5a9e1f660aa2a86938be680c5db07ffd2 (patch) | |
| tree | f16f22cc51930e97eaeb73e1e436d8a4c331fabf /refstore/chain/chain.go | |
| parent | refstore/loose: Add loose refs implementation (diff) | |
| signature | No signature | |
refstore: Add ref shortening
Diffstat (limited to 'refstore/chain/chain.go')
| -rw-r--r-- | refstore/chain/chain.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/refstore/chain/chain.go b/refstore/chain/chain.go index b84aac55..0a78dc94 100644 --- a/refstore/chain/chain.go +++ b/refstore/chain/chain.go @@ -102,6 +102,30 @@ func (chain *Chain) List(pattern string) ([]ref.Ref, error) { return refs, nil } +// Shorten shortens a full reference name using the chain-visible namespace. +func (chain *Chain) Shorten(name string) (string, error) { + refs, err := chain.List("") + if err != nil { + return "", err + } + names := make([]string, 0, len(refs)) + found := false + for _, entry := range refs { + if entry == nil { + continue + } + full := entry.Name() + names = append(names, full) + if full == name { + found = true + } + } + if !found { + return "", refstore.ErrReferenceNotFound + } + return refstore.ShortenName(name, names), nil +} + // Close closes all backends and joins close errors. func (chain *Chain) Close() error { var errs []error |
