ref: a96abc307995afc09f637c905807c0c5203ab874
parent: 7a02e4865c1601ea3576df6196857e1b233c93d5
author: Runxi Yu <me@runxiyu.org>
date: Fri Feb 20 23:17:32 EST 2026
objectstore/loose: We should receive the objects directory, not repo root
--- a/objectstore/loose/loose_test.go
+++ b/objectstore/loose/loose_test.go
@@ -5,6 +5,7 @@
"errors"
"io"
"os"
+ "path/filepath"
"strings"
"testing"
@@ -18,9 +19,10 @@
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() })--- a/objectstore/loose/paths.go
+++ b/objectstore/loose/paths.go
@@ -11,13 +11,13 @@
"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.
--- 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,11 +7,12 @@
"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.
@@ -18,7 +19,7 @@
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
--
⑨