From a0d2b3a238d6e5dcdedb816cf838dd8fe003c632 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 7 Mar 2026 16:25:36 +0800 Subject: refstore: Split files --- refstore/doc.go | 2 ++ refstore/errors.go | 7 ++++ refstore/reading.go | 29 +++++++++++++++ refstore/refstore.go | 89 ----------------------------------------------- refstore/transaction.go | 43 +++++++++++++++++++++++ refstore/transactional.go | 11 ++++++ 6 files changed, 92 insertions(+), 89 deletions(-) create mode 100644 refstore/doc.go create mode 100644 refstore/errors.go create mode 100644 refstore/reading.go delete mode 100644 refstore/refstore.go create mode 100644 refstore/transaction.go create mode 100644 refstore/transactional.go (limited to 'refstore') diff --git a/refstore/doc.go b/refstore/doc.go new file mode 100644 index 00000000..3d6f3908 --- /dev/null +++ b/refstore/doc.go @@ -0,0 +1,2 @@ +// Package refstore provides interfaces for reference storage backends. +package refstore diff --git a/refstore/errors.go b/refstore/errors.go new file mode 100644 index 00000000..45583440 --- /dev/null +++ b/refstore/errors.go @@ -0,0 +1,7 @@ +package refstore + +import "errors" + +// ErrReferenceNotFound indicates that a reference does not exist in a backend. +// TODO: Interface error? Just like object not found in objectstore. +var ErrReferenceNotFound = errors.New("refstore: reference not found") diff --git a/refstore/reading.go b/refstore/reading.go new file mode 100644 index 00000000..eb499deb --- /dev/null +++ b/refstore/reading.go @@ -0,0 +1,29 @@ +package refstore + +import "codeberg.org/lindenii/furgit/ref" + +// ReadingStore reads Git references. +type ReadingStore interface { + // Resolve resolves a reference name to either a symbolic or detached ref. + // + // Implementations should return value forms (ref.Detached or ref.Symbolic), + // not pointer forms. + // If the reference does not exist, implementations should return + // ErrReferenceNotFound. + Resolve(name string) (ref.Ref, error) + // ResolveFully resolves a reference name to a detached object ID. + // + // Implementations may use backend-local lookup semantics for symbolic hops. + // Callers that need cross-backend symbolic resolution (for example in a + // chain of stores) should prefer repeatedly calling Resolve. + // + // ResolveFully resolves symbolic references only. It does not imply peeling + // annotated tag objects. + ResolveFully(name string) (ref.Detached, error) + // List returns references matching pattern. + // + // The exact pattern language is backend-defined. + List(pattern string) ([]ref.Ref, error) + // Close releases resources associated with the store. + Close() error +} diff --git a/refstore/refstore.go b/refstore/refstore.go deleted file mode 100644 index a952ae22..00000000 --- a/refstore/refstore.go +++ /dev/null @@ -1,89 +0,0 @@ -// Package refstore provides interfaces for reference storage backends. -package refstore - -import ( - "errors" - - "codeberg.org/lindenii/furgit/objectid" - "codeberg.org/lindenii/furgit/ref" -) - -// ErrReferenceNotFound indicates that a reference does not exist in a backend. -// TODO: Interface error? Just like object not found in objectstore. -var ErrReferenceNotFound = errors.New("refstore: reference not found") - -// ReadingStore reads Git references. -type ReadingStore interface { - // Resolve resolves a reference name to either a symbolic or detached ref. - // - // Implementations should return value forms (ref.Detached or ref.Symbolic), - // not pointer forms. - // If the reference does not exist, implementations should return - // ErrReferenceNotFound. - Resolve(name string) (ref.Ref, error) - // ResolveFully resolves a reference name to a detached object ID. - // - // Implementations may use backend-local lookup semantics for symbolic hops. - // Callers that need cross-backend symbolic resolution (for example in a - // chain of stores) should prefer repeatedly calling Resolve. - // - // ResolveFully resolves symbolic references only. It does not imply peeling - // annotated tag objects. - ResolveFully(name string) (ref.Detached, error) - // List returns references matching pattern. - // - // The exact pattern language is backend-defined. - List(pattern string) ([]ref.Ref, error) - // 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 -} diff --git a/refstore/transaction.go b/refstore/transaction.go new file mode 100644 index 00000000..539229c9 --- /dev/null +++ b/refstore/transaction.go @@ -0,0 +1,43 @@ +package refstore + +import "codeberg.org/lindenii/furgit/objectid" + +// 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 +} diff --git a/refstore/transactional.go b/refstore/transactional.go new file mode 100644 index 00000000..8f5c32cd --- /dev/null +++ b/refstore/transactional.go @@ -0,0 +1,11 @@ +package refstore + +// 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) +} -- cgit v1.3.1-10-gc9f91