[PATCH 1/1] git-gui: fix hunk parsing for corner case changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]