summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb.go4
-rw-r--r--repository.go27
2 files changed, 24 insertions, 7 deletions
diff --git a/odb.go b/odb.go
index eaa7872..acde696 100644
--- a/odb.go
+++ b/odb.go
@@ -17,6 +17,10 @@ type Odb struct {
ptr *C.git_odb
}
+type OdbBackend struct {
+ ptr *C.git_odb_backend
+}
+
func (v *Odb) Exists(oid *Oid) bool {
ret := C.git_odb_exists(v.ptr, oid.toC())
return ret != 0
diff --git a/repository.go b/repository.go
index 6dbe386..c65bd9d 100644
--- a/repository.go
+++ b/repository.go
@@ -15,7 +15,7 @@ type Repository struct {
ptr *C.git_repository
}
-type InitCustomBackend func(**C.git_repository, **C.git_odb) int
+type InitCustomBackend func(**C.git_odb_backend) int
func OpenRepository(path string) (*Repository, error) {
repo := new(Repository)
@@ -47,18 +47,31 @@ func InitRepository(path string, isbare bool) (*Repository, error) {
return repo, nil
}
-func InitRepositoryWCustomOdbBackend(initStrategy InitCustomBackend) (*Repository, *Odb, error) {
- // init return vars
- repo := new(Repository)
+func InitRepositoryWCustomOdbBackend(initStrategy InitCustomBackend, priority int) (*Repository, *Odb, error) {
+ // inits
+ repo := new(Repository)
odb := new(Odb)
+ backend := new(OdbBackend)
+
+ // wrap routine w/abstract function
+ ret := C.git_odb_new(&odb.ptr)
+ if ret >= 0 {
+ ret = C.git_repository_wrap_odb(&repo.ptr, odb.ptr)
+ }
+
+ if ret >= 0 {
+ ret = C.int(initStrategy(&backend.ptr))
+ }
- // run initStrategy abstract function
- ret := initStrategy(&repo.ptr, &odb.ptr)
+ if ret >= 0 {
+ ret = C.git_odb_add_backend(odb.ptr, backend.ptr, C.int(priority))
+ }
+
+ // cleanup and return
if ret < 0 {
return nil, nil, LastError()
}
- // cleanup and return
runtime.SetFinalizer(repo, (*Repository).Free)
runtime.SetFinalizer(odb, (*Odb).Free)
return repo, odb, nil