merge: add two missing AnnotatedCommit methods #423

Merged
josharian merged 3 commits from more-annotated-commit into master 2020-02-23 09:05:26 -06:00
1 changed files with 25 additions and 0 deletions
Showing only changes of commit 03339f731a - Show all commits

View File

@ -27,6 +27,15 @@ func newAnnotatedCommitFromC(ptr *C.git_annotated_commit, r *Repository) *Annota
return mh return mh
} }
func (mh *AnnotatedCommit) Id() *Oid {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := newOidFromC(C.git_annotated_commit_id(mh.ptr))
runtime.KeepAlive(mh)
return ret
}
func (mh *AnnotatedCommit) Free() { func (mh *AnnotatedCommit) Free() {
runtime.SetFinalizer(mh, nil) runtime.SetFinalizer(mh, nil)
C.git_annotated_commit_free(mh.ptr) C.git_annotated_commit_free(mh.ptr)
@ -79,6 +88,22 @@ func (r *Repository) AnnotatedCommitFromRef(ref *Reference) (*AnnotatedCommit, e
return newAnnotatedCommitFromC(ptr, r), nil return newAnnotatedCommitFromC(ptr, r), nil
} }
func (r *Repository) AnnotatedCommitFromRevspec(spec string) (*AnnotatedCommit, error) {
crevspec := C.CString(spec)
defer C.free(unsafe.Pointer(crevspec))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_annotated_commit
ret := C.git_annotated_commit_from_revspec(&ptr, r.ptr, crevspec)
runtime.KeepAlive(r)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newAnnotatedCommitFromC(ptr, r), nil
}
type MergeTreeFlag int type MergeTreeFlag int
const ( const (