diff options
| author | 2026-06-13 15:57:07 +0000 | |
|---|---|---|
| committer | 2026-06-13 15:57:07 +0000 | |
| commit | a311a5607391d063923eb012a12e081a4c140407 (patch) | |
| tree | 5f66629528d7449accab4d337e87266cd6c097af /object | |
| parent | object/blob: Clone (diff) | |
object/signature: Don't clone on parse
Diffstat (limited to 'object')
| -rw-r--r-- | object/signature/parse.go | 12 |
1 files changed, 9 insertions, 3 deletions
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] != ' ' { |
