diff options
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | Makefile | 11 | ||||
| -rw-r--r-- | blob.go | 2 | ||||
| -rw-r--r-- | checkout.go | 4 | ||||
| -rw-r--r-- | commit.go | 6 | ||||
| -rw-r--r-- | describe.go | 2 | ||||
| -rw-r--r-- | git.go | 1 | ||||
| -rw-r--r-- | index.go | 6 | ||||
| -rw-r--r-- | index_test.go | 5 | ||||
| -rw-r--r-- | merge.go | 12 | ||||
| -rw-r--r-- | merge_test.go | 5 | ||||
| -rw-r--r-- | object.go | 173 | ||||
| -rw-r--r-- | object_test.go | 24 | ||||
| -rw-r--r-- | odb.go | 4 | ||||
| -rw-r--r-- | reference.go | 2 | ||||
| -rw-r--r-- | remote.go | 26 | ||||
| -rw-r--r-- | remote_test.go | 2 | ||||
| -rw-r--r-- | repository.go | 22 | ||||
| -rw-r--r-- | reset.go | 2 | ||||
| -rw-r--r-- | revparse.go | 16 | ||||
| -rw-r--r-- | revparse_test.go | 2 | ||||
| -rw-r--r-- | tag.go | 8 | ||||
| -rw-r--r-- | tree.go | 2 | ||||
| m--------- | vendor/libgit2 | 0 |
24 files changed, 209 insertions, 131 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8eb5872 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/libgit2"] + path = vendor/libgit2 + url = https://github.com/libgit2/libgit2 @@ -1,8 +1,11 @@ default: test -test: +build-libgit2: + ./script/build-libgit2-static.sh + +test: build-libgit2 go run script/check-MakeGitError-thread-lock.go - go test ./... + ./script/with-static.sh go test ./... -install: - go install ./... +install: build-libgit2 + ./script/with-static.sh go install ./... @@ -18,7 +18,7 @@ import ( ) type Blob struct { - gitObject + Object cast_ptr *C.git_blob } diff --git a/checkout.go b/checkout.go index e0c067e..ce2f469 100644 --- a/checkout.go +++ b/checkout.go @@ -44,7 +44,7 @@ type CheckoutOpts struct { FileMode os.FileMode // Default is 0644 or 0755 as dictated by blob FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY TargetDirectory string // Alternative checkout path to workdir - Paths []string + Paths []string } func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOpts { @@ -156,4 +156,4 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOpts) error { } return nil -}
\ No newline at end of file +} @@ -14,7 +14,7 @@ import ( // Commit type Commit struct { - gitObject + Object cast_ptr *C.git_commit } @@ -37,7 +37,7 @@ func (c Commit) Tree() (*Tree, error) { return nil, MakeGitError(err) } - return allocObject((*C.git_object)(ptr), c.repo).(*Tree), nil + return allocTree(ptr, c.repo), nil } func (c Commit) TreeId() *Oid { @@ -61,7 +61,7 @@ func (c *Commit) Parent(n uint) *Commit { return nil } - return allocObject((*C.git_object)(cobj), c.repo).(*Commit) + return allocCommit(cobj, c.repo) } func (c *Commit) ParentId(n uint) *Oid { diff --git a/describe.go b/describe.go index c6f9a79..d75dbcb 100644 --- a/describe.go +++ b/describe.go @@ -127,7 +127,7 @@ func (c *Commit) Describe(opts *DescribeOptions) (*DescribeResult, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - ecode := C.git_describe_commit(&resultPtr, c.gitObject.ptr, cDescribeOpts) + ecode := C.git_describe_commit(&resultPtr, c.ptr, cDescribeOpts) if ecode < 0 { return nil, MakeGitError(ecode) } @@ -3,7 +3,6 @@ package git /* #include <git2.h> #include <git2/sys/openssl.h> -#cgo pkg-config: libgit2 */ import "C" import ( @@ -51,8 +51,8 @@ func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry { return nil } return &IndexEntry{ - IndexTime { int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds) }, - IndexTime { int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds) }, + IndexTime{int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds)}, + IndexTime{int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds)}, Filemode(entry.mode), uint32(entry.uid), uint32(entry.gid), @@ -280,7 +280,7 @@ func (v *Index) ReadTree(tree *Tree) error { runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_index_read_tree(v.ptr, tree.cast_ptr); + ret := C.git_index_read_tree(v.ptr, tree.cast_ptr) if ret < 0 { return MakeGitError(ret) } diff --git a/index_test.go b/index_test.go index 7c65f4f..5f6b375 100644 --- a/index_test.go +++ b/index_test.go @@ -32,10 +32,11 @@ func TestIndexReadTree(t *testing.T) { ref, err := repo.Head() checkFatal(t, err) - obj, err := ref.Peel(ObjectTree); + obj, err := ref.Peel(ObjectTree) checkFatal(t, err) - tree := obj.(*Tree) + tree, err := obj.AsTree() + checkFatal(t, err) idx, err := NewIndex() checkFatal(t, err) @@ -85,8 +85,8 @@ const ( ) type MergeOptions struct { - Version uint - TreeFlags MergeTreeFlag + Version uint + TreeFlags MergeTreeFlag RenameThreshold uint TargetLimit uint @@ -98,7 +98,7 @@ type MergeOptions struct { func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions { return MergeOptions{ Version: uint(opts.version), - TreeFlags: MergeTreeFlag(opts.tree_flags), + TreeFlags: MergeTreeFlag(opts.tree_flags), RenameThreshold: uint(opts.rename_threshold), TargetLimit: uint(opts.target_limit), FileFavor: MergeFileFavor(opts.file_favor), @@ -259,10 +259,10 @@ func (r *Repository) MergeBases(one, two *Oid) ([]*Oid, error) { } oids := make([]*Oid, coids.count) - hdr := reflect.SliceHeader { + hdr := reflect.SliceHeader{ Data: uintptr(unsafe.Pointer(coids.ids)), - Len: int(coids.count), - Cap: int(coids.count), + Len: int(coids.count), + Cap: int(coids.count), } goSlice := *(*[]C.git_oid)(unsafe.Pointer(&hdr)) diff --git a/merge_test.go b/merge_test.go index ad01319..8059727 100644 --- a/merge_test.go +++ b/merge_test.go @@ -115,7 +115,10 @@ func appendCommit(t *testing.T, repo *Repository) (*Oid, *Oid) { parent, err := ref.Peel(ObjectCommit) checkFatal(t, err) - commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree, parent.(*Commit)) + parentCommit, err := parent.AsCommit() + checkFatal(t, err) + + commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree, parentCommit) checkFatal(t, err) return commitId, treeId @@ -4,7 +4,11 @@ package git #include <git2.h> */ import "C" -import "runtime" +import ( + "errors" + "fmt" + "runtime" +) type ObjectType int @@ -17,15 +21,7 @@ const ( ObjectTag ObjectType = C.GIT_OBJ_TAG ) -type Object interface { - Free() - Id() *Oid - Type() ObjectType - Owner() *Repository - Peel(t ObjectType) (Object, error) -} - -type gitObject struct { +type Object struct { ptr *C.git_object repo *Repository } @@ -49,23 +45,128 @@ func (t ObjectType) String() string { return "" } -func (o gitObject) Id() *Oid { +func (o *Object) Id() *Oid { return newOidFromC(C.git_object_id(o.ptr)) } -func (o gitObject) Type() ObjectType { +func (o *Object) Type() ObjectType { return ObjectType(C.git_object_type(o.ptr)) } // Owner returns a weak reference to the repository which owns this -// object -func (o gitObject) Owner() *Repository { +// object. This won't keep the underlying repository alive. +func (o *Object) Owner() *Repository { return &Repository{ ptr: C.git_object_owner(o.ptr), } } -func (o *gitObject) Free() { +func dupObject(obj *Object, kind ObjectType) (*C.git_object, error) { + if obj.Type() != kind { + return nil, errors.New(fmt.Sprintf("object is not a %v", kind)) + } + + var cobj *C.git_object + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if err := C.git_object_dup(&cobj, obj.ptr); err < 0 { + return nil, MakeGitError(err) + } + + return cobj, nil +} + +func allocTree(ptr *C.git_tree, repo *Repository) *Tree { + tree := &Tree{ + Object: Object{ + ptr: (*C.git_object)(ptr), + repo: repo, + }, + cast_ptr: ptr, + } + runtime.SetFinalizer(tree, (*Tree).Free) + + return tree +} + +func (o *Object) AsTree() (*Tree, error) { + cobj, err := dupObject(o, ObjectTree) + if err != nil { + return nil, err + } + + return allocTree((*C.git_tree)(cobj), o.repo), nil +} + +func allocCommit(ptr *C.git_commit, repo *Repository) *Commit { + commit := &Commit{ + Object: Object{ + ptr: (*C.git_object)(ptr), + repo: repo, + }, + cast_ptr: ptr, + } + runtime.SetFinalizer(commit, (*Commit).Free) + + return commit +} + +func (o *Object) AsCommit() (*Commit, error) { + cobj, err := dupObject(o, ObjectCommit) + if err != nil { + return nil, err + } + + return allocCommit((*C.git_commit)(cobj), o.repo), nil +} + +func allocBlob(ptr *C.git_blob, repo *Repository) *Blob { + blob := &Blob{ + Object: Object{ + ptr: (*C.git_object)(ptr), + repo: repo, + }, + cast_ptr: ptr, + } + runtime.SetFinalizer(blob, (*Blob).Free) + + return blob +} + +func (o *Object) AsBlob() (*Blob, error) { + cobj, err := dupObject(o, ObjectBlob) + if err != nil { + return nil, err + } + + return allocBlob((*C.git_blob)(cobj), o.repo), nil +} + +func allocTag(ptr *C.git_tag, repo *Repository) *Tag { + tag := &Tag{ + Object: Object{ + ptr: (*C.git_object)(ptr), + repo: repo, + }, + cast_ptr: ptr, + } + runtime.SetFinalizer(tag, (*Tag).Free) + + return tag +} + +func (o *Object) AsTag() (*Tag, error) { + cobj, err := dupObject(o, ObjectTag) + if err != nil { + return nil, err + } + + return allocTag((*C.git_tag)(cobj), o.repo), nil +} + +func (o *Object) Free() { runtime.SetFinalizer(o, nil) C.git_object_free(o.ptr) } @@ -82,7 +183,7 @@ func (o *gitObject) Free() { // // If peeling a tag we discover an object which cannot be peeled to the target // type due to the object model, an error will be returned. -func (o *gitObject) Peel(t ObjectType) (Object, error) { +func (o *Object) Peel(t ObjectType) (*Object, error) { var cobj *C.git_object runtime.LockOSThread() @@ -95,44 +196,12 @@ func (o *gitObject) Peel(t ObjectType) (Object, error) { return allocObject(cobj, o.repo), nil } -func allocObject(cobj *C.git_object, repo *Repository) Object { - obj := gitObject{ +func allocObject(cobj *C.git_object, repo *Repository) *Object { + obj := &Object{ ptr: cobj, repo: repo, } + runtime.SetFinalizer(obj, (*Object).Free) - switch ObjectType(C.git_object_type(cobj)) { - case ObjectCommit: - commit := &Commit{ - gitObject: obj, - cast_ptr: (*C.git_commit)(cobj), - } - runtime.SetFinalizer(commit, (*Commit).Free) - return commit - - case ObjectTree: - tree := &Tree{ - gitObject: obj, - cast_ptr: (*C.git_tree)(cobj), - } - runtime.SetFinalizer(tree, (*Tree).Free) - return tree - - case ObjectBlob: - blob := &Blob{ - gitObject: obj, - cast_ptr: (*C.git_blob)(cobj), - } - runtime.SetFinalizer(blob, (*Blob).Free) - return blob - case ObjectTag: - tag := &Tag{ - gitObject: obj, - cast_ptr: (*C.git_tag)(cobj), - } - runtime.SetFinalizer(tag, (*Tag).Free) - return tag - } - - return nil + return obj } diff --git a/object_test.go b/object_test.go index ef6c5a1..2ae2a6a 100644 --- a/object_test.go +++ b/object_test.go @@ -10,12 +10,12 @@ func TestObjectPoymorphism(t *testing.T) { commitId, treeId := seedTestRepo(t, repo) - var obj Object + var obj *Object commit, err := repo.LookupCommit(commitId) checkFatal(t, err) - obj = commit + obj = &commit.Object if obj.Type() != ObjectCommit { t.Fatalf("Wrong object type, expected commit, have %v", obj.Type()) } @@ -27,13 +27,13 @@ func TestObjectPoymorphism(t *testing.T) { tree, err := repo.LookupTree(treeId) checkFatal(t, err) - obj = tree + obj = &tree.Object if obj.Type() != ObjectTree { t.Fatalf("Wrong object type, expected tree, have %v", obj.Type()) } - tree2, ok := obj.(*Tree) - if !ok { + tree2, err := obj.AsTree() + if err != nil { t.Fatalf("Converting back to *Tree is not ok") } @@ -46,16 +46,16 @@ func TestObjectPoymorphism(t *testing.T) { t.Fatal("Wrong filemode for \"README\"") } - _, ok = obj.(*Commit) - if ok { + _, err = obj.AsCommit() + if err == nil { t.Fatalf("*Tree is somehow the same as *Commit") } obj, err = repo.Lookup(tree.Id()) checkFatal(t, err) - _, ok = obj.(*Tree) - if !ok { + _, err = obj.AsTree() + if err != nil { t.Fatalf("Lookup creates the wrong type") } @@ -99,8 +99,8 @@ func TestObjectOwner(t *testing.T) { tree, err := repo.LookupTree(treeId) checkFatal(t, err) - checkOwner(t, repo, commit) - checkOwner(t, repo, tree) + checkOwner(t, repo, commit.Object) + checkOwner(t, repo, tree.Object) } func TestObjectPeel(t *testing.T) { @@ -109,7 +109,7 @@ func TestObjectPeel(t *testing.T) { commitID, treeID := seedTestRepo(t, repo) - var obj Object + var obj *Object commit, err := repo.LookupCommit(commitID) checkFatal(t, err) @@ -8,10 +8,10 @@ extern void _go_git_odb_backend_free(git_odb_backend *backend); */ import "C" import ( + "fmt" "reflect" "runtime" "unsafe" - "fmt" ) type Odb struct { @@ -130,7 +130,7 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error { defer pointerHandles.Untrack(handle) ret := C._go_git_odb_foreach(v.ptr, handle) - fmt.Println("ret %v", ret); + fmt.Println("ret %v", ret) if ret == C.GIT_EUSER { return data.err } else if ret < 0 { diff --git a/reference.go b/reference.go index 140082f..463f2fc 100644 --- a/reference.go +++ b/reference.go @@ -263,7 +263,7 @@ func (v *Reference) Delete() error { return nil } -func (v *Reference) Peel(t ObjectType) (Object, error) { +func (v *Reference) Peel(t ObjectType) (*Object, error) { var cobj *C.git_object runtime.LockOSThread() @@ -72,12 +72,12 @@ type RemoteCallbacks struct { type FetchPrune uint const ( - // Use the setting from the configuration + // Use the setting from the configuration FetchPruneUnspecified FetchPrune = C.GIT_FETCH_PRUNE_UNSPECIFIED // Force pruning on - FetchPruneOn FetchPrune = C.GIT_FETCH_PRUNE + FetchPruneOn FetchPrune = C.GIT_FETCH_PRUNE // Force pruning off - FetchNoPrune FetchPrune = C.GIT_FETCH_NO_PRUNE + FetchNoPrune FetchPrune = C.GIT_FETCH_NO_PRUNE ) type DownloadTags uint @@ -88,20 +88,20 @@ const ( DownloadTagsUnspecified DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED // Ask the server for tags pointing to objects we're already // downloading. - DownloadTagsAuto DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_AUTO + DownloadTagsAuto DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_AUTO // Don't ask for any tags beyond the refspecs. - DownloadTagsNone DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_NONE + DownloadTagsNone DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_NONE // Ask for the all the tags. - DownloadTagsAll DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_ALL + DownloadTagsAll DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_ALL ) type FetchOptions struct { // Callbacks to use for this fetch operation RemoteCallbacks RemoteCallbacks // Whether to perform a prune after the fetch - Prune FetchPrune + Prune FetchPrune // Whether to write the results to FETCH_HEAD. Defaults to // on. Leave this default in order to behave like git. UpdateFetchhead bool @@ -111,7 +111,7 @@ type FetchOptions struct { // downloading all of them. // // The default is to auto-follow tags. - DownloadTags DownloadTags + DownloadTags DownloadTags } type Remote struct { @@ -588,7 +588,7 @@ func (o *Remote) RefspecCount() uint { func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) { C.git_fetch_init_options(options, C.GIT_FETCH_OPTIONS_VERSION) if opts == nil { - return; + return } populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks) options.prune = C.git_fetch_prune_t(opts.Prune) @@ -611,7 +611,7 @@ func populatePushOptions(options *C.git_push_options, opts *PushOptions) { // to use for this fetch, use an empty list to use the refspecs from // the configuration; msg specifies what to use for the reflog // entries. Leave "" to use defaults. -func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error { +func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error { var cmsg *C.char = nil if msg != "" { cmsg = C.CString(msg) @@ -624,7 +624,7 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error defer freeStrarray(&crefspecs) var coptions C.git_fetch_options - populateFetchOptions(&coptions, opts); + populateFetchOptions(&coptions, opts) defer untrackCalbacksPayload(&coptions.callbacks) runtime.LockOSThread() @@ -646,7 +646,7 @@ func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error { } func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error { - var ccallbacks C.git_remote_callbacks; + var ccallbacks C.git_remote_callbacks populateRemoteCallbacks(&ccallbacks, callbacks) runtime.LockOSThread() @@ -729,7 +729,7 @@ func (o *Remote) PruneRefs() bool { } func (o *Remote) Prune(callbacks *RemoteCallbacks) error { - var ccallbacks C.git_remote_callbacks; + var ccallbacks C.git_remote_callbacks populateRemoteCallbacks(&ccallbacks, callbacks) runtime.LockOSThread() diff --git a/remote_test.go b/remote_test.go index 73c637f..dac3dbe 100644 --- a/remote_test.go +++ b/remote_test.go @@ -39,7 +39,7 @@ func TestCertificateCheck(t *testing.T) { remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository") checkFatal(t, err) - options := FetchOptions { + options := FetchOptions{ RemoteCallbacks: RemoteCallbacks{ CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode { return assertHostname(cert, valid, hostname, t) diff --git a/repository.go b/repository.go index 62fde6d..d8e398b 100644 --- a/repository.go +++ b/repository.go @@ -12,11 +12,11 @@ import ( // Repository type Repository struct { - ptr *C.git_repository + ptr *C.git_repository // Remotes represents the collection of remotes and can be // used to add, remove and configure remotes for this // repository. - Remotes RemoteCollection + Remotes RemoteCollection // Submodules represents the collection of submodules and can // be used to add, remove and configure submodules in this // repostiory. @@ -26,7 +26,7 @@ type Repository struct { References ReferenceCollection // Notes represents the collection of notes and can be used to // read, write and delete notes from this repository. - Notes NoteCollection + Notes NoteCollection // Tags represents the collection of tags and can be used to create, // list and iterate tags in this repository. Tags TagsCollection @@ -35,10 +35,10 @@ type Repository struct { func newRepositoryFromC(ptr *C.git_repository) *Repository { repo := &Repository{ptr: ptr} - repo.Remotes.repo = repo + repo.Remotes.repo = repo repo.Submodules.repo = repo repo.References.repo = repo - repo.Notes.repo = repo + repo.Notes.repo = repo repo.Tags.repo = repo runtime.SetFinalizer(repo, (*Repository).Free) @@ -145,7 +145,7 @@ func (v *Repository) Index() (*Index, error) { return newIndexFromC(ptr), nil } -func (v *Repository) lookupType(id *Oid, t ObjectType) (Object, error) { +func (v *Repository) lookupType(id *Oid, t ObjectType) (*Object, error) { var ptr *C.git_object runtime.LockOSThread() @@ -159,7 +159,7 @@ func (v *Repository) lookupType(id *Oid, t ObjectType) (Object, error) { return allocObject(ptr, v), nil } -func (v *Repository) Lookup(id *Oid) (Object, error) { +func (v *Repository) Lookup(id *Oid) (*Object, error) { return v.lookupType(id, ObjectAny) } @@ -169,7 +169,7 @@ func (v *Repository) LookupTree(id *Oid) (*Tree, error) { return nil, err } - return obj.(*Tree), nil + return obj.AsTree() } func (v *Repository) LookupCommit(id *Oid) (*Commit, error) { @@ -178,7 +178,7 @@ func (v *Repository) LookupCommit(id *Oid) (*Commit, error) { return nil, err } - return obj.(*Commit), nil + return obj.AsCommit() } func (v *Repository) LookupBlob(id *Oid) (*Blob, error) { @@ -187,7 +187,7 @@ func (v *Repository) LookupBlob(id *Oid) (*Blob, error) { return nil, err } - return obj.(*Blob), nil + return obj.AsBlob() } func (v *Repository) LookupTag(id *Oid) (*Tag, error) { @@ -196,7 +196,7 @@ func (v *Repository) LookupTag(id *Oid) (*Tag, error) { return nil, err } - return obj.(*Tag), nil + return obj.AsTag() } func (v *Repository) Head() (*Reference, error) { @@ -17,7 +17,7 @@ const ( func (r *Repository) ResetToCommit(commit *Commit, resetType ResetType, opts *CheckoutOpts) error { runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_reset(r.ptr, commit.gitObject.ptr, C.git_reset_t(resetType), opts.toC()) + ret := C.git_reset(r.ptr, commit.ptr, C.git_reset_t(resetType), opts.toC()) if ret < 0 { return MakeGitError(ret) diff --git a/revparse.go b/revparse.go index 7eb04f1..950932b 100644 --- a/revparse.go +++ b/revparse.go @@ -20,16 +20,16 @@ const ( ) type Revspec struct { - to Object - from Object + to *Object + from *Object flags RevparseFlag } -func (rs *Revspec) To() Object { +func (rs *Revspec) To() *Object { return rs.to } -func (rs *Revspec) From() Object { +func (rs *Revspec) From() *Object { return rs.from } @@ -38,8 +38,8 @@ func (rs *Revspec) Flags() RevparseFlag { } func newRevspecFromC(ptr *C.git_revspec, repo *Repository) *Revspec { - var to Object - var from Object + var to *Object + var from *Object if ptr.to != nil { to = allocObject(ptr.to, repo) @@ -73,7 +73,7 @@ func (r *Repository) Revparse(spec string) (*Revspec, error) { return newRevspecFromC(&crevspec, r), nil } -func (v *Repository) RevparseSingle(spec string) (Object, error) { +func (v *Repository) RevparseSingle(spec string) (*Object, error) { cspec := C.CString(spec) defer C.free(unsafe.Pointer(cspec)) @@ -90,7 +90,7 @@ func (v *Repository) RevparseSingle(spec string) (Object, error) { return allocObject(ptr, v), nil } -func (r *Repository) RevparseExt(spec string) (Object, *Reference, error) { +func (r *Repository) RevparseExt(spec string) (*Object, *Reference, error) { cspec := C.CString(spec) defer C.free(unsafe.Pointer(cspec)) diff --git a/revparse_test.go b/revparse_test.go index 091a76b..75e9ffd 100644 --- a/revparse_test.go +++ b/revparse_test.go @@ -46,7 +46,7 @@ func TestRevparseExt(t *testing.T) { } } -func checkObject(t *testing.T, obj Object, id *Oid) { +func checkObject(t *testing.T, obj *Object, id *Oid) { if obj == nil { t.Fatalf("bad object") } @@ -13,7 +13,7 @@ import ( // Tag type Tag struct { - gitObject + Object cast_ptr *C.git_tag } @@ -30,7 +30,7 @@ func (t Tag) Tagger() *Signature { return newSignatureFromC(cast_ptr) } -func (t Tag) Target() Object { +func (t Tag) Target() *Object { var ptr *C.git_object ret := C.git_tag_target(&ptr, t.cast_ptr) @@ -70,7 +70,7 @@ func (c *TagsCollection) Create( } defer C.git_signature_free(taggerSig) - ctarget := commit.gitObject.ptr + ctarget := commit.ptr runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -102,7 +102,7 @@ func (c *TagsCollection) CreateLightweight(name string, commit *Commit, force bo cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) - ctarget := commit.gitObject.ptr + ctarget := commit.ptr runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -23,7 +23,7 @@ const ( ) type Tree struct { - gitObject + Object cast_ptr *C.git_tree } diff --git a/vendor/libgit2 b/vendor/libgit2 new file mode 160000 +Subproject ed38e26db5435b519d8b796e4b6c2c660fe982b |
