@matheusbsbs / matheus-bagliano / commits / c976bbff3c
Fork 0

git-gui: rework handling of diff header

The fix in ca53c3f (Fix diff parsing for lines starting with "--" or "++", 2008-09-05) got a bug report from Johannes Sixt, that new files in the index now looks like: new file mode 100644 --- /dev/null +++ b/foo @@ -0,0 +1 @@ +foo The introduced problem was that the 'in-diff-header'-flag was unconditially disabled. Now it is only disabled when a hunk line is detected. And also re-enabled when we encounter a new diff header. The second part solves also the issue reported by me for diffs with file type changes (i.e. the ''error: Unhandled 2 way diff marker: {d}"', which comes from the second 'diff --git' line). Reported-by: Johannes Sixt <j.sixt@viscovery.net> Reported-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Bert Wesarg committed Dec 9, 2010 at 21:47 UTC c976bbff3c3e46e700adbdc14def8c9432fc925c
1 file changed +15 -3
lib/diff.tcl
+15 -3
@@ -382,23 +382,35 @@ proc read_diff {fd conflict_size cont_info} {
382 foreach {line markup} [parse_color_line $line] break
383 set line [string map {\033 ^} $line]
384
385 - # -- Cleanup uninteresting diff header lines.
385 + # -- Check for start of diff header.
386 + if { [string match {diff --git *} $line]
387 + || [string match {diff --cc *} $line]
388 + || [string match {diff --combined *} $line]} {
389 + set ::current_diff_inheader 1
390 + }
391 +
392 + # -- Check for end of diff header (any hunk line will do this).
393 #
394 + if {[regexp {^@@+ } $line]} {set ::current_diff_inheader 0}
395 +
396 if {$::current_diff_inheader} {
397 + append current_diff_header $line "\n"
398 +
399 + # -- Cleanup uninteresting diff header lines.
400 + #
401 if { [string match {diff --git *} $line]
402 || [string match {diff --cc *} $line]
403 || [string match {diff --combined *} $line]
404 || [string match {--- *} $line]
405 || [string match {+++ *} $line]} {
393 - append current_diff_header $line "\n"
406 continue
407 }
408 }
409 +
410 if {[string match {index *} $line]} continue
411 if {$line eq {deleted file mode 120000}} {
412 set line "deleted symlink"
413 }
401 - set ::current_diff_inheader 0
414
415 # -- Automatically detect if this is a 3 way diff.
416 #