From 74a7fa44d36c3e93febccdea5f44ff78555463d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 22 Jul 2016 12:28:44 -0400 Subject: [PATCH 1/3] 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(-) 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*(.*)/) { From 1af9c6096a7ec6cba3a5f7d359cb1caf2152496a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 22 Jul 2016 12:35:19 -0400 Subject: [PATCH 2/3] contrib/git-jump: add whitespace-checking mode If you have whitespace errors in lines you've introduced, it can be convenient to be able to jump directly to them for fixing. You can't quite use "git jump diff" for this, because though it passes arbitrary options to "git diff", it expects to see an actual unified diff in the output. Whereas "git diff --check" actually produces lines that look like compiler quickfix lines already, meaning we just need to run it and feed the output directly to the editor. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/git-jump/README | 4 +++- contrib/git-jump/git-jump | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contrib/git-jump/README b/contrib/git-jump/README index 1cebc328cb..3e0b65b9b3 100644 --- a/contrib/git-jump/README +++ b/contrib/git-jump/README @@ -29,7 +29,7 @@ Obviously this trivial case isn't that interesting; you could just open `foo.c` yourself. But when you have many changes scattered across a project, you can use the editor's support to "jump" from point to point. -Git-jump can generate three types of interesting lists: +Git-jump can generate four types of interesting lists: 1. The beginning of any diff hunks. @@ -37,6 +37,8 @@ Git-jump can generate three types of interesting lists: 3. Any grep matches. + 4. Any whitespace errors detected by `git diff --check`. + Using git-jump -------------- diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index 1f1b996be1..427f206a45 100755 --- a/contrib/git-jump/git-jump +++ b/contrib/git-jump/git-jump @@ -12,6 +12,8 @@ diff: elements are diff hunks. Arguments are given to diff. merge: elements are merge conflicts. Arguments are ignored. grep: elements are grep hits. Arguments are given to grep. + +ws: elements are whitespace errors. Arguments are given to diff --check. EOF } @@ -55,6 +57,10 @@ mode_grep() { ' } +mode_ws() { + git diff --check "$@" +} + if test $# -lt 1; then usage >&2 exit 1 From a91e6925f66f6c08bc6e27aa1278c1df0dfffac8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 22 Jul 2016 12:30:58 -0400 Subject: [PATCH 3/3] contrib/git-jump: fix typo in README Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/git-jump/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/git-jump/README b/contrib/git-jump/README index 3e0b65b9b3..225e3f0954 100644 --- a/contrib/git-jump/README +++ b/contrib/git-jump/README @@ -85,7 +85,7 @@ complete list of files and line numbers for each match. Limitations ----------- -This scripts was written and tested with vim. Given that the quickfix +This script was written and tested with vim. Given that the quickfix format is the same as what gcc produces, I expect emacs users have a similar feature for iterating through the list, but I know nothing about how to activate it.