Skip to content

Commit 916d555

Browse files
committed
tag: accept an Objecter for creating a tag
This lets us create a tag for any kind of object.
1 parent 7f685a6 commit 916d555

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tag.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ type TagsCollection struct {
6767
repo *Repository
6868
}
6969

70-
func (c *TagsCollection) Create(
71-
name string, commit *Commit, tagger *Signature, message string) (*Oid, error) {
70+
func (c *TagsCollection) Create(name string, obj Objecter, tagger *Signature, message string) (*Oid, error) {
7271

7372
oid := new(Oid)
7473

@@ -84,13 +83,13 @@ func (c *TagsCollection) Create(
8483
}
8584
defer C.git_signature_free(taggerSig)
8685

87-
ctarget := commit.ptr
88-
8986
runtime.LockOSThread()
9087
defer runtime.UnlockOSThread()
9188

92-
ret := C.git_tag_create(oid.toC(), c.repo.ptr, cname, ctarget, taggerSig, cmessage, 0)
89+
o := obj.AsObject()
90+
ret := C.git_tag_create(oid.toC(), c.repo.ptr, cname, o.ptr, taggerSig, cmessage, 0)
9391
runtime.KeepAlive(c)
92+
runtime.KeepAlive(obj)
9493
if ret < 0 {
9594
return nil, MakeGitError(ret)
9695
}
@@ -114,7 +113,7 @@ func (c *TagsCollection) Remove(name string) error {
114113
return nil
115114
}
116115

117-
// CreateLightweight creates a new lightweight tag pointing to a commit
116+
// CreateLightweight creates a new lightweight tag pointing to an object
118117
// and returns the id of the target object.
119118
//
120119
// The name of the tag is validated for consistency (see git_tag_create() for the rules
@@ -126,20 +125,20 @@ func (c *TagsCollection) Remove(name string) error {
126125
// The created tag is a simple reference and can be queried using
127126
// repo.References.Lookup("refs/tags/<name>"). The name of the tag (eg "v1.0.0")
128127
// is queried with ref.Shorthand().
129-
func (c *TagsCollection) CreateLightweight(name string, commit *Commit, force bool) (*Oid, error) {
128+
func (c *TagsCollection) CreateLightweight(name string, obj Objecter, force bool) (*Oid, error) {
130129

131130
oid := new(Oid)
132131

133132
cname := C.CString(name)
134133
defer C.free(unsafe.Pointer(cname))
135134

136-
ctarget := commit.ptr
137-
138135
runtime.LockOSThread()
139136
defer runtime.UnlockOSThread()
140137

141-
err := C.git_tag_create_lightweight(oid.toC(), c.repo.ptr, cname, ctarget, cbool(force))
138+
o := obj.AsObject()
139+
err := C.git_tag_create_lightweight(oid.toC(), c.repo.ptr, cname, o.ptr, cbool(force))
142140
runtime.KeepAlive(c)
141+
runtime.KeepAlive(obj)
143142
if err < 0 {
144143
return nil, MakeGitError(err)
145144
}

0 commit comments

Comments
 (0)