From a311a5607391d063923eb012a12e081a4c140407 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 13 Jun 2026 15:57:07 +0000 Subject: object/signature: Don't clone on parse --- object/signature/parse.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'object') diff --git a/object/signature/parse.go b/object/signature/parse.go index b39100cd..20b8fe9e 100644 --- a/object/signature/parse.go +++ b/object/signature/parse.go @@ -10,7 +10,13 @@ import ( // Parse parses a canonical Git signature line. // -// Labels: Life-Independent. +// The returned signature aliases line: +// its Name and Email share line's backing array, +// so the signature inherits line's lifetime +// and must not be mutated unless line may be. +// Use [Signature.Clone] for an independent copy. +// +// Labels: Life-Parent, Mut-No. func Parse(line []byte) (*Signature, error) { lt := bytes.IndexByte(line, '<') if lt < 0 { @@ -24,8 +30,8 @@ func Parse(line []byte) (*Signature, error) { gt := lt + 1 + gtRel - nameBytes := append([]byte(nil), bytes.TrimRight(line[:lt], " ")...) - emailBytes := append([]byte(nil), line[lt+1:gt]...) + nameBytes := bytes.TrimRight(line[:lt], " ") + emailBytes := line[lt+1:gt] rest := line[gt+1:] if len(rest) == 0 || rest[0] != ' ' { -- cgit v1.3.1-10-gc9f91