[PATCH 1/1] git-gui: fix hunk parsing for corner case changes
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- Jan 9, 2012, 13:43 UTC
- Message-ID
- <cccd6193cf3bfe170e14270204d735a842bb8563.1326116492.git.bert.wesarg@googlemail.com>
The simple hunk parsing code did not recognize hunks when there is no second number after the comma. Like in these cases:
@@ -1 +0,0 @@ -1
Which resulted in this hunk header:
@@ -1 +0,1 +1 +0,0 @@
Or:
@@ -1 +1 @@ -1 +2
Resulted in:
@@ -1 +1 @@ ,1 +1 +1 @@ ,0 @@
While trying to stage only the '-1' line.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> --- lib/diff.tcl | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/diff.tcl b/lib/diff.tcl index ec44055..63f8742 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -672,9 +672,11 @@ proc apply_range_or_line {x y} { # $i_l is now at the beginning of a line # pick start line number from hunk header - set hh [$ui_diff get $i_l "$i_l + 1 lines"] - set hh [lindex [split $hh ,] 0] - set hln [lindex [split $hh -] 1] + if {![regexp {^@@ -(\d+)(?:,\d+)? \+(?:\d+)(?:,\d+)? @@(?:\s|$)} \ + [$ui_diff get $i_l "$i_l + 1 lines"] hh hln]} { + unlock_index + return + } # There is a special situation to take care of. Consider this # hunk:
-- 1.7.8.1.873.gfea665