···186186// can lead to panic.
187187func ReadCommit(oid plumbing.Hash, reader io.Reader) (*object.Commit, error) {
188188 commit := &object.Commit{
189189- Hash: oid,
189189+ Hash: oid,
190190+ ExtraHeaders: make(map[string][]byte),
190191 }
191192192193 payloadSB := new(strings.Builder)
···231232 continue
232233 }
233234234234- split := bytes.SplitN(trimmed, []byte{' '}, 2)
235235- var data []byte
236236- if len(split) > 1 {
237237- data = split[1]
238238- }
235235+ k, data, _ := bytes.Cut(line, []byte{' '})
239236240240- switch string(split[0]) {
237237+ switch string(k) {
241238 case "tree":
242239 commit.TreeHash = plumbing.NewHash(string(data))
243240 _, _ = payloadSB.Write(line)
···257254 _ = signatureSB.WriteByte('\n')
258255 pgpsig = true
259256 default:
257257+ commit.ExtraHeaders[string(k)] = bytes.TrimSpace(data)
260258 // If the first line is not any of the known headers, then it is probably the prefix added when git cat-file is called with --batch, and that is not part of the payload
261259 if !firstLine {
262260 // Every subsequent header field is added to the payload
···271269 firstLine = false
272270 }
273271 commit.Message = messageSB.String()
272272+ // TODO: pass raw payload so we can verify it without reconstructing the payload
274273 commit.PGPSignature = signatureSB.String()
275274276275 return commit, nil