mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
Document and enforce parser invariants
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.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gitdiff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -35,3 +36,8 @@ type Fragment struct {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user