Merge remote-tracking branch 'libgit/master' into add-basic-diff-patch
This commit is contained in:
commit
b00cb1a343
|
@ -5,8 +5,7 @@ go:
|
||||||
- 1.1
|
- 1.1
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
env:
|
|
||||||
- PKG_CONFIG_PATH=libgit2/install/lib/pkgconfig LD_LIBRARY_PATH=libgit2/install/lib
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- script/build-libgit2.sh
|
- script/build-libgit2.sh
|
||||||
|
- export PKG_CONFIG_PATH=$PWD/libgit2/install/lib/pkgconfig
|
||||||
|
- export LD_LIBRARY_PATH=$PWD/libgit2/install/lib
|
||||||
|
|
7
blob.go
7
blob.go
|
@ -20,15 +20,16 @@ import (
|
||||||
|
|
||||||
type Blob struct {
|
type Blob struct {
|
||||||
gitObject
|
gitObject
|
||||||
|
cast_ptr *C.git_blob
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Blob) Size() int64 {
|
func (v *Blob) Size() int64 {
|
||||||
return int64(C.git_blob_rawsize(v.ptr))
|
return int64(C.git_blob_rawsize(v.cast_ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Blob) Contents() []byte {
|
func (v *Blob) Contents() []byte {
|
||||||
size := C.int(C.git_blob_rawsize(v.ptr))
|
size := C.int(C.git_blob_rawsize(v.cast_ptr))
|
||||||
buffer := unsafe.Pointer(C.git_blob_rawcontent(v.ptr))
|
buffer := unsafe.Pointer(C.git_blob_rawcontent(v.cast_ptr))
|
||||||
return C.GoBytes(buffer, size)
|
return C.GoBytes(buffer, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_branch_create(&ref.ptr, repo.ptr, cBranchName, target.ptr, cForce, cSignature, cmsg)
|
ret := C.git_branch_create(&ref.ptr, repo.ptr, cBranchName, target.cast_ptr, cForce, cSignature, cmsg)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
29
commit.go
29
commit.go
|
@ -17,56 +17,57 @@ import (
|
||||||
// Commit
|
// Commit
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
gitObject
|
gitObject
|
||||||
|
cast_ptr *C.git_commit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commit) Message() string {
|
func (c Commit) Message() string {
|
||||||
return C.GoString(C.git_commit_message(c.ptr))
|
return C.GoString(C.git_commit_message(c.cast_ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commit) Tree() (*Tree, error) {
|
func (c Commit) Tree() (*Tree, error) {
|
||||||
var ptr *C.git_object
|
var ptr *C.git_tree
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C.git_commit_tree(&ptr, c.ptr)
|
err := C.git_commit_tree(&ptr, c.cast_ptr)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return nil, MakeGitError(err)
|
return nil, MakeGitError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return allocObject(ptr).(*Tree), nil
|
return allocObject((*C.git_object)(ptr)).(*Tree), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commit) TreeId() *Oid {
|
func (c Commit) TreeId() *Oid {
|
||||||
return newOidFromC(C.git_commit_tree_id(c.ptr))
|
return newOidFromC(C.git_commit_tree_id(c.cast_ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commit) Author() *Signature {
|
func (c Commit) Author() *Signature {
|
||||||
ptr := C.git_commit_author(c.ptr)
|
cast_ptr := C.git_commit_author(c.cast_ptr)
|
||||||
return newSignatureFromC(ptr)
|
return newSignatureFromC(cast_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commit) Committer() *Signature {
|
func (c Commit) Committer() *Signature {
|
||||||
ptr := C.git_commit_committer(c.ptr)
|
cast_ptr := C.git_commit_committer(c.cast_ptr)
|
||||||
return newSignatureFromC(ptr)
|
return newSignatureFromC(cast_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) Parent(n uint) *Commit {
|
func (c *Commit) Parent(n uint) *Commit {
|
||||||
var cobj *C.git_object
|
var cobj *C.git_commit
|
||||||
ret := C.git_commit_parent(&cobj, c.ptr, C.uint(n))
|
ret := C.git_commit_parent(&cobj, c.cast_ptr, C.uint(n))
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return allocObject(cobj).(*Commit)
|
return allocObject((*C.git_object)(cobj)).(*Commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) ParentId(n uint) *Oid {
|
func (c *Commit) ParentId(n uint) *Oid {
|
||||||
return newOidFromC(C.git_commit_parent_id(c.ptr, C.uint(n)))
|
return newOidFromC(C.git_commit_parent_id(c.cast_ptr, C.uint(n)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) ParentCount() uint {
|
func (c *Commit) ParentCount() uint {
|
||||||
return uint(C.git_commit_parentcount(c.ptr))
|
return uint(C.git_commit_parentcount(c.cast_ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signature
|
// Signature
|
||||||
|
|
4
git.go
4
git.go
|
@ -150,6 +150,10 @@ func MakeGitError(errorCode C.int) error {
|
||||||
return &GitError{C.GoString(err.message), int(err.klass), int(errorCode)}
|
return &GitError{C.GoString(err.message), int(err.klass), int(errorCode)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeGitError2(err int) error {
|
||||||
|
return MakeGitError(C.int(err))
|
||||||
|
}
|
||||||
|
|
||||||
func cbool(b bool) C.int {
|
func cbool(b bool) C.int {
|
||||||
if b {
|
if b {
|
||||||
return C.int(1)
|
return C.int(1)
|
||||||
|
|
188
index.go
188
index.go
|
@ -27,6 +27,39 @@ type IndexEntry struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
|
||||||
|
if entry == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &IndexEntry{
|
||||||
|
time.Unix(int64(entry.ctime.seconds), int64(entry.ctime.nanoseconds)),
|
||||||
|
time.Unix(int64(entry.mtime.seconds), int64(entry.mtime.nanoseconds)),
|
||||||
|
uint(entry.mode),
|
||||||
|
uint(entry.uid),
|
||||||
|
uint(entry.gid),
|
||||||
|
uint(entry.file_size),
|
||||||
|
newOidFromC(&entry.id),
|
||||||
|
C.GoString(entry.path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) {
|
||||||
|
dest.ctime.seconds = C.git_time_t(source.Ctime.Unix())
|
||||||
|
dest.ctime.nanoseconds = C.uint(source.Ctime.UnixNano())
|
||||||
|
dest.mtime.seconds = C.git_time_t(source.Mtime.Unix())
|
||||||
|
dest.mtime.nanoseconds = C.uint(source.Mtime.UnixNano())
|
||||||
|
dest.mode = C.uint(source.Mode)
|
||||||
|
dest.uid = C.uint(source.Uid)
|
||||||
|
dest.gid = C.uint(source.Gid)
|
||||||
|
dest.file_size = C.git_off_t(source.Size)
|
||||||
|
dest.id = *source.Id.toC()
|
||||||
|
dest.path = C.CString(source.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func freeCIndexEntry(entry *C.git_index_entry) {
|
||||||
|
C.free(unsafe.Pointer(entry.path))
|
||||||
|
}
|
||||||
|
|
||||||
func newIndexFromC(ptr *C.git_index) *Index {
|
func newIndexFromC(ptr *C.git_index) *Index {
|
||||||
idx := &Index{ptr}
|
idx := &Index{ptr}
|
||||||
runtime.SetFinalizer(idx, (*Index).Free)
|
runtime.SetFinalizer(idx, (*Index).Free)
|
||||||
|
@ -97,19 +130,6 @@ func (v *Index) EntryCount() uint {
|
||||||
return uint(C.git_index_entrycount(v.ptr))
|
return uint(C.git_index_entrycount(v.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
|
|
||||||
return &IndexEntry{
|
|
||||||
time.Unix(int64(entry.ctime.seconds), int64(entry.ctime.nanoseconds)),
|
|
||||||
time.Unix(int64(entry.mtime.seconds), int64(entry.mtime.nanoseconds)),
|
|
||||||
uint(entry.mode),
|
|
||||||
uint(entry.uid),
|
|
||||||
uint(entry.gid),
|
|
||||||
uint(entry.file_size),
|
|
||||||
newOidFromC(&entry.id),
|
|
||||||
C.GoString(entry.path),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
|
func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
|
||||||
centry := C.git_index_get_byindex(v.ptr, C.size_t(index))
|
centry := C.git_index_get_byindex(v.ptr, C.size_t(index))
|
||||||
if centry == nil {
|
if centry == nil {
|
||||||
|
@ -117,3 +137,145 @@ func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
|
||||||
}
|
}
|
||||||
return newIndexEntryFromC(centry), nil
|
return newIndexEntryFromC(centry), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Index) HasConflicts() bool {
|
||||||
|
return C.git_index_has_conflicts(v.ptr) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) CleanupConflicts() {
|
||||||
|
C.git_index_conflict_cleanup(v.ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) AddConflict(ancestor *IndexEntry, our *IndexEntry, their *IndexEntry) error {
|
||||||
|
|
||||||
|
var cancestor *C.git_index_entry
|
||||||
|
var cour *C.git_index_entry
|
||||||
|
var ctheir *C.git_index_entry
|
||||||
|
|
||||||
|
if ancestor != nil {
|
||||||
|
cancestor = &C.git_index_entry{}
|
||||||
|
populateCIndexEntry(ancestor, cancestor)
|
||||||
|
defer freeCIndexEntry(cancestor)
|
||||||
|
}
|
||||||
|
|
||||||
|
if our != nil {
|
||||||
|
cour = &C.git_index_entry{}
|
||||||
|
populateCIndexEntry(our, cour)
|
||||||
|
defer freeCIndexEntry(cour)
|
||||||
|
}
|
||||||
|
|
||||||
|
if their != nil {
|
||||||
|
ctheir = &C.git_index_entry{}
|
||||||
|
populateCIndexEntry(their, ctheir)
|
||||||
|
defer freeCIndexEntry(ctheir)
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_index_conflict_add(v.ptr, cancestor, cour, ctheir)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type IndexConflict struct {
|
||||||
|
Ancestor *IndexEntry
|
||||||
|
Our *IndexEntry
|
||||||
|
Their *IndexEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) GetConflict(path string) (IndexConflict, error) {
|
||||||
|
|
||||||
|
var cancestor *C.git_index_entry
|
||||||
|
var cour *C.git_index_entry
|
||||||
|
var ctheir *C.git_index_entry
|
||||||
|
|
||||||
|
cpath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_index_conflict_get(&cancestor, &cour, &ctheir, v.ptr, cpath)
|
||||||
|
if ecode < 0 {
|
||||||
|
return IndexConflict{}, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return IndexConflict{
|
||||||
|
Ancestor: newIndexEntryFromC(cancestor),
|
||||||
|
Our: newIndexEntryFromC(cour),
|
||||||
|
Their: newIndexEntryFromC(ctheir),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) RemoveConflict(path string) error {
|
||||||
|
|
||||||
|
cpath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_index_conflict_remove(v.ptr, cpath)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type IndexConflictIterator struct {
|
||||||
|
ptr *C.git_index_conflict_iterator
|
||||||
|
index *Index
|
||||||
|
}
|
||||||
|
|
||||||
|
func newIndexConflictIteratorFromC(index *Index, ptr *C.git_index_conflict_iterator) *IndexConflictIterator {
|
||||||
|
i := &IndexConflictIterator{ptr: ptr, index: index}
|
||||||
|
runtime.SetFinalizer(i, (*IndexConflictIterator).Free)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IndexConflictIterator) Index() *Index {
|
||||||
|
return v.index
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IndexConflictIterator) Free() {
|
||||||
|
runtime.SetFinalizer(v, nil)
|
||||||
|
C.git_index_conflict_iterator_free(v.ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) ConflictIterator() (*IndexConflictIterator, error) {
|
||||||
|
var i *C.git_index_conflict_iterator
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_index_conflict_iterator_new(&i, v.ptr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return nil, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return newIndexConflictIteratorFromC(v, i), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *IndexConflictIterator) Next() (IndexConflict, error) {
|
||||||
|
var cancestor *C.git_index_entry
|
||||||
|
var cour *C.git_index_entry
|
||||||
|
var ctheir *C.git_index_entry
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_index_conflict_next(&cancestor, &cour, &ctheir, v.ptr)
|
||||||
|
if ecode == C.GIT_ITEROVER {
|
||||||
|
return IndexConflict{}, ErrIterOver
|
||||||
|
}
|
||||||
|
|
||||||
|
if ecode < 0 {
|
||||||
|
return IndexConflict{}, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return IndexConflict{
|
||||||
|
Ancestor: newIndexEntryFromC(cancestor),
|
||||||
|
Our: newIndexEntryFromC(cour),
|
||||||
|
Their: newIndexEntryFromC(ctheir),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
19
object.go
19
object.go
|
@ -48,7 +48,7 @@ func (t ObjectType) String() (string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o gitObject) Id() *Oid {
|
func (o gitObject) Id() *Oid {
|
||||||
return newOidFromC(C.git_commit_id(o.ptr))
|
return newOidFromC(C.git_object_id(o.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o gitObject) Type() ObjectType {
|
func (o gitObject) Type() ObjectType {
|
||||||
|
@ -57,24 +57,33 @@ func (o gitObject) Type() ObjectType {
|
||||||
|
|
||||||
func (o *gitObject) Free() {
|
func (o *gitObject) Free() {
|
||||||
runtime.SetFinalizer(o, nil)
|
runtime.SetFinalizer(o, nil)
|
||||||
C.git_commit_free(o.ptr)
|
C.git_object_free(o.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func allocObject(cobj *C.git_object) Object {
|
func allocObject(cobj *C.git_object) Object {
|
||||||
|
|
||||||
switch ObjectType(C.git_object_type(cobj)) {
|
switch ObjectType(C.git_object_type(cobj)) {
|
||||||
case ObjectCommit:
|
case ObjectCommit:
|
||||||
commit := &Commit{gitObject{cobj}}
|
commit := &Commit{
|
||||||
|
gitObject: gitObject{cobj},
|
||||||
|
cast_ptr: (*C.git_commit)(cobj),
|
||||||
|
}
|
||||||
runtime.SetFinalizer(commit, (*Commit).Free)
|
runtime.SetFinalizer(commit, (*Commit).Free)
|
||||||
return commit
|
return commit
|
||||||
|
|
||||||
case ObjectTree:
|
case ObjectTree:
|
||||||
tree := &Tree{gitObject{cobj}}
|
tree := &Tree{
|
||||||
|
gitObject: gitObject{cobj},
|
||||||
|
cast_ptr: (*C.git_tree)(cobj),
|
||||||
|
}
|
||||||
runtime.SetFinalizer(tree, (*Tree).Free)
|
runtime.SetFinalizer(tree, (*Tree).Free)
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
case ObjectBlob:
|
case ObjectBlob:
|
||||||
blob := &Blob{gitObject{cobj}}
|
blob := &Blob{
|
||||||
|
gitObject: gitObject{cobj},
|
||||||
|
cast_ptr: (*C.git_blob)(cobj),
|
||||||
|
}
|
||||||
runtime.SetFinalizer(blob, (*Blob).Free)
|
runtime.SetFinalizer(blob, (*Blob).Free)
|
||||||
return blob
|
return blob
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) CreateRemoteInMemory(fetch string, url string) (*Remote, error) {
|
func (repo *Repository) CreateAnonymousRemote(url, fetch string) (*Remote, error) {
|
||||||
remote := &Remote{}
|
remote := &Remote{}
|
||||||
|
|
||||||
curl := C.CString(url)
|
curl := C.CString(url)
|
||||||
|
@ -195,7 +195,7 @@ func (repo *Repository) CreateRemoteInMemory(fetch string, url string) (*Remote,
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_remote_create_inmemory(&remote.ptr, repo.ptr, cfetch, curl)
|
ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl, cfetch)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ func TestRefspecs(t *testing.T) {
|
||||||
defer os.RemoveAll(repo.Workdir())
|
defer os.RemoveAll(repo.Workdir())
|
||||||
defer repo.Free()
|
defer repo.Free()
|
||||||
|
|
||||||
remote, err := repo.CreateRemoteInMemory("refs/heads/*:refs/heads/*", "git://foo/bar")
|
remote, err := repo.CreateAnonymousRemote("git://foo/bar", "refs/heads/*:refs/heads/*")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
|
|
|
@ -253,7 +253,7 @@ func (v *Repository) CreateCommit(
|
||||||
if nparents > 0 {
|
if nparents > 0 {
|
||||||
cparents = make([]*C.git_commit, nparents)
|
cparents = make([]*C.git_commit, nparents)
|
||||||
for i, v := range parents {
|
for i, v := range parents {
|
||||||
cparents[i] = v.ptr
|
cparents[i] = v.cast_ptr
|
||||||
}
|
}
|
||||||
parentsarg = &cparents[0]
|
parentsarg = &cparents[0]
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ func (v *Repository) CreateCommit(
|
||||||
ret := C.git_commit_create(
|
ret := C.git_commit_create(
|
||||||
oid.toC(), v.ptr, cref,
|
oid.toC(), v.ptr, cref,
|
||||||
authorSig, committerSig,
|
authorSig, committerSig,
|
||||||
nil, cmsg, tree.ptr, C.size_t(nparents), parentsarg)
|
nil, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
|
||||||
|
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -345,7 +345,7 @@ func (v *Repository) TreeBuilderFromTree(tree *Tree) (*TreeBuilder, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if ret := C.git_treebuilder_create(&bld.ptr, tree.ptr); ret < 0 {
|
if ret := C.git_treebuilder_create(&bld.ptr, tree.cast_ptr); ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
||||||
|
|
|
@ -11,7 +11,3 @@ cmake -DTHREADSAFE=ON \
|
||||||
.
|
.
|
||||||
|
|
||||||
make install
|
make install
|
||||||
|
|
||||||
# Let the Go build system know where to find libgit2
|
|
||||||
export LD_LIBRARY_PATH="$TMPDIR/libgit2/install/lib"
|
|
||||||
export PKG_CONFIG_PATH="$TMPDIR/libgit2/install/lib/pkgconfig"
|
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
package settings
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo pkg-config: libgit2
|
||||||
|
#include <git2.h>
|
||||||
|
|
||||||
|
int _go_git_opts_get_search_path(int level, git_buf *buf)
|
||||||
|
{
|
||||||
|
return git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, level, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _go_git_opts_set_search_path(int level, const char *path)
|
||||||
|
{
|
||||||
|
return git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _go_git_opts_set_size_t(int opt, size_t val)
|
||||||
|
{
|
||||||
|
return git_libgit2_opts(opt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _go_git_opts_get_size_t(int opt, size_t *val)
|
||||||
|
{
|
||||||
|
return git_libgit2_opts(opt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
"github.com/libgit2/git2go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MakeGitError(err C.int) error {
|
||||||
|
return git.MakeGitError2(int(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchPath(level git.ConfigLevel) (string, error) {
|
||||||
|
var buf C.git_buf
|
||||||
|
defer C.git_buf_free(&buf)
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
err := C._go_git_opts_get_search_path(C.int(level), &buf)
|
||||||
|
if err < 0 {
|
||||||
|
return "", MakeGitError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return C.GoString(buf.ptr), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetSearchPath(level git.ConfigLevel, path string) error {
|
||||||
|
cpath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
err := C._go_git_opts_set_search_path(C.int(level), cpath)
|
||||||
|
if err < 0 {
|
||||||
|
return MakeGitError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSizet(opt C.int) (int, error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
var val C.size_t
|
||||||
|
err := C._go_git_opts_get_size_t(opt, &val);
|
||||||
|
if err < 0 {
|
||||||
|
return 0, MakeGitError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(val), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func setSizet(opt C.int, val int) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cval := C.size_t(val)
|
||||||
|
err := C._go_git_opts_set_size_t(opt, cval);
|
||||||
|
if err < 0 {
|
||||||
|
return MakeGitError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MwindowSize() (int, error) {
|
||||||
|
return getSizet(C.GIT_OPT_GET_MWINDOW_SIZE)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetMwindowSize(size int) error {
|
||||||
|
return setSizet(C.GIT_OPT_SET_MWINDOW_SIZE, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MwindowMappedLimit() (int, error) {
|
||||||
|
return getSizet(C.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetMwindowMappedLimit(size int) error {
|
||||||
|
return setSizet(C.GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size)
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package settings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"runtime"
|
||||||
|
"github.com/libgit2/git2go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type pathPair struct {
|
||||||
|
Level git.ConfigLevel
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSearchPath(t *testing.T) {
|
||||||
|
paths := []pathPair{
|
||||||
|
pathPair{git.ConfigLevelSystem, "/tmp/system"},
|
||||||
|
pathPair{git.ConfigLevelGlobal, "/tmp/global"},
|
||||||
|
pathPair{git.ConfigLevelXDG, "/tmp/xdg"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pair := range paths {
|
||||||
|
err := SetSearchPath(pair.Level, pair.Path)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
actual, err := SearchPath(pair.Level)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if pair.Path != actual {
|
||||||
|
t.Fatal("Search paths don't match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMmapSizes(t *testing.T) {
|
||||||
|
size := 42 * 1024
|
||||||
|
|
||||||
|
err := SetMwindowSize(size)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
actual, err := MwindowSize()
|
||||||
|
if size != actual {
|
||||||
|
t.Fatal("Sizes don't match")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = SetMwindowMappedLimit(size)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
actual, err = MwindowMappedLimit()
|
||||||
|
if size != actual {
|
||||||
|
t.Fatal("Sizes don't match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkFatal(t *testing.T, err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// The failure happens at wherever we were called, not here
|
||||||
|
_, file, line, ok := runtime.Caller(1)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatalf("Fail at %v:%v; %v", file, line, err)
|
||||||
|
}
|
|
@ -287,22 +287,22 @@ func (sub *Submodule) Open() (*Repository, error) {
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sub *Submodule) Reload() error {
|
func (sub *Submodule) Reload(force bool) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_submodule_reload(sub.ptr)
|
ret := C.git_submodule_reload(sub.ptr, cbool(force))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) ReloadAllSubmodules() error {
|
func (repo *Repository) ReloadAllSubmodules(force bool) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_submodule_reload_all(repo.ptr)
|
ret := C.git_submodule_reload_all(repo.ptr, cbool(force))
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return MakeGitError(ret)
|
return MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
11
tree.go
11
tree.go
|
@ -26,6 +26,7 @@ const (
|
||||||
|
|
||||||
type Tree struct {
|
type Tree struct {
|
||||||
gitObject
|
gitObject
|
||||||
|
cast_ptr *C.git_tree
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeEntry struct {
|
type TreeEntry struct {
|
||||||
|
@ -48,7 +49,7 @@ func (t Tree) EntryByName(filename string) *TreeEntry {
|
||||||
cname := C.CString(filename)
|
cname := C.CString(filename)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
entry := C.git_tree_entry_byname(t.ptr, cname)
|
entry := C.git_tree_entry_byname(t.cast_ptr, cname)
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -66,7 +67,7 @@ func (t Tree) EntryByPath(path string) (*TreeEntry, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_tree_entry_bypath(&entry, t.ptr, cpath)
|
ret := C.git_tree_entry_bypath(&entry, t.cast_ptr, cpath)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +76,7 @@ func (t Tree) EntryByPath(path string) (*TreeEntry, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) EntryByIndex(index uint64) *TreeEntry {
|
func (t Tree) EntryByIndex(index uint64) *TreeEntry {
|
||||||
entry := C.git_tree_entry_byindex(t.ptr, C.size_t(index))
|
entry := C.git_tree_entry_byindex(t.cast_ptr, C.size_t(index))
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ func (t Tree) EntryByIndex(index uint64) *TreeEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tree) EntryCount() uint64 {
|
func (t Tree) EntryCount() uint64 {
|
||||||
num := C.git_tree_entrycount(t.ptr)
|
num := C.git_tree_entrycount(t.cast_ptr)
|
||||||
return uint64(num)
|
return uint64(num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ func (t Tree) Walk(callback TreeWalkCallback) error {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C._go_git_treewalk(
|
err := C._go_git_treewalk(
|
||||||
t.ptr,
|
t.cast_ptr,
|
||||||
C.GIT_TREEWALK_PRE,
|
C.GIT_TREEWALK_PRE,
|
||||||
unsafe.Pointer(&callback),
|
unsafe.Pointer(&callback),
|
||||||
)
|
)
|
||||||
|
|
105
walk.go
105
walk.go
|
@ -9,6 +9,7 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RevWalk
|
// RevWalk
|
||||||
|
@ -37,8 +38,57 @@ func (v *RevWalk) Reset() {
|
||||||
C.git_revwalk_reset(v.ptr)
|
C.git_revwalk_reset(v.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RevWalk) Push(id *Oid) {
|
func (v *RevWalk) Push(id *Oid) error {
|
||||||
C.git_revwalk_push(v.ptr, id.toC())
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_push(v.ptr, id.toC())
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) PushGlob(glob string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cstr := C.CString(glob)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_push_glob(v.ptr, cstr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) PushRange(r string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cstr := C.CString(r)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_push_range(v.ptr, cstr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) PushRef(r string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cstr := C.CString(r)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_push_ref(v.ptr, cstr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RevWalk) PushHead() (err error) {
|
func (v *RevWalk) PushHead() (err error) {
|
||||||
|
@ -49,8 +99,57 @@ func (v *RevWalk) PushHead() (err error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
err = MakeGitError(ecode)
|
err = MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return
|
func (v *RevWalk) Hide(id *Oid) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_hide(v.ptr, id.toC())
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) HideGlob(glob string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cstr := C.CString(glob)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_hide_glob(v.ptr, cstr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) HideRef(r string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cstr := C.CString(r)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_hide_ref(v.ptr, cstr)
|
||||||
|
if ecode < 0 {
|
||||||
|
return MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *RevWalk) HideHead() (err error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_revwalk_hide_head(v.ptr)
|
||||||
|
if ecode < 0 {
|
||||||
|
err = MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RevWalk) Next(id *Oid) (err error) {
|
func (v *RevWalk) Next(id *Oid) (err error) {
|
||||||
|
|
Loading…
Reference in New Issue