From 74a7fa44d36c3e93febccdea5f44ff78555463d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 22 Jul 2016 12:28:44 -0400 Subject: contrib/git-jump: fix greedy regex when matching hunks The hunk-header regex looks for "\+\d+" to find the post-image line numbers, but it skips the pre-image line numbers with a simple ".*". That means we may greedily eat the post-image numbers and match a "\+\d" further on, in the funcname text. For example, commit 6b9c38e has this hunk header: diff --git a/t/t0006-date.sh b/t/t0006-date.sh [...] @@ -50,8 +50,8 @@ check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000' If you run: git checkout 6b9c38e git jump diff HEAD^ t/ it will erroneously match "+0000" as the starting line number and jump there, rather than line 50. We can fix it by just making the "skip" regex non-greedy, taking the first "+" we see, which should be the post-image line information. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/git-jump/git-jump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index dc90cd6379..1f1b996be1 100755 --- a/contrib/git-jump/git-jump +++ b/contrib/git-jump/git-jump @@ -25,7 +25,7 @@ mode_diff() { perl -ne ' if (m{^\+\+\+ (.*)}) { $file = $1; next } defined($file) or next; - if (m/^@@ .*\+(\d+)/) { $line = $1; next } + if (m/^@@ .*?\+(\d+)/) { $line = $1; next } defined($line) or next; if (/^ /) { $line++; next } if (/^[-+]\s*(.*)/) { -- cgit v1.2.3