libgit2/git2go — pull request #48 by anulman (2013-12-18 00:13:06+00:00)
Title: [TEST MISSING] Add function to init repos w/custom odb backends

Add function in repository.go to initialize a repository with a custom ODB backend.

I am unsure how to write tests for this, as the test environment would require a custom ODB backend.

In the meantime, you can install my Kyoto Tycoon backend from https://github.com/anulman/libgit2/tree/kyoto (set -DGIT_ODB_KYOTO=ON before building) and use the following routine to test:

```go
package main

/*
#cgo pkg-config: libgit2
#include
#include
*/
import "C"
import (
"errors"
"fmt"
"github.com/libgit2/git2go"
"os"
"unsafe"
)

const kyotoPath string = "http://localhost:1978/"

func main() {
// define initStrategy abstract function for custom backend init
initStrategy := func(repo **C.git_repository, odb **C.git_odb) (ret int) {
// convert path for use in c
cpath := C.CString(kyotoPath)
defer C.free(unsafe.Pointer(cpath))

// handoff to c, convert C.int to int for error check
cret := C.git_odb_backend_wrap_kyoto(repo, odb, cpath)
ret = int(cret)

return
}

_, odb, err := git.InitRepositoryWCustomOdbBackend(initStrategy)
defer odb.Free()

if err != nil {
fmt.Println(err)
return
}

if len(os.Args) < 3 {
err = errors.New("call with (w)rite/(r)ead + data/oid")
fmt.Println(err)
return
}

if os.Args[1] == "write" || os.Args[1] == "w" {
oid, err := odb.Write([]byte(os.Args[2]), git.ObjectBlob)
if err == nil {
fmt.Println("oid:", oid)
return
}
} else if os.Args[1] == "read" || os.Args[1] == "r" {
oid, err := git.NewOidFromString(os.Args[2])
if err == nil {
obj, err := odb.Read(oid)
if err == nil {
fmt.Println("obj data:", string(obj.Data()))
return
}
}
} else {
fmt.Println("unrecognized command:", os.Args[1])
}

if err != nil {
fmt.Println(err)
return
}
}
```

run with:
```bash
go run [file] w [string]
go run [file] r [returned oid]
```