git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 1/3] contrib/git-jump: fix greedy regex when matching hunks
Date: Fri, 22 Jul 2016 12:28:44 -0400	[thread overview]
Message-ID: <20160722162844.GA14080@sigill.intra.peff.net> (raw)
In-Reply-To: <20160722162707.GA13905@sigill.intra.peff.net>

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 <peff@peff.net>
---
 contrib/git-jump/git-jump | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index dc90cd6..1f1b996 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*(.*)/) {
-- 
2.9.2.506.g8452fe7


  reply	other threads:[~2016-07-22 16:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-22 16:27 [PATCH 0/3] minor git-jump improvements Jeff King
2016-07-22 16:28 ` Jeff King [this message]
2016-07-22 16:29 ` [PATCH 2/3] contrib/git-jump: add whitespace-checking mode Jeff King
2016-07-22 16:35   ` [PATCH v2 " Jeff King
2016-07-22 16:30 ` [PATCH 3/3] contrib/git-jump: fix typo in README Jeff King
2016-07-23  8:52 ` [PATCH 0/3] minor git-jump improvements Johannes Schindelin
2016-07-24 15:32   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160722162844.GA14080@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).