aboutsummaryrefslogtreecommitdiff
path: root/refstore/shorten.go
diff options
context:
space:
mode:
Diffstat (limited to 'refstore/shorten.go')
-rw-r--r--refstore/shorten.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/refstore/shorten.go b/refstore/shorten.go
index 26fa82c0..250ab01f 100644
--- a/refstore/shorten.go
+++ b/refstore/shorten.go
@@ -20,17 +20,22 @@ func (rule shortenRule) match(name string) (string, bool) {
if !strings.HasPrefix(name, rule.prefix) {
return "", false
}
+
if !strings.HasSuffix(name, rule.suffix) {
return "", false
}
+
short := strings.TrimPrefix(name, rule.prefix)
+
short = strings.TrimSuffix(short, rule.suffix)
if short == "" {
return "", false
}
+
if rule.prefix+short+rule.suffix != name {
return "", false
}
+
return short, true
}
@@ -47,6 +52,7 @@ func ShortenName(name string, all []string) string {
if full == "" {
continue
}
+
names[full] = struct{}{}
}
@@ -55,20 +61,26 @@ func ShortenName(name string, all []string) string {
if !ok {
continue
}
+
ambiguous := false
+
for j := range shortenRules {
if j == i {
continue
}
+
full := shortenRules[j].render(short)
if _, found := names[full]; found {
ambiguous = true
+
break
}
}
+
if !ambiguous {
return short
}
}
+
return name
}