Adjust to Go tip changes
It does not like breaking aliasing rules, so let's keep a casted pointer for when libgit2 wants that.
This commit is contained in:
parent
286ff62b14
commit
a06f4a030a
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
|
||||||
|
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,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]
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,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)
|
||||||
|
@ -331,7 +331,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
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),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue