aboutsummaryrefslogtreecommitdiff
path: root/obj_tag.go
diff options
context:
space:
mode:
Diffstat (limited to 'obj_tag.go')
-rw-r--r--obj_tag.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/obj_tag.go b/obj_tag.go
index bf9ee97d..ce42e41b 100644
--- a/obj_tag.go
+++ b/obj_tag.go
@@ -7,9 +7,9 @@ import (
)
// Tag models an annotated Git tag object.
-type Tag struct {
- Hash Hash
- Target Hash
+type Tag[T HashType] struct {
+ Hash Hash[T]
+ Target Hash[T]
TargetType ObjType
Name []byte
Tagger *Ident
@@ -17,13 +17,13 @@ type Tag struct {
}
// ObjType allows Tag to satisfy the Object interface.
-func (*Tag) ObjType() ObjType {
+func (*Tag[T]) ObjType() ObjType {
return ObjTag
}
// parseTag parses a tag object body.
-func parseTag(id Hash, body []byte, hashSize int) (*Tag, error) {
- t := new(Tag)
+func parseTag[T HashType](id Hash[T], body []byte) (*Tag[T], error) {
+ t := new(Tag[T])
t.Hash = id
i := 0
var haveTarget, haveType bool
@@ -41,7 +41,7 @@ func parseTag(id Hash, body []byte, hashSize int) (*Tag, error) {
switch {
case bytes.HasPrefix(line, []byte("object ")):
- hash, err := ParseHashWithSize(string(line[7:]), hashSize)
+ hash, err := ParseHash[T](string(line[7:]))
if err != nil {
return nil, fmt.Errorf("furgit: tag: object: %w", err)
}
@@ -94,9 +94,9 @@ func parseTag(id Hash, body []byte, hashSize int) (*Tag, error) {
return t, nil
}
-func tagBody(t *Tag, hashSize int) ([]byte, error) {
+func tagBody[T HashType](t *Tag[T]) ([]byte, error) {
var buf bytes.Buffer
- fmt.Fprintf(&buf, "object %s\n", t.Target.StringWithSize(hashSize))
+ fmt.Fprintf(&buf, "object %s\n", t.Target.String())
buf.WriteString("type ")
switch t.TargetType {
case ObjCommit:
@@ -128,8 +128,8 @@ func tagBody(t *Tag, hashSize int) ([]byte, error) {
}
// Serialize renders a Tag into canonical Git format.
-func (t *Tag) Serialize(hashSize int) ([]byte, error) {
- body, err := tagBody(t, hashSize)
+func (t *Tag[T]) Serialize() ([]byte, error) {
+ body, err := tagBody(t)
if err != nil {
return nil, err
}