Ignore diff results which aren't actually hunks.

Some people have reported a failure whereby at least one `line` in the
diff results doesn't match the hunk regexp.  I believe, though cannot
say with certainty, that this is due to mismatching newline shenanigans.

However this theory doesn't explain how the failure could occur on a
file without changes, as reported by one person.  Furthermore I think
that the hunk results would have to have double \n characters to cause
this failure, which I don't think would ordinarily occur on Windows or
Unix.

Whatever the reason, this change copes with the situation.
This commit is contained in:
Andy Stewart
2013-02-27 10:34:07 +01:00
parent 0c16f257d6
commit 270613bd71

View File

@@ -89,12 +89,14 @@ function! s:parse_diff(diff)
let hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
let hunks = []
for line in split(a:diff, '\n')
let matches = matchlist(line, hunk_re)
let from_line = str2nr(matches[1])
let from_count = (matches[2] == '') ? 1 : str2nr(matches[2])
let to_line = str2nr(matches[3])
let to_count = (matches[4] == '') ? 1 : str2nr(matches[4])
call add(hunks, [from_line, from_count, to_line, to_count])
let matches = matchlist(line, hunk_re)
if len(matches) > 0
let from_line = str2nr(matches[1])
let from_count = (matches[2] == '') ? 1 : str2nr(matches[2])
let to_line = str2nr(matches[3])
let to_count = (matches[4] == '') ? 1 : str2nr(matches[4])
call add(hunks, [from_line, from_count, to_line, to_count])
end
endfor
return hunks
endfunction