From dfe6d1ab7efa8bb480616eb5f3962989b4ac3096 Mon Sep 17 00:00:00 2001 From: Aidan Nulman Date: Wed, 18 Dec 2013 17:25:54 -0500 Subject: [PATCH] Stop assuming ODB backend includes wrapping routine; wrap in git2go instead --- odb.go | 4 ++++ repository.go | 27 ++++++++++++++++++++------- 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) - // 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