aboutsummaryrefslogtreecommitdiff
path: root/refstore/refstore.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-07 14:34:59 +0800
committerGravatar Runxi Yu2026-03-07 15:26:37 +0800
commite99bfdd873f2e083b5c5b53fdecaec35c90a70fe (patch)
tree3630b5b5bd2cea6b09bfed4659b925726d90ef82 /refstore/refstore.go
parentrefstore: Rename Store to ReadingStore (diff)
signatureNo signature
refstore: Add TransactionalStore
Diffstat (limited to 'refstore/refstore.go')
-rw-r--r--refstore/refstore.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/refstore/refstore.go b/refstore/refstore.go
index b9760ecf..8d37b427 100644
--- a/refstore/refstore.go
+++ b/refstore/refstore.go
@@ -4,6 +4,7 @@ package refstore
import (
"errors"
+ "codeberg.org/lindenii/furgit/objectid"
"codeberg.org/lindenii/furgit/ref"
)
@@ -42,3 +43,53 @@ type ReadingStore interface {
// Close releases resources associated with the store.
Close() error
}
+
+// TransactionalStore begins atomic reference transactions.
+//
+// Not every readable reference store is writable. Implementations should only
+// satisfy TransactionalStore when they can stage and commit reference updates
+// atomically within that backend.
+type TransactionalStore interface {
+ // BeginTransaction creates one new mutable transaction.
+ BeginTransaction() (Transaction, error)
+}
+
+// Transaction stages reference updates for one atomic commit.
+//
+// Ordinary methods operate in dereference mode if name resolves to
+// a symbolic ref, the operation applies to the final referent rather
+// than to the symbolic ref itself.
+//
+// Symbolic methods operate on the named reference directly, without
+// dereferencing symbolic refs.
+type Transaction interface {
+ // Create creates one detached reference, requiring that the logical
+ // reference does not already exist.
+ Create(name string, newID objectid.ObjectID) error
+ // Update updates one detached reference, requiring that the current logical
+ // reference value matches oldID.
+ Update(name string, newID, oldID objectid.ObjectID) error
+ // Delete deletes one detached reference, requiring that the current logical
+ // reference value matches oldID.
+ Delete(name string, oldID objectid.ObjectID) error
+ // Verify verifies that the current logical reference value matches oldID.
+ Verify(name string, oldID objectid.ObjectID) error
+
+ // CreateSymbolic creates one symbolic reference, requiring that the named
+ // reference does not already exist.
+ CreateSymbolic(name, newTarget string) error
+ // UpdateSymbolic updates one symbolic reference directly, requiring that its
+ // current target matches oldTarget.
+ UpdateSymbolic(name, newTarget, oldTarget string) error
+ // DeleteSymbolic deletes one symbolic reference directly, requiring that its
+ // current target matches oldTarget.
+ DeleteSymbolic(name, oldTarget string) error
+ // VerifySymbolic verifies that the named symbolic reference currently points
+ // at oldTarget.
+ VerifySymbolic(name, oldTarget string) error
+
+ // Commit validates and applies all queued operations atomically.
+ Commit() error
+ // Abort abandons the transaction and releases any resources it holds.
+ Abort() error
+}