Skip to content

Commit

Permalink
update to libgit2 v0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosset committed Aug 30, 2012
1 parent 93e2068 commit 1c0edaf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 87 deletions.
12 changes: 6 additions & 6 deletions Makefile
@@ -1,14 +1,14 @@
build:
@cd libgit2; ./waf configure
@cd libgit2; ./waf build
@mkdir libgit2_build
@cd libgit2_build; cmake ../libgit2
@cd libgit2_build; cmake --build .

libgit2-init:
@git submodule update --init libgit2

install:
@cd libgit2; ./waf install
@cd libgit2_build; cmake --build . --target install

clean:
@cd libgit2; ./waf clean


rm -rf ./libgit2_build
rm -rf ./tmp
22 changes: 0 additions & 22 deletions defs.c

This file was deleted.

30 changes: 0 additions & 30 deletions defs.go

This file was deleted.

37 changes: 23 additions & 14 deletions git.go
Expand Up @@ -3,6 +3,7 @@ package git
/*
#cgo pkg-config: libgit2
#include <git2.h>
#include <git2/errors.h>
*/
import "C"
import (
Expand All @@ -15,6 +16,7 @@ import (
const (
NOTBARE = iota
BARE
GIT_SUCCESS = 0
)

type Test *C.git_repository
Expand Down Expand Up @@ -52,7 +54,7 @@ type Tree struct {
}

func (t *Tree) Free() {
C.git_tree_close(t.git_tree)
C.git_tree_free(t.git_tree)
}

func TreeLookup(repo *Repo, oid *Oid) (*Tree, error) {
Expand Down Expand Up @@ -93,7 +95,7 @@ func (t *Tree) EntryByName(filename string) (*Entry, error) {

func (t *Tree) EntryByIndex(index int) (*Entry, error) {
entry := new(Entry)
entry.git_tree_entry = C.git_tree_entry_byindex(t.git_tree, C.int(index))
entry.git_tree_entry = C.git_tree_entry_byindex(t.git_tree, C.uint(index))
if entry.git_tree_entry == nil {
return nil, errors.New("Unable to find entry.")
}
Expand Down Expand Up @@ -124,6 +126,7 @@ type Commit struct {
git_commit *C.git_commit
}

/*
//TODO: do not use hardcoded update_ref
func CommitCreate(repo *Repo, tree, parent *Oid, author, commiter *Signature, message string) error {
oid := NewOid()
Expand All @@ -146,6 +149,7 @@ func CommitCreate(repo *Repo, tree, parent *Oid, author, commiter *Signature, me
}
return nil
}
*/

func (c *Commit) Lookup(r *Repo, o *Oid) (err error) {
ecode := C.git_commit_lookup(&c.git_commit, r.git_repo, o.git_oid)
Expand Down Expand Up @@ -180,7 +184,9 @@ func NewOid() *Oid {

func NewOidString(s string) (*Oid, error) {
o := &Oid{new(C.git_oid)}
if C.git_oid_mkstr(o.git_oid, C.CString(s)) < GIT_SUCCESS {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
if C.git_oid_fromstr(o.git_oid, cs) < GIT_SUCCESS {
return nil, LastError()
}
return o, nil
Expand Down Expand Up @@ -280,7 +286,7 @@ func (v *Reference) SetTarget(target string) (err error) {
}

func (v *Reference) Type() {
if C.git_reference_type(v.git_reference) == GIT_REF_SYMBOLIC {
if C.git_reference_type(v.git_reference) == C.GIT_REF_SYMBOLIC {
println("THIS IS A SYMBOLIC REF")
}
}
Expand All @@ -298,12 +304,13 @@ type Index struct {
git_index *C.git_index
}

func (v *Index) Open(repo *Repo) (err error) {
if ecode := C.git_index_open_inrepo(&v.git_index, repo.git_repo); ecode != GIT_SUCCESS {
estring := fmt.Sprintf("failed to open index error code %v", ecode)
return errors.New(estring)
func NewIndex(repo *Repo) (*Index, error) {
i := new(C.git_index)
ecode := C.git_repository_index(&i, repo.git_repo)
if ecode != GIT_SUCCESS {
return nil, LastError()
}
return
return &Index{i}, nil
}

func (v *Index) Add(file string) (err error) {
Expand Down Expand Up @@ -334,7 +341,7 @@ func (v *Index) EntryCount() int {
}

func (v *Index) Get(n int) (*IndexEntry, error) {
p := C.git_index_get(v.git_index, C.int(n))
p := C.git_index_get(v.git_index, C.uint(n))
if p == nil {
estring := fmt.Sprintf("Index %v not found, total index is %v", n, v.EntryCount())
return nil, errors.New(estring)
Expand Down Expand Up @@ -380,14 +387,16 @@ func NewSignature(name, email string) *Signature {
e := C.CString(email)
defer C.free(unsafe.Pointer(n))
defer C.free(unsafe.Pointer(e))
s := &Signature{C.git_signature_now(n, e)}
return s
gs := new(C.git_signature)
C.git_signature_now(&gs, n, e)
return &Signature{gs}
}

// Helper functions
func LastError() error {
lasterror := C.GoString(C.git_lasterror())
return errors.New(lasterror)
ge := C.giterr_last()
msg := C.GoString(ge.message)
return errors.New(msg)
}

//Private
Expand Down
43 changes: 29 additions & 14 deletions git_test.go
Expand Up @@ -25,7 +25,7 @@ func init() {
// Repo
func TestInitBare(t *testing.T) {
repo = new(Repo)
if err := repo.Init(path, BARE); err != nil {
if err := repo.Init(path, 1); err != nil {
t.Fatal("Error:", err)
}
}
Expand Down Expand Up @@ -66,9 +66,11 @@ func TestSeed(t *testing.T) {

// Index
func TestIndexAdd(t *testing.T) {
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
tmpfile := "README"
f, err := os.OpenFile(path+"/"+tmpfile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
Expand All @@ -83,9 +85,11 @@ func TestIndexAdd(t *testing.T) {

func TestIndexEntryCount(t *testing.T) {
expected := 1
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
err = index.Read()
check(t, err)
Expand All @@ -97,9 +101,11 @@ func TestIndexEntryCount(t *testing.T) {
func TestIndexGet(t *testing.T) {
path := "README"
flags := 6
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
err = index.Read()
check(t, err)
Expand All @@ -115,14 +121,17 @@ func TestIndexGet(t *testing.T) {
}
}

/*
// Commit
func TestCommit(t *testing.T) {
TestIndexAdd(t)
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
tree, err := TreeFromIndex(repo, index)
tree, err := TreeFromIndex(repo, &index)
check(t, err)
head, err := GetHead(repo)
check(t, err)
Expand All @@ -131,11 +140,13 @@ func TestCommit(t *testing.T) {
err = CommitCreate(repo, tree, head, s, s, "some stuff here")
check(t, err)
}
func TestManyCommits(t *testing.T) {
for i := 0; i < 29; i++ {
TestCommit(t)
}
}
*/

// RevWalk
func TestNewRevWalk(t *testing.T) {
Expand Down Expand Up @@ -191,18 +202,22 @@ func TestTSignature(t *testing.T) {
// Tree

func TestTreeFromIndex(t *testing.T) {
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
_, err = TreeFromIndex(repo, index)
check(t, err)
}

func TestTreeLookup(t *testing.T) {
index := new(Index)
index, err := NewIndex(repo)
if err != nil {
t.Error(err)
}
defer index.Free()
err := index.Open(repo)
check(t, err)
oid, err := TreeFromIndex(repo, index)
check(t, err)
Expand Down
2 changes: 1 addition & 1 deletion libgit2
Submodule libgit2 updated 817 files

0 comments on commit 1c0edaf

Please sign in to comment.