MCPcopy Index your code
hub / github.com/ChimeraCoder/gitgo / parseObj

Function parseObj

object.go:96–216  ·  view source on GitHub ↗
(obj string)

Source from the content-addressed store, hash-verified

94}
95
96func parseObj(obj string) (result GitObject, err error) {
97
98 parts := strings.Split(obj, "\x00")
99 parts = strings.Fields(parts[0])
100 resultType := parts[0]
101 resultSize := parts[1]
102 nullIndex := strings.Index(obj, "\x00")
103
104 lines := strings.Split(obj[nullIndex+1:], "\n")
105
106 switch resultType {
107 case "commit":
108 var commit = Commit{_type: resultType, size: resultSize}
109 for i, line := range lines {
110 // The next line is the commit message
111 if len(strings.Fields(line)) == 0 {
112 commit.Message = strings.Join(lines[i+1:], "\n")
113 break
114 }
115 parts := strings.Fields(line)
116 key := parts[0]
117 switch KeyType(key) {
118 case TreeKey:
119 commit.Tree = parts[1]
120 case ParentKey:
121 commit.Parents = append(commit.Parents, parts[1])
122 case AuthorKey:
123 commit.Author = strings.Join(parts[1:], " ")
124 case CommitterKey:
125 commit.Committer = strings.Join(parts[1:], " ")
126 default:
127 err = fmt.Errorf("Encountered unknown field in commit: %s", key)
128 return
129 }
130 }
131 result = commit
132 case "tree":
133 var tree = Tree{_type: resultType, size: resultSize}
134
135 scanner := bufio.NewScanner(bytes.NewBuffer([]byte(obj)))
136 scanner.Split(ScanNullLines)
137
138 var tmp objectMeta
139
140 var resultObjs []objectMeta
141
142 for count := 0; ; count++ {
143 done := !scanner.Scan()
144 if done {
145 break
146 }
147
148 txt := scanner.Text()
149
150 if count == 0 {
151 // the first time through, scanner.Text() will be
152 // "tree <size>"
153 continue

Callers 3

Test_parseObjFunction · 0.85
NewObjectFunction · 0.85

Calls 5

KeyTypeTypeAlias · 0.85
normalizePermsFunction · 0.85
SHATypeAlias · 0.85
NewObjectFunction · 0.85
TypeMethod · 0.65

Tested by 2

Test_parseObjFunction · 0.68