aboutsummaryrefslogtreecommitdiff
path: root/obj_tag.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commit5cfbd8863dfb7c6af92497d9a5eb6eb63a6bd589 (patch)
tree42a871a72388bb6d40c479fbaa6eedde1cddc42e /obj_tag.go
parenthash: Generic hash-algorithm API (diff)
signature
Revert "hash: Generic hash-algorithm API"
This reverts commit 94bfb1fa147f80e6ec39009d41fc2f853925e0a5. Generics actually kinda suck for these purposes... once you look at it from the user's perspective.
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 ce42e41b..bf9ee97d 100644
--- a/obj_tag.go
+++ b/obj_tag.go
@@ -7,9 +7,9 @@ import (
)
// Tag models an annotated Git tag object.
-type Tag[T HashType] struct {
- Hash Hash[T]
- Target Hash[T]
+type Tag struct {
+ Hash Hash
+ Target Hash
TargetType ObjType
Name []byte
Tagger *Ident
@@ -17,13 +17,13 @@ type Tag[T HashType] struct {
}
// ObjType allows Tag to satisfy the Object interface.
-func (*Tag[T]) ObjType() ObjType {
+func (*Tag) ObjType() ObjType {
return ObjTag
}
// parseTag parses a tag object body.
-func parseTag[T HashType](id Hash[T], body []byte) (*Tag[T], error) {
- t := new(Tag[T])
+func parseTag(id Hash, body []byte, hashSize int) (*Tag, error) {
+ t := new(Tag)
t.Hash = id
i := 0
var haveTarget, haveType bool
@@ -41,7 +41,7 @@ func parseTag[T HashType](id Hash[T], body []byte) (*Tag[T], error) {
switch {
case bytes.HasPrefix(line, []byte("object ")):
- hash, err := ParseHash[T](string(line[7:]))
+ hash, err := ParseHashWithSize(string(line[7:]), hashSize)
if err != nil {
return nil, fmt.Errorf("furgit: tag: object: %w", err)
}
@@ -94,9 +94,9 @@ func parseTag[T HashType](id Hash[T], body []byte) (*Tag[T], error) {
return t, nil
}
-func tagBody[T HashType](t *Tag[T]) ([]byte, error) {
+func tagBody(t *Tag, hashSize int) ([]byte, error) {
var buf bytes.Buffer
- fmt.Fprintf(&buf, "object %s\n", t.Target.String())
+ fmt.Fprintf(&buf, "object %s\n", t.Target.StringWithSize(hashSize))
buf.WriteString("type ")
switch t.TargetType {
case ObjCommit:
@@ -128,8 +128,8 @@ func tagBody[T HashType](t *Tag[T]) ([]byte, error) {
}
// Serialize renders a Tag into canonical Git format.
-func (t *Tag[T]) Serialize() ([]byte, error) {
- body, err := tagBody(t)
+func (t *Tag) Serialize(hashSize int) ([]byte, error) {
+ body, err := tagBody(t, hashSize)
if err != nil {
return nil, err
}