git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Next: Bert Wesarg
Message 1 of 8 in “git-gui: fix hunk parsing for corner case changes”
  1. 1/1 git-gui: fix hunk parsing for corner case changesBert Wesarg, Jan 9, 2012
  2. 2/2 git-gui: fix applying line/ranges when the selection ends at the begin of a lineBert Wesarg, Jan 9, 2012
  3. 3/3 git-gui: support for reverting hunks and linesBert Wesarg, Jan 9, 2012
  4. Bert WesargJan 14, 2012
  5. Junio C HamanoJan 14, 2012
  6. Bert WesargJan 14, 2012
  7. Bert WesargJan 14, 2012
  8. Bert WesargJan 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.