MCPcopy Create free account
hub / github.com/antonmedv/gitmal / ParseTextFragments

Method ParseTextFragments

pkg/gitdiff/text.go:13–37  ·  view source on GitHub ↗

ParseTextFragments parses text fragments until the next file header or the end of the stream and attaches them to the given file. It returns the number of fragments that were added.

(f *File)

Source from the content-addressed store, hash-verified

11// end of the stream and attaches them to the given file. It returns the number
12// of fragments that were added.
13func (p *parser) ParseTextFragments(f *File) (n int, err error) {
14 for {
15 frag, err := p.ParseTextFragmentHeader()
16 if err != nil {
17 return n, err
18 }
19 if frag == nil {
20 return n, nil
21 }
22
23 if f.IsNew && frag.OldLines > 0 {
24 return n, p.Errorf(-1, "new file depends on old contents")
25 }
26 if f.IsDelete && frag.NewLines > 0 {
27 return n, p.Errorf(-1, "deleted file still has contents")
28 }
29
30 if err := p.ParseTextChunk(frag); err != nil {
31 return n, err
32 }
33
34 f.TextFragments = append(f.TextFragments, frag)
35 n++
36 }
37}
38
39func (p *parser) ParseTextFragmentHeader() (*TextFragment, error) {
40 const (

Callers 2

TestParseTextFragmentsFunction · 0.80

Calls 3

ErrorfMethod · 0.95
ParseTextChunkMethod · 0.95

Tested by 2

TestParseTextFragmentsFunction · 0.64