aboutsummaryrefslogtreecommitdiff
path: root/object
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-13 16:02:45 +0000
committerGravatar Runxi Yu2026-06-13 16:02:45 +0000
commit8e9b417b168b21dcccc26326b1d0ddd175dd768c (patch)
tree6ec7be219da60d5fe0fd0170de7574b6d5345b7e /object
parentobject/commit: Fix tests (diff)
object/tag: Don't clone on parse
Diffstat (limited to 'object')
-rw-r--r--object/tag/append.go2
-rw-r--r--object/tag/parse.go18
-rw-r--r--object/tag/tag.go2
3 files changed, 16 insertions, 6 deletions
diff --git a/object/tag/append.go b/object/tag/append.go
index 15a6fde9..2f524a73 100644
--- a/object/tag/append.go
+++ b/object/tag/append.go
@@ -27,7 +27,7 @@ func (tag *Tag) AppendWithoutHeader(dst []byte) ([]byte, error) {
for _, h := range tag.ExtraHeaders {
// GIGO on empty keys and such.
- dst = append(dst, []byte(h.Key)...)
+ dst = append(dst, h.Key...)
dst = append(dst, byte(' '))
dst = append(dst, h.Value...)
dst = append(dst, byte('\n'))
diff --git a/object/tag/parse.go b/object/tag/parse.go
index c5ea7e14..1fcc7c2c 100644
--- a/object/tag/parse.go
+++ b/object/tag/parse.go
@@ -15,6 +15,16 @@ import (
var ErrInvalidTag = errors.New("object/tag: invalid tag")
// Parse decodes a tag object body.
+//
+// The returned tag aliases body:
+// its Name, Message, and extra-header fields,
+// along with the byte fields of its tagger signature,
+// share body's backing array.
+// The tag inherits body's lifetime
+// and must not be mutated unless body may be.
+// Use [Tag.Clone] for an independent copy.
+//
+// Labels: Life-Parent, Mut-No.
func Parse(body []byte, objectFormat id.ObjectFormat) (*Tag, error) {
t := new(Tag)
@@ -56,7 +66,7 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Tag, error) {
return nil, fmt.Errorf("%w: tag name: %w", ErrInvalidTag, err)
}
- t.Name = append([]byte(nil), line...)
+ t.Name = line
i = next
line, next, err = requiredHeaderLine(body, i, "tagger")
@@ -84,7 +94,7 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Tag, error) {
i += rel + 1
if len(line) == 0 {
- t.Message = append([]byte(nil), body[i:]...)
+ t.Message = body[i:]
return t, nil
}
@@ -112,8 +122,8 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Tag, error) {
}
default:
t.ExtraHeaders = append(t.ExtraHeaders, ExtraHeader{
- Key: string(key),
- Value: append([]byte(nil), value...),
+ Key: key,
+ Value: value,
})
}
}
diff --git a/object/tag/tag.go b/object/tag/tag.go
index f4b36c30..a4572921 100644
--- a/object/tag/tag.go
+++ b/object/tag/tag.go
@@ -20,6 +20,6 @@ type Tag struct {
// ExtraHeader represents an extra header in a Git tag object.
type ExtraHeader struct {
- Key string
+ Key []byte
Value []byte
}