Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update to libgit2 v0.17.0

  • Loading branch information...
commit 1c0edafbe5b0b2639c8cf810d26f0e23540d241d 1 parent 93e2068
@str1ngs authored
Showing with 59 additions and 87 deletions.
  1. +6 −6 Makefile
  2. +0 −22 defs.c
  3. +0 −30 defs.go
  4. +23 −14 git.go
  5. +29 −14 git_test.go
  6. +1 −1  libgit2
View
12 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
View
22 defs.c
@@ -1,22 +0,0 @@
-#include <git2.h>
-
-enum
-{
- $GIT_OBJ_ANY = GIT_OBJ_ANY,
- $GIT_OBJ_BAD = GIT_OBJ_BAD,
- $GIT_OBJ__EXT1 = GIT_OBJ__EXT1,
- $GIT_OBJ_BLOB = GIT_OBJ_BLOB,
- $GIT_OBJ_COMMIT = GIT_OBJ_COMMIT,
- $GIT_OBJ_OFS_DELTA = GIT_OBJ_OFS_DELTA,
- $GIT_OBJ_REF_DELTA = GIT_OBJ_REF_DELTA,
- $GIT_OBJ_TAG = GIT_OBJ_TAG,
- $GIT_OBJ_TREE = GIT_OBJ_TREE,
- $GIT_OBJ__EXT2 = GIT_OBJ__EXT2,
-
- $GIT_REF_SYMBOLIC = GIT_REF_SYMBOLIC,
-
- $GIT_SUCCESS = GIT_SUCCESS,
- $GIT_ENOTOID = GIT_ENOTOID
-};
-
-typedef struct git_time $GitTime;
View
30 defs.go
@@ -1,30 +0,0 @@
-// godefs -g git defs.c
-
-// MACHINE GENERATED - DO NOT EDIT.
-
-package git
-
-// Constants
-const (
- GIT_OBJ_ANY = -0x2
- GIT_OBJ_BAD = -0x1
- GIT_OBJ__EXT1 = 0
- GIT_OBJ_BLOB = 0x3
- GIT_OBJ_COMMIT = 0x1
- GIT_OBJ_OFS_DELTA = 0x6
- GIT_OBJ_REF_DELTA = 0x7
- GIT_OBJ_TAG = 0x4
- GIT_OBJ_TREE = 0x2
- GIT_OBJ__EXT2 = 0x5
- GIT_REF_SYMBOLIC = 0x2
- GIT_SUCCESS = 0
- GIT_ENOTOID = -0x2
-)
-
-// Types
-
-type GitTime struct {
- Time int64
- Offset int32
- Pad_godefs_0 [4]byte
-}
View
37 git.go
@@ -3,6 +3,7 @@ package git
/*
#cgo pkg-config: libgit2
#include <git2.h>
+#include <git2/errors.h>
*/
import "C"
import (
@@ -15,6 +16,7 @@ import (
const (
NOTBARE = iota
BARE
+ GIT_SUCCESS = 0
)
type Test *C.git_repository
@@ -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) {
@@ -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.")
}
@@ -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()
@@ -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)
@@ -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
@@ -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")
}
}
@@ -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) {
@@ -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)
@@ -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
View
43 git_test.go
@@ -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)
}
}
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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) {
@@ -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)
2  libgit2
@@ -1 +1 @@
-Subproject commit 40774549e14e2d9f24b9271173d58b44f82d5254
+Subproject commit 5b9fac39d8a76b9139667c26a63e6b3f204b3977
Please sign in to comment.
Something went wrong with that request. Please try again.