scanTree expects the first non-empty header to be `tree HASH`. Anything else (or an empty buffer) is rejected with ErrMalformedCommit, matching upstream's `bogus commit object` check.
(s *commitScanner)
| 73 | // else (or an empty buffer) is rejected with ErrMalformedCommit, matching |
| 74 | // upstream's `bogus commit object` check. |
| 75 | func scanTree(s *commitScanner) (commitState, error) { |
| 76 | line, err := s.readLine() |
| 77 | if err != nil && err != io.EOF { |
| 78 | return nil, err |
| 79 | } |
| 80 | if len(line) == 0 || isBlankLine(line) { |
| 81 | return nil, fmt.Errorf("%w: missing tree header", ErrMalformedCommit) |
| 82 | } |
| 83 | |
| 84 | key, data := splitHeader(line) |
| 85 | if key != "tree" { |
| 86 | return nil, fmt.Errorf("%w: tree header must be first", ErrMalformedCommit) |
| 87 | } |
| 88 | h, herr := parseObjectIDHex(data, ErrMalformedCommit, "tree") |
| 89 | if herr != nil { |
| 90 | return nil, herr |
| 91 | } |
| 92 | s.c.TreeHash = h |
| 93 | s.sawTree = true |
| 94 | if err == io.EOF { |
| 95 | return nil, nil |
| 96 | } |
| 97 | return scanParents, nil |
| 98 | } |
| 99 | |
| 100 | // scanParents consumes contiguous `parent HASH` lines. The first non-parent |
| 101 | // line ends the parent block and is handed off to scanAuthor; any later |
nothing calls this directly
no test coverage detected
searching dependent graphs…