aboutsummaryrefslogtreecommitdiff
path: root/refstore/files/transaction_verify_refnames.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-07 18:09:20 +0800
committerGravatar Runxi Yu2026-03-07 18:17:54 +0800
commite667c3c52a535ee67fe895bb0240fbad6e920087 (patch)
tree0815f7cc9b2c4a06d00722bce4c3ac57c515288b /refstore/files/transaction_verify_refnames.go
parentreceivepack: Connect protocol with service (diff)
signatureNo signature
refstore/files: Accept timeout instead of reading from config
And split things up again.
Diffstat (limited to 'refstore/files/transaction_verify_refnames.go')
-rw-r--r--refstore/files/transaction_verify_refnames.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/refstore/files/transaction_verify_refnames.go b/refstore/files/transaction_verify_refnames.go
new file mode 100644
index 00000000..2efc872a
--- /dev/null
+++ b/refstore/files/transaction_verify_refnames.go
@@ -0,0 +1,40 @@
+package files
+
+import (
+ "fmt"
+ "strings"
+)
+
+func verifyRefnameAvailable(name string, existing map[string]struct{}, writes []string, deleted map[string]struct{}) error {
+ for existingName := range existing {
+ if existingName == name {
+ continue
+ }
+
+ if _, skip := deleted[existingName]; skip {
+ continue
+ }
+
+ if refnamesConflict(name, existingName) {
+ return fmt.Errorf("refstore/files: reference name conflict between %q and %q", name, existingName)
+ }
+ }
+
+ for _, other := range writes {
+ if other == name {
+ continue
+ }
+
+ if refnamesConflict(name, other) {
+ return fmt.Errorf("refstore/files: reference name conflict between %q and %q", name, other)
+ }
+ }
+
+ return nil
+}
+
+func refnamesConflict(left, right string) bool {
+ return left == right ||
+ strings.HasPrefix(left, right+"/") ||
+ strings.HasPrefix(right, left+"/")
+}