git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] contrib/git-jump: extract function diff_to_quickfix
@ 2019-12-21 11:38 Beat Bolli
  2019-12-21 11:38 ` [PATCH 2/2] contrib/git-jump: add mode commit Beat Bolli
  0 siblings, 1 reply; 5+ messages in thread
From: Beat Bolli @ 2019-12-21 11:38 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Beat Bolli

In preparation for a new mode that will also jump to diff hunks, extract
the function that generates the quickfix list from a diff.

Signed-off-by: Beat Bolli <dev+git@drbeat.li>
---
 contrib/git-jump/git-jump | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
 mode change 100755 => 100644 contrib/git-jump/git-jump

diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
old mode 100755
new mode 100644
index 931b0fe3a9..776fa90f7f
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -24,7 +24,10 @@ open_editor() {
 }
 
 mode_diff() {
-	git diff --no-prefix --relative "$@" |
+	git diff --no-prefix --relative "$@" | diff_to_quickfix
+}
+
+diff_to_quickfix() {
 	perl -ne '
 	if (m{^\+\+\+ (.*)}) { $file = $1; next }
 	defined($file) or next;
-- 
2.21.0.1020.gf2820cf01a


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] contrib/git-jump: add mode commit
  2019-12-21 11:38 [PATCH 1/2] contrib/git-jump: extract function diff_to_quickfix Beat Bolli
@ 2019-12-21 11:38 ` Beat Bolli
  2019-12-21 19:23   ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Beat Bolli @ 2019-12-21 11:38 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Beat Bolli

After committing, I often want to return to the place of the latest
change to continue my work. Add the new mode "commit" which does exactly
this.

Optional arguments are given to the "git show" call. So it's possible to
jump to changes of other commits than HEAD.

Signed-off-by: Beat Bolli <dev+git@drbeat.li>
---
 contrib/git-jump/git-jump | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 776fa90f7f..e7192073c6 100644
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -9,6 +9,9 @@ The <mode> parameter is one of:
 
 diff: elements are diff hunks. Arguments are given to diff.
 
+commit: element are the hunks of a commit (default HEAD). Arguments are
+        given to git show.
+
 merge: elements are merge conflicts. Arguments are ignored.
 
 grep: elements are grep hits. Arguments are given to git grep or, if
@@ -27,6 +30,10 @@ mode_diff() {
 	git diff --no-prefix --relative "$@" | diff_to_quickfix
 }
 
+mode_commit() {
+	git show --no-prefix --relative "$@" | diff_to_quickfix
+}
+
 diff_to_quickfix() {
 	perl -ne '
 	if (m{^\+\+\+ (.*)}) { $file = $1; next }
-- 
2.21.0.1020.gf2820cf01a


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] contrib/git-jump: add mode commit
  2019-12-21 11:38 ` [PATCH 2/2] contrib/git-jump: add mode commit Beat Bolli
@ 2019-12-21 19:23   ` Jeff King
  2019-12-22 12:47     ` Beat Bolli
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2019-12-21 19:23 UTC (permalink / raw)
  To: Beat Bolli; +Cc: git

On Sat, Dec 21, 2019 at 12:38:46PM +0100, Beat Bolli wrote:

> After committing, I often want to return to the place of the latest
> change to continue my work. Add the new mode "commit" which does exactly
> this.

That's one of my primary uses for git-jump, too. But you can already do
that by jumping to the diff of HEAD^. Which has the additional advantage
that it's a diff against the working tree. So if you did a partial
commit, the diff will include any leftover changes.

So I'm not opposed to this patch per se, given that it's not very many
lines. But I'm not sure I see much advantage over "git jump diff HEAD^".
It's slightly less typing, but I already alias "git jump diff" since
it's so long.

> Optional arguments are given to the "git show" call. So it's possible to
> jump to changes of other commits than HEAD.

This can also be done with "git jump diff $commit^ $commit". However,
I've found that jumping based on older diffs is mostly useless, because
the line numbers at $commit and those in the working tree don't always
match up (and inherently you're always jumping in the working tree
copy).

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] contrib/git-jump: add mode commit
  2019-12-21 19:23   ` Jeff King
@ 2019-12-22 12:47     ` Beat Bolli
  2019-12-22 12:47       ` Beat Bolli
  0 siblings, 1 reply; 5+ messages in thread
From: Beat Bolli @ 2019-12-22 12:47 UTC (permalink / raw)
  To: Jeff King; +Cc: git

On 21.12.19 20:23, Jeff King wrote:
> On Sat, Dec 21, 2019 at 12:38:46PM +0100, Beat Bolli wrote:
> 
>> After committing, I often want to return to the place of the latest
>> change to continue my work. Add the new mode "commit" which does exactly
>> this.
> 
> That's one of my primary uses for git-jump, too. But you can already do
> that by jumping to the diff of HEAD^. Which has the additional advantage
> that it's a diff against the working tree. So if you did a partial
> commit, the diff will include any leftover changes.
> 
> So I'm not opposed to this patch per se, given that it's not very many
> lines. But I'm not sure I see much advantage over "git jump diff HEAD^".
> It's slightly less typing, but I already alias "git jump diff" since
> it's so long.
> 
>> Optional arguments are given to the "git show" call. So it's possible to
>> jump to changes of other commits than HEAD.
> 
> This can also be done with "git jump diff $commit^ $commit". However,
> I've found that jumping based on older diffs is mostly useless, because
> the line numbers at $commit and those in the working tree don't always
> match up (and inherently you're always jumping in the working tree
> copy).

Thanks, I didn't realize that git diff could just as well be used to
generate the diff of an arbitrary commit. I have added this new shortcut
to my bash aliases:

    gjc() { git jump diff ${1:-HEAD}^ ${1:-HEAD}; }


Cheers, Beat

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] contrib/git-jump: add mode commit
  2019-12-22 12:47     ` Beat Bolli
@ 2019-12-22 12:47       ` Beat Bolli
  0 siblings, 0 replies; 5+ messages in thread
From: Beat Bolli @ 2019-12-22 12:47 UTC (permalink / raw)
  To: git; +Cc: git

On 21.12.19 20:23, Jeff King wrote:
> On Sat, Dec 21, 2019 at 12:38:46PM +0100, Beat Bolli wrote:
> 
>> After committing, I often want to return to the place of the latest
>> change to continue my work. Add the new mode "commit" which does exactly
>> this.
> 
> That's one of my primary uses for git-jump, too. But you can already do
> that by jumping to the diff of HEAD^. Which has the additional advantage
> that it's a diff against the working tree. So if you did a partial
> commit, the diff will include any leftover changes.
> 
> So I'm not opposed to this patch per se, given that it's not very many
> lines. But I'm not sure I see much advantage over "git jump diff HEAD^".
> It's slightly less typing, but I already alias "git jump diff" since
> it's so long.
> 
>> Optional arguments are given to the "git show" call. So it's possible to
>> jump to changes of other commits than HEAD.
> 
> This can also be done with "git jump diff $commit^ $commit". However,
> I've found that jumping based on older diffs is mostly useless, because
> the line numbers at $commit and those in the working tree don't always
> match up (and inherently you're always jumping in the working tree
> copy).

Thanks, I didn't realize that git diff could just as well be used to
generate the diff of an arbitrary commit. I have added this new shortcut
to my bash aliases:

    gjc() { git jump diff ${1:-HEAD}^ ${1:-HEAD}; }


Cheers, Beat


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-22 12:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-21 11:38 [PATCH 1/2] contrib/git-jump: extract function diff_to_quickfix Beat Bolli
2019-12-21 11:38 ` [PATCH 2/2] contrib/git-jump: add mode commit Beat Bolli
2019-12-21 19:23   ` Jeff King
2019-12-22 12:47     ` Beat Bolli
2019-12-22 12:47       ` Beat Bolli

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).