mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
9b0fc30459
After considering fragment parsing, it made sense to change the invariant estabilished in the previous commit. Specifically, parser functions now assume they are call on the first line of their object and return with the parser on the first line after their object. This means code can call parse function immediately after each other without advancing the parser in between. It's possible this will change back later on... there seem to be annoying edge cases with either choice, but I think making the functions consistent is important.
44 lines
787 B
Go
44 lines
787 B
Go
package gitdiff
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// File describes changes to a single file. It can be either a text file or a
|
|
// binary file.
|
|
type File struct {
|
|
OldName string
|
|
NewName string
|
|
|
|
IsNew bool
|
|
IsDelete bool
|
|
IsCopy bool
|
|
IsRename bool
|
|
|
|
OldMode os.FileMode
|
|
NewMode os.FileMode
|
|
|
|
OldOIDPrefix string
|
|
NewOIDPrefix string
|
|
Score int
|
|
|
|
Fragments []*Fragment
|
|
}
|
|
|
|
// Fragment describes changed lines starting at a specific line in a text file.
|
|
type Fragment struct {
|
|
Comment string
|
|
|
|
OldPosition int64
|
|
OldLines int64
|
|
|
|
NewPosition int64
|
|
NewLines int64
|
|
}
|
|
|
|
// 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)
|
|
}
|