diff options
Diffstat (limited to 'refstore/chain')
| -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 |
