MCPcopy Index your code
hub / github.com/antonmedv/gitmal / parseHeaderPretty

Function parseHeaderPretty

pkg/gitdiff/patch_header.go:213–297  ·  view source on GitHub ↗
(prettyLine string, r io.Reader)

Source from the content-addressed store, hash-verified

211}
212
213func parseHeaderPretty(prettyLine string, r io.Reader) (*PatchHeader, error) {
214 const (
215 authorPrefix = "Author:"
216 commitPrefix = "Commit:"
217 datePrefix = "Date:"
218 authorDatePrefix = "AuthorDate:"
219 commitDatePrefix = "CommitDate:"
220 )
221
222 h := &PatchHeader{}
223
224 prettyLine = strings.TrimPrefix(prettyLine, prettyHeaderPrefix)
225 if i := strings.IndexByte(prettyLine, ' '); i > 0 {
226 h.SHA = prettyLine[:i]
227 } else {
228 h.SHA = prettyLine
229 }
230
231 s := bufio.NewScanner(r)
232 for s.Scan() {
233 line := s.Text()
234
235 // empty line marks end of fields, remaining lines are title/message
236 if strings.TrimSpace(line) == "" {
237 break
238 }
239
240 switch {
241 case strings.HasPrefix(line, authorPrefix):
242 u, err := ParsePatchIdentity(line[len(authorPrefix):])
243 if err != nil {
244 return nil, err
245 }
246 h.Author = &u
247
248 case strings.HasPrefix(line, commitPrefix):
249 u, err := ParsePatchIdentity(line[len(commitPrefix):])
250 if err != nil {
251 return nil, err
252 }
253 h.Committer = &u
254
255 case strings.HasPrefix(line, datePrefix):
256 d, err := ParsePatchDate(strings.TrimSpace(line[len(datePrefix):]))
257 if err != nil {
258 return nil, err
259 }
260 h.AuthorDate = d
261
262 case strings.HasPrefix(line, authorDatePrefix):
263 d, err := ParsePatchDate(strings.TrimSpace(line[len(authorDatePrefix):]))
264 if err != nil {
265 return nil, err
266 }
267 h.AuthorDate = d
268
269 case strings.HasPrefix(line, commitDatePrefix):
270 d, err := ParsePatchDate(strings.TrimSpace(line[len(commitDatePrefix):]))

Callers 1

ParsePatchHeaderFunction · 0.85

Calls 4

ParsePatchIdentityFunction · 0.85
ParsePatchDateFunction · 0.85
scanMessageTitleFunction · 0.85
scanMessageBodyFunction · 0.85

Tested by

no test coverage detected