diff options
| author | 2026-03-04 08:26:56 +0800 | |
|---|---|---|
| committer | 2026-03-04 08:59:53 +0800 | |
| commit | ab7501be34032fb9e5c48726a68ae90a917af9eb (patch) | |
| tree | 20d005647569befea8133e953c3270e8fd2a2a5b /object/commit_parse.go | |
| parent | *: gofumpt (diff) | |
| signature | No signature | |
*: Lint
Diffstat (limited to 'object/commit_parse.go')
| -rw-r--r-- | object/commit_parse.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/object/commit_parse.go b/object/commit_parse.go index ae1b2559..31e215de 100644 --- a/object/commit_parse.go +++ b/object/commit_parse.go @@ -11,14 +11,17 @@ import ( // ParseCommit decodes a commit object body. func ParseCommit(body []byte, algo objectid.Algorithm) (*Commit, error) { c := new(Commit) + i := 0 for i < len(body) { rel := bytes.IndexByte(body[i:], '\n') if rel < 0 { return nil, errors.New("object: commit: missing newline") } + line := body[i : i+rel] i += rel + 1 + if len(line) == 0 { break } @@ -34,24 +37,28 @@ func ParseCommit(body []byte, algo objectid.Algorithm) (*Commit, error) { if err != nil { return nil, fmt.Errorf("object: commit: tree: %w", err) } + c.Tree = id case "parent": id, err := objectid.ParseHex(algo, string(value)) if err != nil { return nil, fmt.Errorf("object: commit: parent: %w", err) } + c.Parents = append(c.Parents, id) case "author": idt, err := ParseSignature(value) if err != nil { return nil, fmt.Errorf("object: commit: author: %w", err) } + c.Author = *idt case "committer": idt, err := ParseSignature(value) if err != nil { return nil, fmt.Errorf("object: commit: committer: %w", err) } + c.Committer = *idt case "change-id": c.ChangeID = string(value) @@ -61,9 +68,11 @@ func ParseCommit(body []byte, algo objectid.Algorithm) (*Commit, error) { if nextRel < 0 { return nil, errors.New("object: commit: unterminated gpgsig") } + if body[i] != ' ' { break } + i += nextRel + 1 } default: @@ -77,6 +86,8 @@ func ParseCommit(body []byte, algo objectid.Algorithm) (*Commit, error) { if i > len(body) { return nil, errors.New("object: commit: parser position out of bounds") } + c.Message = append([]byte(nil), body[i:]...) + return c, nil } |
