From 2110ba328e474e6882a6a4c2298f731fef336e40 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 9 Jan 2012 14:22:54 +0100 Subject: [PATCH] git-gui: fix hunk parsing for corner case changes The simple hunk parsing code did not recognize hunks when where 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 --- lib/diff.tcl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/diff.tcl b/lib/diff.tcl index 3f0de6b..8226d49 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -659,9 +659,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: -- 2.11.4.GIT