MCPcopy Index your code
hub / github.com/github/git-sizer / ParseCommit

Function ParseCommit

git/commit.go:18–57  ·  view source on GitHub ↗

ParseCommit parses the commit object whose contents are in `data`. `oid` is used only in error messages.

(oid OID, data []byte)

Source from the content-addressed store, hash-verified

16// ParseCommit parses the commit object whose contents are in `data`.
17// `oid` is used only in error messages.
18func ParseCommit(oid OID, data []byte) (*Commit, error) {
19 var parents []OID
20 var tree OID
21 var treeFound bool
22 iter, err := NewObjectHeaderIter(oid.String(), data)
23 if err != nil {
24 return nil, err
25 }
26 for iter.HasNext() {
27 key, value, err := iter.Next()
28 if err != nil {
29 return nil, err
30 }
31 switch key {
32 case "parent":
33 parent, err := NewOID(value)
34 if err != nil {
35 return nil, fmt.Errorf("malformed parent header in commit %s", oid)
36 }
37 parents = append(parents, parent)
38 case "tree":
39 if treeFound {
40 return nil, fmt.Errorf("multiple trees found in commit %s", oid)
41 }
42 tree, err = NewOID(value)
43 if err != nil {
44 return nil, fmt.Errorf("malformed tree header in commit %s", oid)
45 }
46 treeFound = true
47 }
48 }
49 if !treeFound {
50 return nil, fmt.Errorf("no tree found in commit %s", oid)
51 }
52 return &Commit{
53 Size: counts.NewCount32(uint64(len(data))),
54 Parents: parents,
55 Tree: tree,
56 }, nil
57}

Callers 1

ScanRepositoryUsingGraphFunction · 0.92

Calls 6

HasNextMethod · 0.95
NextMethod · 0.95
NewCount32Function · 0.92
NewObjectHeaderIterFunction · 0.85
NewOIDFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected