Refactor InitRepositoryWCustomOdbBackend() into component functions
This commit is contained in:
parent
dfe6d1ab7e
commit
19b241bd55
23
odb.go
23
odb.go
|
@ -17,8 +17,29 @@ type Odb struct {
|
||||||
ptr *C.git_odb
|
ptr *C.git_odb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OdbBackends need public Ptrs: client apps init the backend
|
||||||
type OdbBackend struct {
|
type OdbBackend struct {
|
||||||
ptr *C.git_odb_backend
|
Ptr *C.git_odb_backend
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitOdb() (odb *Odb, err error) {
|
||||||
|
odb = new(Odb)
|
||||||
|
|
||||||
|
ret := C.git_odb_new(&odb.ptr)
|
||||||
|
if ret < 0 {
|
||||||
|
return nil, LastError()
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.SetFinalizer(odb, (*Odb).Free)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Odb) AddBackend(backend *OdbBackend, priority int) (err error) {
|
||||||
|
ret := C.git_odb_add_backend(v.ptr, backend.Ptr, C.int(priority))
|
||||||
|
if ret < 0 {
|
||||||
|
err = LastError()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Odb) Exists(oid *Oid) bool {
|
func (v *Odb) Exists(oid *Oid) bool {
|
||||||
|
|
|
@ -15,8 +15,6 @@ type Repository struct {
|
||||||
ptr *C.git_repository
|
ptr *C.git_repository
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitCustomBackend func(**C.git_odb_backend) int
|
|
||||||
|
|
||||||
func OpenRepository(path string) (*Repository, error) {
|
func OpenRepository(path string) (*Repository, error) {
|
||||||
repo := new(Repository)
|
repo := new(Repository)
|
||||||
|
|
||||||
|
@ -47,34 +45,16 @@ func InitRepository(path string, isbare bool) (*Repository, error) {
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitRepositoryWCustomOdbBackend(initStrategy InitCustomBackend, priority int) (*Repository, *Odb, error) {
|
func InitRepositoryByWrapOdb(odb *Odb) (repo *Repository, err error) {
|
||||||
// inits
|
repo = new(Repository)
|
||||||
repo := new(Repository)
|
|
||||||
odb := new(Odb)
|
|
||||||
backend := new(OdbBackend)
|
|
||||||
|
|
||||||
// wrap routine w/abstract function
|
ret := C.git_repository_wrap_odb(&repo.ptr, odb.ptr)
|
||||||
ret := C.git_odb_new(&odb.ptr)
|
if ret < 0 {
|
||||||
if ret >= 0 {
|
return nil, LastError()
|
||||||
ret = C.git_repository_wrap_odb(&repo.ptr, odb.ptr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret >= 0 {
|
runtime.SetFinalizer(repo, (*Repository).Free)
|
||||||
ret = C.int(initStrategy(&backend.ptr))
|
return
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.SetFinalizer(repo, (*Repository).Free)
|
|
||||||
runtime.SetFinalizer(odb, (*Odb).Free)
|
|
||||||
return repo, odb, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Repository) Free() {
|
func (v *Repository) Free() {
|
||||||
|
|
Loading…
Reference in New Issue