diff options
| author | 2026-02-21 04:17:32 +0800 | |
|---|---|---|
| committer | 2026-02-21 04:17:32 +0800 | |
| commit | a96abc307995afc09f637c905807c0c5203ab874 (patch) | |
| tree | 2e78f0068eba90b33220e4c871ba27ef1e1d9c52 /objectstore/loose | |
| parent | objectstore/loose: Add testing (diff) | |
| signature | No signature | |
objectstore/loose: We should receive the objects directory, not repo root
Diffstat (limited to 'objectstore/loose')
| -rw-r--r-- | objectstore/loose/loose_test.go | 6 | ||||
| -rw-r--r-- | objectstore/loose/paths.go | 4 | ||||
| -rw-r--r-- | objectstore/loose/store.go | 9 |
3 files changed, 11 insertions, 8 deletions
diff --git a/objectstore/loose/loose_test.go b/objectstore/loose/loose_test.go index 5302257a..9265aca2 100644 --- a/objectstore/loose/loose_test.go +++ b/objectstore/loose/loose_test.go @@ -5,6 +5,7 @@ import ( "errors" "io" "os" + "path/filepath" "strings" "testing" @@ -18,9 +19,10 @@ import ( func openLooseStore(t *testing.T, repoPath string, algo objectid.Algorithm) *loose.Store { t.Helper() - root, err := os.OpenRoot(repoPath) + objectsPath := filepath.Join(repoPath, "objects") + root, err := os.OpenRoot(objectsPath) if err != nil { - t.Fatalf("OpenRoot(%q): %v", repoPath, err) + t.Fatalf("OpenRoot(%q): %v", objectsPath, err) } t.Cleanup(func() { _ = root.Close() }) diff --git a/objectstore/loose/paths.go b/objectstore/loose/paths.go index 0e4b7d05..7c8bae92 100644 --- a/objectstore/loose/paths.go +++ b/objectstore/loose/paths.go @@ -11,13 +11,13 @@ import ( "codeberg.org/lindenii/furgit/objectstore" ) -// objectPath returns the loose object path for id. +// objectPath returns the loose object path for id relative to the objects root. func (store *Store) objectPath(id objectid.ObjectID) (string, error) { if id.Algorithm() != store.algo { return "", fmt.Errorf("objectstore/loose: object id algorithm mismatch: got %s want %s", id.Algorithm(), store.algo) } hex := id.String() - return path.Join("objects", hex[:2], hex[2:]), nil + return path.Join(hex[:2], hex[2:]), nil } // openObject opens the loose object file for id. diff --git a/objectstore/loose/store.go b/objectstore/loose/store.go index 01341a45..b06d8a78 100644 --- a/objectstore/loose/store.go +++ b/objectstore/loose/store.go @@ -1,4 +1,4 @@ -// Package loose provides loose-object reads from a repository root. +// Package loose provides loose-object reads from a Git objects directory. package loose import ( @@ -7,18 +7,19 @@ import ( "codeberg.org/lindenii/furgit/objectid" ) -// Store reads loose Git objects from a repository root. +// Store reads loose Git objects from an objects directory root. // // Store does not own root. Callers are responsible for closing root. type Store struct { - // root is the repository root capability used for all object file access. + // root is the objects directory capability used for all object file access. + // Object files are opened by relative paths like "<first2>/<rest>". // Store does not own this root. root *os.Root // algo is the expected object ID algorithm for lookups. algo objectid.Algorithm } -// New creates a loose-object store rooted at root for algo. +// New creates a loose-object store rooted at an objects directory for algo. func New(root *os.Root, algo objectid.Algorithm) (*Store, error) { if algo.Size() == 0 { return nil, objectid.ErrInvalidAlgorithm |
