2014-07-24 17:37:59 -05:00
|
|
|
package git
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <git2.h>
|
|
|
|
#include <git2/errors.h>
|
|
|
|
|
|
|
|
extern void _go_git_revspec_free(git_revspec *revspec);
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RevSpec struct {
|
|
|
|
ptr *C.git_revspec
|
|
|
|
repo *Repository
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRevSpecFrom(ptr *C.git_revspec, repo *Repository) *RevSpec {
|
|
|
|
rev := &RevSpec{
|
|
|
|
ptr: ptr,
|
|
|
|
repo: repo,
|
|
|
|
}
|
|
|
|
|
|
|
|
return rev
|
|
|
|
}
|
|
|
|
|
2014-07-24 19:02:14 -05:00
|
|
|
func (r *RevSpec) From() Object {
|
|
|
|
if r.ptr.from == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocObject(r.ptr.from, r.repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RevSpec) To() Object {
|
|
|
|
if r.ptr.to == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocObject(r.ptr.to, r.repo)
|
2014-07-24 17:37:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Repository) RevParse(spec string) (*RevSpec, error) {
|
|
|
|
cspec := C.CString(spec)
|
|
|
|
defer C.free(unsafe.Pointer(cspec))
|
2014-07-24 19:02:14 -05:00
|
|
|
|
2014-07-24 19:20:22 -05:00
|
|
|
ptr := new(C.git_revspec)
|
2014-07-24 17:37:59 -05:00
|
|
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
|
|
|
ecode := C.git_revparse(ptr, r.ptr, cspec)
|
2014-07-24 19:02:14 -05:00
|
|
|
if ecode != 0 {
|
2014-07-24 17:37:59 -05:00
|
|
|
return nil, MakeGitError(ecode)
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRevSpecFrom(ptr, r), nil
|
|
|
|
}
|