aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commit5c15542025c98f89d65331ff01b28daa389cf2a6 (patch)
tree18a4cf7eb79ef81d63b9c658dc42b21e69e1282e
parentrepo is thread safe (diff)
signature
Fix some docs and API types
-rw-r--r--hash.go2
-rw-r--r--loose.go2
-rw-r--r--obj.go2
-rw-r--r--obj_tree.go6
-rw-r--r--pack_pack.go4
-rw-r--r--repo.go10
6 files changed, 18 insertions, 8 deletions
diff --git a/hash.go b/hash.go
index 2278f7cc..068eb840 100644
--- a/hash.go
+++ b/hash.go
@@ -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]...)
}
diff --git a/loose.go b/loose.go
index 60cdfbc9..84ebd006 100644
--- a/loose.go
+++ b/loose.go
@@ -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
diff --git a/obj.go b/obj.go
index 7deb330e..8a7eccac 100644
--- a/obj.go
+++ b/obj.go
@@ -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
diff --git a/repo.go b/repo.go
index 05473252..0fdfa5dd 100644
--- a/repo.go
+++ b/repo.go
@@ -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() {