aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commit9ac827977b8f430906110ecd2030324248fff604 (patch)
treeb0f8fdb46252bef429beb27190a2cfc0cbd42540 /repo.go
parentREADME: Add my Villosa instance (diff)
signature
Support multiple hash sizes in one build
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/repo.go b/repo.go
index c0d056bc..fb835edb 100644
--- a/repo.go
+++ b/repo.go
@@ -1,6 +1,7 @@
package furgit
import (
+ "fmt"
"os"
"path/filepath"
"sync"
@@ -9,6 +10,7 @@ import (
// Repository represents the root of a Git repository.
type Repository struct {
rootPath string
+ HashSize int
packIdxOnce sync.Once
packIdx []*packIndex
@@ -22,8 +24,10 @@ type Repository struct {
closeOnce sync.Once
}
-// OpenRepository opens the repository at the provided path.
-func OpenRepository(path string) (*Repository, error) {
+// OpenRepository opens the repository at the provided path with the specified hash size.
+// This will be replaced later with a function that auto-detects the hash size based
+// on the git configuration.
+func OpenRepository(path string, hashSize int) (*Repository, error) {
fi, err := os.Stat(path)
if err != nil {
return nil, err
@@ -31,7 +35,10 @@ func OpenRepository(path string) (*Repository, error) {
if !fi.IsDir() {
return nil, ErrInvalidObject
}
- return &Repository{rootPath: path}, nil
+ if _, ok := hashFuncs[hashSize]; !ok {
+ return nil, fmt.Errorf("furgit: unsupported hash size %d", hashSize)
+ }
+ return &Repository{rootPath: path, HashSize: hashSize}, nil
}
func (r *Repository) Close() error {