git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC: Adding an option to log-like commands to call an external command for each revision

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 11, 2010, 15:56 UTC
Message-ID
<AANLkTi=WokEQMDc92SoWXPJW67dy0q79WW9RajrBHRx3@mail.gmail.com>
In-Reply-To
<20100830030819.GA25415@sigill.intra.peff.net>
`On Mon, Aug 30, 2010 at 03:08, Jeff King <peff@peff.net> wrote:
Sorry for not replying to this earlier.
Show 14 quoted lines
> 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).

I just like the UI of having each commit "pop up" where I can either page up/down within the commit, or dismiss it with "q" and go to the next one.

You can't do both of those in a pager, up/down goes across commits, and "q" quits the whole pager.

> But I guess you like having an individual less invocation for each
> commit. Have you tried "tig", which might suit your purpose even
> better?

I haven't tried tig, but "git review" as I implement it (below) is sufficient for my needs.

Show 20 quoted lines
>> 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're not missing something, my alias was silly because I brainfarted and didn't realize I could do $@, not "$@", so now it's:

    review = "!f() { for rev in $(git log --reverse --format=%H $@);
do git show $rev; done; }; f"
Which means I can do all of the commands you suggested above, thanks!
Show 28 quoted lines
> 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.

Yeah, it's not very Unixy, I just find it so useful that I thought there might be interest in adding it to Git. It's easily in the list of top 5 git commands that I use.

But just using the pipe is more flexible I guess.
Previous: Jeff KingNext: Mark Lodato
Message 4 of 9 in “RFC: Adding an option to log-like commands to call an external command for each revision”
  1. Ævar Arnfjörð BjarmasonAug 29, 2010
  2. Jonathan NiederAug 29, 2010
  3. Jeff KingAug 30, 2010
  4. Ævar Arnfjörð BjarmasonSep 11, 2010
  5. Mark LodatoSep 11, 2010
  6. Ævar Arnfjörð BjarmasonSep 11, 2010
  7. Artur SkawinaSep 11, 2010
  8. Junio C HamanoSep 12, 2010
  9. Ævar Arnfjörð BjarmasonSep 12, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.