MCPcopy Index your code
hub / github.com/go-git/go-git / scanTree

Function scanTree

plumbing/object/commit_scanner.go:75–98  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

73// else (or an empty buffer) is rejected with ErrMalformedCommit, matching
74// upstream's `bogus commit object` check.
75func 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

Callers

nothing calls this directly

Calls 4

isBlankLineFunction · 0.85
splitHeaderFunction · 0.85
parseObjectIDHexFunction · 0.85
readLineMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…