mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
Add basic fragment parsing function
This should work, but does no validation on the fragment after parsing.
This commit is contained in:
@@ -35,8 +35,31 @@ type Fragment struct {
|
||||
|
||||
NewPosition int64
|
||||
NewLines int64
|
||||
|
||||
LinesAdded int64
|
||||
LinesDeleted int64
|
||||
|
||||
Lines []FragmentLine
|
||||
}
|
||||
|
||||
// FragmentLine is a line in a fragment.
|
||||
type FragmentLine struct {
|
||||
Op LineOp
|
||||
Line string
|
||||
}
|
||||
|
||||
// LineOp describes the type of a fragment line: context, added, or removed.
|
||||
type LineOp int
|
||||
|
||||
const (
|
||||
// OpContext indicates a context line
|
||||
OpContext LineOp = iota
|
||||
// OpDelete indicates a deleted line
|
||||
OpDelete
|
||||
// OpAdd indicates an added line
|
||||
OpAdd
|
||||
)
|
||||
|
||||
// Header returns the cannonical header of this fragment.
|
||||
func (f *Fragment) Header() string {
|
||||
return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)
|
||||
|
||||
Reference in New Issue
Block a user