diff options
| author | 2026-03-04 12:52:26 +0800 | |
|---|---|---|
| committer | 2026-03-04 12:52:26 +0800 | |
| commit | b3028bc65ac03b0bb4a88482519fb45700c675f3 (patch) | |
| tree | 137391bcb8a0c7f63aefb0fc7221720ae6f894d2 /refstore/packed/store.go | |
| parent | repository: Split (diff) | |
| signature | No signature | |
refstore/packed: Split
Diffstat (limited to 'refstore/packed/store.go')
| -rw-r--r-- | refstore/packed/store.go | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/refstore/packed/store.go b/refstore/packed/store.go index 5ab9d602..92f69ec6 100644 --- a/refstore/packed/store.go +++ b/refstore/packed/store.go @@ -2,11 +2,6 @@ package packed import ( - "fmt" - "os" - "path" - - "codeberg.org/lindenii/furgit/objectid" "codeberg.org/lindenii/furgit/ref" "codeberg.org/lindenii/furgit/refstore" ) @@ -18,102 +13,3 @@ type Store struct { } var _ refstore.Store = (*Store)(nil) - -// New parses packed-refs from one repository root using the given object ID -// algorithm. -func New(root *os.Root, algo objectid.Algorithm) (*Store, error) { - if algo.Size() == 0 { - return nil, objectid.ErrInvalidAlgorithm - } - - packedRefs, err := root.Open("packed-refs") - if err != nil { - return nil, fmt.Errorf("refstore/packed: open packed-refs: %w", err) - } - - defer func() { _ = packedRefs.Close() }() - - byName, ordered, err := parsePackedRefs(packedRefs, algo) - if err != nil { - return nil, err - } - - return &Store{ - byName: byName, - ordered: ordered, - }, nil -} - -// Resolve resolves a packed reference name to a detached ref. -func (store *Store) Resolve(name string) (ref.Ref, error) { - detached, ok := store.byName[name] - if !ok { - return nil, refstore.ErrReferenceNotFound - } - - return detached, nil -} - -// ResolveFully resolves a packed reference name to a detached ref. -// -// Packed refs are detached-only, so ResolveFully is equivalent to Resolve. -func (store *Store) ResolveFully(name string) (ref.Detached, error) { - detached, ok := store.byName[name] - if !ok { - return ref.Detached{}, refstore.ErrReferenceNotFound - } - - return detached, nil -} - -// List lists packed references matching pattern. -// -// Pattern uses path.Match syntax against full reference names. -// Empty pattern matches all references. -func (store *Store) List(pattern string) ([]ref.Ref, error) { - matchAll := pattern == "" - if !matchAll { - _, err := path.Match(pattern, "refs/heads/main") - if err != nil { - return nil, err - } - } - - refs := make([]ref.Ref, 0, len(store.ordered)) - for _, entry := range store.ordered { - if !matchAll { - matched, err := path.Match(pattern, entry.Name()) - if err != nil { - return nil, err - } - - if !matched { - continue - } - } - - refs = append(refs, entry) - } - - return refs, nil -} - -// Shorten returns the shortest unambiguous shorthand for a packed ref name. -func (store *Store) Shorten(name string) (string, error) { - _, ok := store.byName[name] - if !ok { - return "", refstore.ErrReferenceNotFound - } - - names := make([]string, 0, len(store.ordered)) - for _, entry := range store.ordered { - names = append(names, entry.Name()) - } - - return refstore.ShortenName(name, names), nil -} - -// Close releases resources associated with the backend. -func (store *Store) Close() error { - return nil -} |
