Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ChangeList []ContentChange
// Hunk is a line that starts with @@.
// Each hunk shows one area where the files differ
// Unified format hunks look like this:
// @@ from-file-line-numbers to-file-line-numbers @@
// @@ from-file-line-numbers to-file-line-numbers @@( context)?
//
// line-from-either-file
// line-from-either-file…
Expand All @@ -45,6 +45,7 @@ type Hunk struct {
CountOld int `json:"count_old"`
StartLineNumberNew int `json:"start_line_number_new"`
CountNew int `json:"count_new"`
Context string `json:"context,omitempty"`
}

func (changes *ChangeList) IsSignificant() bool {
Expand All @@ -57,7 +58,7 @@ func (changes *ChangeList) IsSignificant() bool {
}

func NewHunk(line string) (Hunk, error) {
namedHunkRegex := regexp.MustCompile(`(?m)^@@ -(?P<start_old>\d+),?(?P<count_old>\d+)? \+(?P<start_new>\d+),?(?P<count_new>\d+)? @@`)
namedHunkRegex := regexp.MustCompile(`(?m)^@@ -(?P<start_old>\d+),?(?P<count_old>\d+)? \+(?P<start_new>\d+),?(?P<count_new>\d+)? @@ ?(?P<context>.*)?`)
match := namedHunkRegex.FindStringSubmatch(line)
result := make(map[string]string)
for i, name := range namedHunkRegex.SubexpNames() {
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewHunk(line string) (Hunk, error) {
CountOld: countOld,
StartLineNumberNew: startLineNumberNew,
CountNew: countNew,
Context: result["context"],
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/significant/add.diff
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/a.txt
@@ -0,0 +1 @@
@@ -0,0 +1 @@ test context
+a
2 changes: 1 addition & 1 deletion testdata/significant/add.diff.msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
significant diff &git_diff_parser.FileDiff{FromFile:"a.txt", ToFile:"a.txt", Type:"modify", IsBinary:false, NewMode:"100644", Hunks:[]git_diff_parser.Hunk{git_diff_parser.Hunk{ChangeList:git_diff_parser.ChangeList{git_diff_parser.ContentChange{Type:"add", From:"", To:"a"}, git_diff_parser.ContentChange{Type:"", From:"", To:""}}, StartLineNumberOld:0, CountOld:0, StartLineNumberNew:1, CountNew:1}}, BinaryPatch:[]git_diff_parser.BinaryPatch(nil)}
significant diff &git_diff_parser.FileDiff{FromFile:"a.txt", ToFile:"a.txt", Type:"modify", IsBinary:false, NewMode:"100644", Hunks:[]git_diff_parser.Hunk{git_diff_parser.Hunk{ChangeList:git_diff_parser.ChangeList{git_diff_parser.ContentChange{Type:"add", From:"", To:"a"}, git_diff_parser.ContentChange{Type:"", From:"", To:""}}, StartLineNumberOld:0, CountOld:0, StartLineNumberNew:1, CountNew:1, Context:"test context"}}, BinaryPatch:[]git_diff_parser.BinaryPatch(nil)}