Select the types of activity you want to include in your feed.
Rename types in preparation for binary parsing
Fragment is now TextFragment to distinguish from a future BinaryFragment. Also rename FragmentLine to Line, since the text-orientation is implied by the name.
···2323 NewOIDPrefix string
2424 Score int
25252626- Fragments []*Fragment
2626+ // TextFragments contains the fragments describing changes to a text file. It
2727+ // may be empty if the file is empty or if only the mode changes.
2828+ TextFragments []*TextFragment
2729}
28302929-// Fragment describes changed lines starting at a specific line in a text file.
3030-type Fragment struct {
3131+// TextFragment describes changed lines starting at a specific line in a text file.
3232+type TextFragment struct {
3133 Comment string
32343335 OldPosition int64
···4244 LeadingContext int64
4345 TrailingContext int64
44464545- Lines []FragmentLine
4747+ Lines []Line
4848+}
4949+5050+// Header returns the cannonical header of this fragment.
5151+func (f *TextFragment) Header() string {
5252+ return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)
4653}
47544848-// FragmentLine is a line in a fragment.
4949-type FragmentLine struct {
5555+// Line is a line in a text fragment.
5656+type Line struct {
5057 Op LineOp
5158 Line string
5259}
53605454-func (fl FragmentLine) String() string {
6161+func (fl Line) String() string {
5562 return fl.Op.String() + fl.Line
5663}
57645858-// LineOp describes the type of a fragment line: context, added, or removed.
6565+// LineOp describes the type of a text fragment line: context, added, or removed.
5966type LineOp int
60676168const (
···7986 return "?"
8087}
81888282-// Header returns the cannonical header of this fragment.
8383-func (f *Fragment) Header() string {
8484- return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)
8585-}
+7-7
gitdiff/parser.go
···144144 return n, err
145145 }
146146147147- f.Fragments = append(f.Fragments, frag)
147147+ f.TextFragments = append(f.TextFragments, frag)
148148 n++
149149 }
150150}
···200200 return fmt.Errorf("gitdiff: line %d: %s", p.lineno+delta, fmt.Sprintf(msg, args...))
201201}
202202203203-func (p *parser) ParseTextFragmentHeader() (*Fragment, error) {
203203+func (p *parser) ParseTextFragmentHeader() (*TextFragment, error) {
204204 const (
205205 startMark = "@@ -"
206206 endMark = " @@"
···215215 return nil, p.Errorf(0, "invalid fragment header")
216216 }
217217218218- f := &Fragment{}
218218+ f := &TextFragment{}
219219 f.Comment = strings.TrimSpace(parts[1])
220220221221 header := parts[0][len(startMark) : len(parts[0])-len(endMark)]
···238238 return f, nil
239239}
240240241241-func (p *parser) ParseTextChunk(frag *Fragment) error {
241241+func (p *parser) ParseTextChunk(frag *TextFragment) error {
242242 if p.Line(0) == "" {
243243 return p.Errorf(0, "no content following fragment header")
244244 }
···266266 } else {
267267 frag.TrailingContext++
268268 }
269269- frag.Lines = append(frag.Lines, FragmentLine{OpContext, data})
269269+ frag.Lines = append(frag.Lines, Line{OpContext, data})
270270 case '-':
271271 oldLines--
272272 frag.LinesDeleted++
273273 frag.TrailingContext = 0
274274- frag.Lines = append(frag.Lines, FragmentLine{OpDelete, data})
274274+ frag.Lines = append(frag.Lines, Line{OpDelete, data})
275275 case '+':
276276 newLines--
277277 frag.LinesAdded++
278278 frag.TrailingContext = 0
279279- frag.Lines = append(frag.Lines, FragmentLine{OpAdd, data})
279279+ frag.Lines = append(frag.Lines, Line{OpAdd, data})
280280 default:
281281 // this may appear in middle of fragment if it's for a deleted line
282282 if isNoNewlineLine(line) {