add function to init repos w/custom odb backends

This commit is contained in:
Aidan Nulman 2013-12-17 18:46:25 -05:00
parent 625ffd022e
commit 66dfbbf539
1 changed files with 19 additions and 0 deletions

View File

@ -15,6 +15,8 @@ type Repository struct {
ptr *C.git_repository
}
type InitCustomBackend func(**C.git_repository, **C.git_odb) int
func OpenRepository(path string) (*Repository, error) {
repo := new(Repository)
@ -45,6 +47,23 @@ func InitRepository(path string, isbare bool) (*Repository, error) {
return repo, nil
}
func InitRepositoryWCustomOdbBackend(initStrategy InitCustomBackend) (*Repository, *Odb, error) {
// init return vars
repo := new(Repository)
odb := new(Odb)
// run initStrategy abstract function
ret := initStrategy(&repo.ptr, &odb.ptr)
if ret < 0 {
return nil, nil, LastError()
}
// cleanup and return
runtime.SetFinalizer(repo, (*Repository).Free)
runtime.SetFinalizer(odb, (*Odb).Free)
return repo, odb, nil
}
func (v *Repository) Free() {
runtime.SetFinalizer(v, nil)
C.git_repository_free(v.ptr)