diff options
| author | 2025-11-16 00:00:00 +0000 | |
|---|---|---|
| committer | 2025-11-16 00:00:00 +0000 | |
| commit | 5c15542025c98f89d65331ff01b28daa389cf2a6 (patch) | |
| tree | 18a4cf7eb79ef81d63b9c658dc42b21e69e1282e | |
| parent | repo is thread safe (diff) | |
| signature | ||
Fix some docs and API types
| -rw-r--r-- | hash.go | 2 | ||||
| -rw-r--r-- | loose.go | 2 | ||||
| -rw-r--r-- | obj.go | 2 | ||||
| -rw-r--r-- | obj_tree.go | 6 | ||||
| -rw-r--r-- | pack_pack.go | 4 | ||||
| -rw-r--r-- | repo.go | 10 |
6 files changed, 18 insertions, 8 deletions
@@ -40,7 +40,7 @@ func (hash Hash) String() string { return hex.EncodeToString(hash.data[:hash.size]) } -// Bytes returns a mutable copy of the hash bytes. +// Bytes returns a copy of the hash's bytes. func (hash Hash) Bytes() []byte { return append([]byte(nil), hash.data[:hash.size]...) } @@ -21,7 +21,7 @@ func (repo *Repository) loosePath(id Hash) (string, error) { return filepath.Join("objects", hex[:2], hex[2:]), nil } -func (repo *Repository) looseRead(id Hash) (Object, error) { +func (repo *Repository) looseRead(id Hash) (StoredObject, error) { ty, body, err := repo.looseReadTyped(id) if err != nil { return nil, err @@ -92,7 +92,7 @@ func parseObjectBody(ty ObjectType, id Hash, body []byte, repo *Repository) (Sto } // ReadObject resolves an ID. -func (repo *Repository) ReadObject(id Hash) (Object, error) { +func (repo *Repository) ReadObject(id Hash) (StoredObject, error) { obj, err := repo.looseRead(id) if err == nil { return obj, nil diff --git a/obj_tree.go b/obj_tree.go index 7b04b231..d4246285 100644 --- a/obj_tree.go +++ b/obj_tree.go @@ -149,12 +149,12 @@ func (tree *Tree) Entry(name []byte) *TreeEntry { // // Lookups are recursive. // It returns nil if no such entry exists. -func (tree *Tree) EntryRecursive(repo *Repository, path [][]byte) (*TreeEntry, error) { +func (sTree *StoredTree) EntryRecursive(repo *Repository, path [][]byte) (*TreeEntry, error) { if len(path) == 0 { return nil, errors.New("furgit: tree: empty path") } - currentTree := tree + currentTree := sTree for i, part := range path { entry := currentTree.Entry(part) if entry == nil { @@ -167,7 +167,7 @@ func (tree *Tree) EntryRecursive(repo *Repository, path [][]byte) (*TreeEntry, e if err != nil { return nil, err } - nextTree, ok := obj.(*Tree) + nextTree, ok := obj.(*StoredTree) if !ok { return nil, fmt.Errorf("furgit: tree: expected tree object at %s, got %T", part, obj) // TODO: It may be useful to check the mode instead of reporting diff --git a/pack_pack.go b/pack_pack.go index 15eedf60..5c2c8628 100644 --- a/pack_pack.go +++ b/pack_pack.go @@ -25,7 +25,7 @@ type packlocation struct { Offset uint64 } -func (repo *Repository) packRead(id Hash) (Object, error) { +func (repo *Repository) packRead(id Hash) (StoredObject, error) { loc, err := repo.packIndexFind(id) if err != nil { return nil, err @@ -64,7 +64,7 @@ func (repo *Repository) packIndexFind(id Hash) (packlocation, error) { return packlocation{}, ErrNotFound } -func (repo *Repository) packReadAt(loc packlocation, want Hash) (Object, error) { +func (repo *Repository) packReadAt(loc packlocation, want Hash) (StoredObject, error) { ty, body, err := repo.packBodyResolveAtLocation(loc) if err != nil { return nil, err @@ -16,6 +16,9 @@ import ( // // It is safe to access the same Repository from multiple goroutines // without additional synchronization. +// +// Objects derived from a Repository must not be used after the Repository +// has been closed. type Repository struct { rootPath string hashSize int @@ -82,6 +85,13 @@ func OpenRepository(path string) (*Repository, error) { return &Repository{rootPath: path, hashSize: hashSize}, nil } +// Close closes the repository, releasing any resources associated with it. +// +// It is safe to call Close multiple times; subsequent calls will have no +// effect. +// +// Close invalidates any objects derived from the Repository as it; +// using them may cause segmentation faults or other undefined behavior. func (repo *Repository) Close() error { var closeErr error repo.closeOnce.Do(func() { |
