aboutsummaryrefslogtreecommitdiff
path: root/refstore/chain
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-21 11:33:40 +0800
committerGravatar Runxi Yu2026-02-21 11:33:40 +0800
commit6cdf75c5a9e1f660aa2a86938be680c5db07ffd2 (patch)
treef16f22cc51930e97eaeb73e1e436d8a4c331fabf /refstore/chain
parentrefstore/loose: Add loose refs implementation (diff)
signatureNo signature
refstore: Add ref shortening
Diffstat (limited to 'refstore/chain')
-rw-r--r--refstore/chain/chain.go24
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