git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: RFC: Adding an option to log-like commands to call an external command for each revision
Date: Sun, 29 Aug 2010 23:08:19 -0400	[thread overview]
Message-ID: <20100830030819.GA25415@sigill.intra.peff.net> (raw)
In-Reply-To: <AANLkTikh-KoWuPYE12pVszwduGTBOssKDxqk=4iF6QZT@mail.gmail.com>

On Sun, Aug 29, 2010 at 08:30:15PM +0000, Ævar Arnfjörð Bjarmason wrote:

> I have this alias in my .gitconfig:
> 
>     review = "!f() { for rev in $(git rev-list --reverse \"$@\"); do
> git show $rev; done; }; f"
> 
> I use it after I "git pull" to see what changed, e.g.:
> 
>     git review 49ea7b8..e1ef3c1

It took me a minute of reading this to see why you would want to call
"git show" in a loop when you could have the same data from "git log"
all at once (and much faster, too). But I guess you like having an
individual less invocation for each commit. Have you tried "tig", which
might suit your purpose even better?

> But sometimes I find that I want to do that for other things too, so I
> have these hacks:
> 
>     review-grep = "!f() { for rev in $(git log --reverse
> --pretty=format:%H --grep=\"$@\"); do git show $rev; done; }; f"
>     review-file = "!f() { for rev in $(git log --reverse
> --pretty=format:%H \"$@\"); do git show $rev; done; }; f"
> 
> But just now I wanted to use -S instead of grep, but adding aliases
> like this is a bit silly.

I don't understand why you have these at all. Just use "git log
--format=%H" in your git review above (instead of rev-list), and then
you can just do:

  git review --grep=whatever
  git review -Sfoo
  git review file

Or am I missing something subtle?

You wouldn't even need to switch to log over rev-list, except that
rev-list misses log's useful "default to HEAD if no revisions given"
behavior.

> Maybe we should have something like:
> 
>     git log --for-each=less a..b
> 
> To call "less" for each commit, what do you think?

I think it is not very Unix-y. We already have many ways to to call a
command once per commit, including:

  - for i in `git rev-list "$@"`; do git show $i; done

  - git rev-list "$@" | xargs -n 1 git show

  - git log -z "$@" | perl -0ne 'open(LESS, "|less"); print LESS'

What does your solution offer that the other do not? Because you are
actually reinvoking git for each commit, it is more efficient than the
first two (as you seem to assume that the --for-each command will
receive the entire log output). But the third one should be more or less
equivalent to what you want (though note: if you want tty-ish things
like color on, you should set GIT_PAGER_IN_USE=1 so git knows output is
eventually going to a pager). Sure, yours is slightly less typing, but
it's _way_ less flexible, and that typing should probably be hidden
behind an alias anyway.

-Peff

  parent reply	other threads:[~2010-08-30  3:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-29 20:30 RFC: Adding an option to log-like commands to call an external command for each revision Ævar Arnfjörð Bjarmason
2010-08-29 20:39 ` Jonathan Nieder
2010-08-30  3:08 ` Jeff King [this message]
2010-09-11 15:56   ` Ævar Arnfjörð Bjarmason
2010-09-11 17:09     ` Mark Lodato
2010-09-11 19:07     ` Ævar Arnfjörð Bjarmason
2010-09-11 22:17     ` Artur Skawina
2010-09-12 21:25     ` Junio C Hamano
2010-09-12 22:44       ` Ævar Arnfjörð Bjarmason

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=20100830030819.GA25415@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --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).