Last active
December 17, 2015 10:09
-
-
Save technoweenie/5593168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/Merovius/git2go" | |
"os" | |
) | |
// $ GOPATH=./vendor go run test.go | |
// # command-line-arguments | |
// ./test.go:34: repo.NewPackbuilder undefined (type *git.Repository has no field or method NewPackbuilder) | |
func main() { | |
fmt.Println(os.Getenv("GOPATH")) | |
oid, err := git.NewOidFromString("ec0b0b9228c34acf7cce6082d7fb318ad587a816") | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(oid) | |
repo, err := git.OpenRepository("/Users/rick/p/go-git-experiment") | |
defer repo.Free() | |
if err != nil { | |
panic(err) | |
} | |
commit, err := repo.LookupCommit(oid) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(commit.Message()) | |
pb, err := repo.NewPackbuilder() | |
//defer pb.Free() | |
if err != nil { | |
panic(err) | |
} | |
//fmt.Println(pb.ObjectCount()) | |
//err = pb.InsertCommit(oid) | |
if err != nil { | |
panic(err) | |
} | |
//fmt.Println(pb.ObjectCount()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~p/go-git-experiment/vendor/src/github.com/Merovius/git2go git:(packbuilder) ✗$ gl | |
commit 3a1bbbdf9dcdf88c909ea9df127f32b126d38547 | |
Author: Axel Wagner <[email protected]> | |
Date: Thu May 16 16:53:21 2013 +0200 | |
Correct some errors from 1da989e | |
commit 1da989e28b04807fb9781c3198769630ccb9a0fd | |
Author: Axel Wagner <[email protected]> | |
Date: Thu May 16 14:02:22 2013 +0200 | |
Add Write(w io.Writer) to packbuilder | |
This wraps (*packbuilder).ForEach(), making it possible to write the | |
pack easiliy to a tcp-connection, a HTTP-Body or the like. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ GOPATH=./vendor go build -v -x | |
WORK=/var/folders/q9/12fpv_bn2yngtr41t2hz7l4m0000gn/T/go-build809812750 | |
_/Users/rick/p/go-git-experiment | |
mkdir -p $WORK/_/Users/rick/p/go-git-experiment/_obj/ | |
cd /Users/rick/p/go-git-experiment | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/6g -o $WORK/_/Users/rick/p/go-git-experiment/_obj/_go_.6 -p _/Users/rick/p/go-git-experiment -D _/Users/rick/p/go-git-experiment -I $WORK -I vendor/pkg/darwin_amd64 ./test.go | |
# _/Users/rick/p/go-git-experiment | |
./test.go:34: repo.NewPackbuilder undefined (type *git.Repository has no field or method NewPackbuilder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~p/go-git-experiment/vendor/src/github.com/Merovius/git2go git:(packbuilder) ✗$ go build -v -x | |
WORK=/var/folders/q9/12fpv_bn2yngtr41t2hz7l4m0000gn/T/go-build474686434 | |
_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go | |
mkdir -p $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ | |
cd /Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go | |
pkg-config --cflags libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 | |
pkg-config --libs libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 libgit2 | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/cgo -objdir $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -- -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ blob.go checkout.go commit.go config.go git.go index.go odb.go packbuilder.go reference.go repository.go submodule.go tree.go walk.go | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/6c -FVw -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -I /opt/boxen/homebrew/Cellar/go/1.0.3/pkg/darwin_amd64 -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_defun.6 -DGOOS_darwin -DGOARCH_amd64 $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_defun.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_main.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_main.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_export.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_export.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/blob.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/blob.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/checkout.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/checkout.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/commit.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/commit.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/config.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/config.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/git.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/git.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/index.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/index.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/odb.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/odb.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/packbuilder.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/packbuilder.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/reference.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/reference.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/repository.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/repository.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/submodule.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/submodule.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/tree.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/tree.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/walk.cgo2.o -c $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/walk.cgo2.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I/usr/local/include -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/wrapper.o -c ./wrapper.c | |
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_main.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_export.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/blob.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/checkout.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/commit.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/config.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/git.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/index.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/odb.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/packbuilder.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/reference.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/repository.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/submodule.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/tree.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/walk.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/wrapper.o -L/usr/local/lib -lgit2 -lz -lcrypto -lz | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/cgo -objdir $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -dynimport $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_.o -dynout $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_import.c | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/6c -FVw -I $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/ -I /opt/boxen/homebrew/Cellar/go/1.0.3/pkg/darwin_amd64 -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_import.6 -DGOOS_darwin -DGOARCH_amd64 $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_import.c | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/6g -o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_go_.6 -p _/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go -D _/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go -I $WORK $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_gotypes.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/blob.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/checkout.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/commit.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/config.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/git.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/index.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/odb.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/packbuilder.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/reference.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/repository.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/submodule.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/tree.cgo1.go $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/walk.cgo1.go | |
/opt/boxen/homebrew/Cellar/go/1.0.3/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go.a $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_go_.6 $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_import.6 $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_defun.6 $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/_cgo_export.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/blob.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/checkout.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/commit.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/config.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/git.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/index.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/odb.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/packbuilder.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/reference.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/repository.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/submodule.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/tree.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/walk.cgo2.o $WORK/_/Users/rick/p/go-git-experiment/vendor/src/github.com/Merovius/git2go/_obj/wrapper.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://raw.github.com/Merovius/git2go/packbuilder/packbuilder.go | |
package git | |
/* | |
#cgo pkg-config: libgit2 | |
#include <git2.h> | |
#include <git2/errors.h> | |
#include <git2/pack.h> | |
#include <stdlib.h> | |
extern int _go_git_packbuilder_foreach(git_packbuilder *pb, void *payload); | |
*/ | |
import "C" | |
import ( | |
"runtime" | |
"unsafe" | |
"io" | |
) | |
type Packbuilder struct { | |
ptr *C.git_packbuilder | |
} | |
func (repo *Repository) NewPackbuilder() (*Packbuilder, error) { | |
builder := &Packbuilder{} | |
ret := C.git_packbuilder_new(&builder.ptr, repo.ptr) | |
if ret != 0 { | |
return nil, LastError() | |
} | |
runtime.SetFinalizer(builder, (*Packbuilder).Free) | |
return builder, nil | |
} | |
func (pb *Packbuilder) Free() { | |
runtime.SetFinalizer(pb, nil) | |
C.git_packbuilder_free(pb.ptr) | |
} | |
func (pb *Packbuilder) Insert(id *Oid, name string) error { | |
cname := C.CString(name) | |
defer C.free(unsafe.Pointer(cname)) | |
ret := C.git_packbuilder_insert(pb.ptr, id.toC(), cname) | |
if ret != 0 { | |
return LastError() | |
} | |
return nil | |
} | |
func (pb *Packbuilder) InsertCommit(id *Oid) error { | |
ret := C.git_packbuilder_insert_commit(pb.ptr, id.toC()) | |
if ret != 0 { | |
return LastError() | |
} | |
return nil | |
} | |
func (pb *Packbuilder) InsertTree(id *Oid) error { | |
ret := C.git_packbuilder_insert_tree(pb.ptr, id.toC()) | |
if ret != 0 { | |
return LastError() | |
} | |
return nil | |
} | |
func (pb *Packbuilder) ObjectCount() uint32 { | |
return uint32(C.git_packbuilder_object_count(pb.ptr)) | |
} | |
func (pb *Packbuilder) WriteToFile(name string) error { | |
cname := C.CString(name) | |
defer C.free(unsafe.Pointer(cname)) | |
ret := C.git_packbuilder_write(pb.ptr, cname) | |
if ret != 0 { | |
return LastError() | |
} | |
return nil | |
} | |
func (pb *Packbuilder) Write(w io.Writer) error { | |
ch := pb.ForEach() | |
for slice := range ch { | |
_, err := w.Write(slice) | |
if err != nil { | |
return err | |
} | |
} | |
return nil | |
} | |
func (pb *Packbuilder) Written() uint32 { | |
return uint32(C.git_packbuilder_written(pb.ptr)) | |
} | |
//export packbuilderForEachCb | |
func packbuilderForEachCb(buf unsafe.Pointer, size C.size_t, payload unsafe.Pointer) int { | |
ch := *(*chan []byte)(payload) | |
slice := C.GoBytes(buf, C.int(size)) | |
ch <- slice | |
return 0 | |
} | |
func (pb *Packbuilder) forEachWrap(ch chan []byte) { | |
C._go_git_packbuilder_foreach(pb.ptr, unsafe.Pointer(&ch)) | |
close(ch) | |
} | |
func (pb *Packbuilder) ForEach() chan []byte { | |
ch := make(chan []byte, 0) | |
go pb.forEachWrap(ch) | |
return ch | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://raw.github.com/Merovius/git2go/packbuilder/repository.go | |
package git | |
/* | |
#cgo pkg-config: libgit2 | |
#include <git2.h> | |
#include <git2/errors.h> | |
*/ | |
import "C" | |
import ( | |
"unsafe" | |
"runtime" | |
) | |
// Repository | |
type Repository struct { | |
ptr *C.git_repository | |
} | |
func OpenRepository(path string) (*Repository, error) { | |
repo := new(Repository) | |
cpath := C.CString(path) | |
defer C.free(unsafe.Pointer(cpath)) | |
ret := C.git_repository_open(&repo.ptr, cpath) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
runtime.SetFinalizer(repo, (*Repository).Free) | |
return repo, nil | |
} | |
func InitRepository(path string, isbare bool) (*Repository, error) { | |
repo := new(Repository) | |
cpath := C.CString(path) | |
defer C.free(unsafe.Pointer(cpath)) | |
ret := C.git_repository_init(&repo.ptr, cpath, ucbool(isbare)) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
runtime.SetFinalizer(repo, (*Repository).Free) | |
return repo, nil | |
} | |
func (v *Repository) Free() { | |
runtime.SetFinalizer(v, nil) | |
C.git_repository_free(v.ptr) | |
} | |
func (v *Repository) Config() (*Config, error) { | |
config := new(Config) | |
ret := C.git_repository_config(&config.ptr, v.ptr) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
return config, nil | |
} | |
func (v *Repository) Index() (*Index, error) { | |
var ptr *C.git_index | |
ret := C.git_repository_index(&ptr, v.ptr) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
return newIndexFromC(ptr), nil | |
} | |
func (v *Repository) LookupTree(oid *Oid) (*Tree, error) { | |
tree := new(Tree) | |
ret := C.git_tree_lookup(&tree.ptr, v.ptr, oid.toC()) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
return tree, nil | |
} | |
func (v *Repository) LookupCommit(o *Oid) (*Commit, error) { | |
commit := new(Commit) | |
ecode := C.git_commit_lookup(&commit.ptr, v.ptr, o.toC()) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
return commit, nil | |
} | |
func (v *Repository) LookupBlob(o *Oid) (*Blob, error) { | |
blob := new(Blob) | |
ecode := C.git_blob_lookup(&blob.ptr, v.ptr, o.toC()) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
runtime.SetFinalizer(blob, (*Blob).Free) | |
return blob, nil | |
} | |
func (v *Repository) LookupReference(name string) (*Reference, error) { | |
cname := C.CString(name) | |
defer C.free(unsafe.Pointer(cname)) | |
var ptr *C.git_reference | |
ecode := C.git_reference_lookup(&ptr, v.ptr, cname) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
return newReferenceFromC(ptr), nil | |
} | |
func (v *Repository) CreateReference(name string, oid *Oid, force bool) (*Reference, error) { | |
cname := C.CString(name) | |
defer C.free(unsafe.Pointer(cname)) | |
var ptr *C.git_reference | |
ecode := C.git_reference_create(&ptr, v.ptr, cname, oid.toC(), cbool(force)) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
return newReferenceFromC(ptr), nil | |
} | |
func (v *Repository) CreateSymbolicReference(name, target string, force bool) (*Reference, error) { | |
cname := C.CString(name) | |
defer C.free(unsafe.Pointer(cname)) | |
ctarget := C.CString(target) | |
defer C.free(unsafe.Pointer(ctarget)) | |
var ptr *C.git_reference | |
ecode := C.git_reference_symbolic_create(&ptr, v.ptr, cname, ctarget, cbool(force)) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
return newReferenceFromC(ptr), nil | |
} | |
func (v *Repository) Walk() (*RevWalk, error) { | |
walk := new(RevWalk) | |
ecode := C.git_revwalk_new(&walk.ptr, v.ptr) | |
if ecode < 0 { | |
return nil, LastError() | |
} | |
walk.repo = v | |
runtime.SetFinalizer(walk, freeRevWalk) | |
return walk, nil | |
} | |
func (v *Repository) CreateCommit( | |
refname string, author, committer *Signature, | |
message string, tree *Tree, parents ...*Commit) (*Oid, error) { | |
oid := new(Oid) | |
cref := C.CString(refname) | |
defer C.free(unsafe.Pointer(cref)) | |
cmsg := C.CString(message) | |
defer C.free(unsafe.Pointer(cmsg)) | |
var cparents []*C.git_commit = nil | |
var parentsarg **C.git_commit = nil | |
nparents:= len(parents) | |
if nparents > 0 { | |
cparents = make([]*C.git_commit, nparents) | |
for i, v := range parents { | |
cparents[i] = v.ptr | |
} | |
parentsarg = &cparents[0] | |
} | |
authorSig := author.toC() | |
defer C.git_signature_free(authorSig) | |
committerSig := committer.toC() | |
defer C.git_signature_free(committerSig) | |
ret := C.git_commit_create( | |
oid.toC(), v.ptr, cref, | |
authorSig, committerSig, | |
nil, cmsg, tree.ptr, C.int(nparents), parentsarg) | |
if ret < 0 { | |
return nil, LastError() | |
} | |
return oid, nil | |
} | |
func (v *Odb) Free() { | |
runtime.SetFinalizer(v, nil) | |
C.git_odb_free(v.ptr) | |
} | |
func (v *Repository) Odb() (odb *Odb, err error) { | |
odb = new(Odb) | |
if ret := C.git_repository_odb(&odb.ptr, v.ptr); ret < 0 { | |
return nil, LastError() | |
} | |
runtime.SetFinalizer(odb, (*Odb).Free) | |
return | |
} | |
func (repo *Repository) Path() string { | |
return C.GoString(C.git_repository_path(repo.ptr)) | |
} | |
func (repo *Repository) IsBare() (bool) { | |
return C.git_repository_is_bare(repo.ptr) != 0 | |
} | |
func (repo *Repository) Workdir() string { | |
return C.GoString(C.git_repository_workdir(repo.ptr)) | |
} | |
func (repo *Repository) SetWorkdir(workdir string, updateGitlink bool) error { | |
cstr := C.CString(workdir) | |
defer C.free(unsafe.Pointer(cstr)) | |
if C.git_repository_set_workdir(repo.ptr, cstr, cbool(updateGitlink)) < 0 { | |
return LastError() | |
} | |
return nil | |
} | |
func (v *Repository) TreeBuilder() (*TreeBuilder, error) { | |
bld := new(TreeBuilder) | |
if ret := C.git_treebuilder_create(&bld.ptr, nil); ret < 0 { | |
return nil, LastError() | |
} | |
bld.repo = v | |
return bld, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment