Stop assuming ODB backend includes wrapping routine; wrap in git2go instead

This commit is contained in:
Aidan Nulman 2013-12-18 17:25:54 -05:00
parent 66dfbbf539
commit dfe6d1ab7e
2 changed files with 24 additions and 7 deletions

4
odb.go
View File

@ -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

View File

@ -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
func InitRepositoryWCustomOdbBackend(initStrategy InitCustomBackend, priority int) (*Repository, *Odb, error) {
// inits
repo := new(Repository)
odb := new(Odb)
backend := new(OdbBackend)
// run initStrategy abstract function
ret := initStrategy(&repo.ptr, &odb.ptr)
// 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))
}
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