Merge pull request #397 from libgit2/cmn/tag-generic
Tag any kind of object
This commit is contained in:
commit
7969aefd42
4
blob.go
4
blob.go
|
@ -20,6 +20,10 @@ type Blob struct {
|
||||||
cast_ptr *C.git_blob
|
cast_ptr *C.git_blob
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Blob) AsObject() *Object {
|
||||||
|
return &b.Object
|
||||||
|
}
|
||||||
|
|
||||||
func (v *Blob) Size() int64 {
|
func (v *Blob) Size() int64 {
|
||||||
ret := int64(C.git_blob_rawsize(v.cast_ptr))
|
ret := int64(C.git_blob_rawsize(v.cast_ptr))
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
|
|
|
@ -18,6 +18,10 @@ type Commit struct {
|
||||||
cast_ptr *C.git_commit
|
cast_ptr *C.git_commit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Commit) AsObject() *Object {
|
||||||
|
return &c.Object
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Commit) Message() string {
|
func (c *Commit) Message() string {
|
||||||
ret := C.GoString(C.git_commit_message(c.cast_ptr))
|
ret := C.GoString(C.git_commit_message(c.cast_ptr))
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
|
|
|
@ -26,6 +26,11 @@ type Object struct {
|
||||||
repo *Repository
|
repo *Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Objecter lets us accept any kind of Git object in functions.
|
||||||
|
type Objecter interface {
|
||||||
|
AsObject() *Object
|
||||||
|
}
|
||||||
|
|
||||||
func (t ObjectType) String() string {
|
func (t ObjectType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case ObjectAny:
|
case ObjectAny:
|
||||||
|
|
23
tag.go
23
tag.go
|
@ -17,6 +17,10 @@ type Tag struct {
|
||||||
cast_ptr *C.git_tag
|
cast_ptr *C.git_tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tag) AsObject() *Object {
|
||||||
|
return &t.Object
|
||||||
|
}
|
||||||
|
|
||||||
func (t Tag) Message() string {
|
func (t Tag) Message() string {
|
||||||
ret := C.GoString(C.git_tag_message(t.cast_ptr))
|
ret := C.GoString(C.git_tag_message(t.cast_ptr))
|
||||||
runtime.KeepAlive(t)
|
runtime.KeepAlive(t)
|
||||||
|
@ -63,8 +67,7 @@ type TagsCollection struct {
|
||||||
repo *Repository
|
repo *Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TagsCollection) Create(
|
func (c *TagsCollection) Create(name string, obj Objecter, tagger *Signature, message string) (*Oid, error) {
|
||||||
name string, commit *Commit, tagger *Signature, message string) (*Oid, error) {
|
|
||||||
|
|
||||||
oid := new(Oid)
|
oid := new(Oid)
|
||||||
|
|
||||||
|
@ -80,13 +83,13 @@ func (c *TagsCollection) Create(
|
||||||
}
|
}
|
||||||
defer C.git_signature_free(taggerSig)
|
defer C.git_signature_free(taggerSig)
|
||||||
|
|
||||||
ctarget := commit.ptr
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_tag_create(oid.toC(), c.repo.ptr, cname, ctarget, taggerSig, cmessage, 0)
|
o := obj.AsObject()
|
||||||
|
ret := C.git_tag_create(oid.toC(), c.repo.ptr, cname, o.ptr, taggerSig, cmessage, 0)
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
|
runtime.KeepAlive(obj)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -110,7 +113,7 @@ func (c *TagsCollection) Remove(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateLightweight creates a new lightweight tag pointing to a commit
|
// CreateLightweight creates a new lightweight tag pointing to an object
|
||||||
// and returns the id of the target object.
|
// and returns the id of the target object.
|
||||||
//
|
//
|
||||||
// The name of the tag is validated for consistency (see git_tag_create() for the rules
|
// The name of the tag is validated for consistency (see git_tag_create() for the rules
|
||||||
|
@ -122,20 +125,20 @@ func (c *TagsCollection) Remove(name string) error {
|
||||||
// The created tag is a simple reference and can be queried using
|
// The created tag is a simple reference and can be queried using
|
||||||
// repo.References.Lookup("refs/tags/<name>"). The name of the tag (eg "v1.0.0")
|
// repo.References.Lookup("refs/tags/<name>"). The name of the tag (eg "v1.0.0")
|
||||||
// is queried with ref.Shorthand().
|
// is queried with ref.Shorthand().
|
||||||
func (c *TagsCollection) CreateLightweight(name string, commit *Commit, force bool) (*Oid, error) {
|
func (c *TagsCollection) CreateLightweight(name string, obj Objecter, force bool) (*Oid, error) {
|
||||||
|
|
||||||
oid := new(Oid)
|
oid := new(Oid)
|
||||||
|
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
ctarget := commit.ptr
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C.git_tag_create_lightweight(oid.toC(), c.repo.ptr, cname, ctarget, cbool(force))
|
o := obj.AsObject()
|
||||||
|
err := C.git_tag_create_lightweight(oid.toC(), c.repo.ptr, cname, o.ptr, cbool(force))
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
|
runtime.KeepAlive(obj)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return nil, MakeGitError(err)
|
return nil, MakeGitError(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue