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

Function Parse

pkg/gitdiff/parser.go:19–60  ·  view source on GitHub ↗

Parse parses a patch with changes to one or more files. Any content before the first file is returned as the second value. If an error occurs while parsing, it returns all files parsed before the error. Parse expects to receive a single patch. If the input may contain multiple patches (for example,

(r io.Reader)

Source from the content-addressed store, hash-verified

17// patches (for example, if it is an mbox file), callers should split it into
18// individual patches and call Parse on each one.
19func Parse(r io.Reader) ([]*File, string, error) {
20 p := newParser(r)
21
22 if err := p.Next(); err != nil {
23 if err == io.EOF {
24 return nil, "", nil
25 }
26 return nil, "", err
27 }
28
29 var preamble string
30 var files []*File
31 for {
32 file, pre, err := p.ParseNextFileHeader()
33 if err != nil {
34 return files, preamble, err
35 }
36 if len(files) == 0 {
37 preamble = pre
38 }
39 if file == nil {
40 break
41 }
42
43 for _, fn := range []func(*File) (int, error){
44 p.ParseTextFragments,
45 p.ParseBinaryFragments,
46 } {
47 n, err := fn(file)
48 if err != nil {
49 return files, preamble, err
50 }
51 if n > 0 {
52 break
53 }
54 }
55
56 files = append(files, file)
57 }
58
59 return files, preamble, nil
60}
61
62// TODO(bkeyes): consider exporting the parser type with configuration
63// this would enable OID validation, p-value guessing, and prefix stripping

Callers 4

generateCommitPageFunction · 0.92
runMethod · 0.85
assertParseSingleFileFunction · 0.85
TestParseFunction · 0.85

Calls 3

newParserFunction · 0.85
NextMethod · 0.80
ParseNextFileHeaderMethod · 0.80

Tested by 3

runMethod · 0.68
assertParseSingleFileFunction · 0.68
TestParseFunction · 0.68