threads / discuss / 52983

[Feature request] "Hooks" for git log

Subject: [Feature request] "Hooks" for git log

## tl;dr

6 messages between Mar 12, 2020 and Mar 12, 2020.

replies: 5people: 2as markdown or json

Konstantin Tokarev· Mar 12, 2020, 15:06 UTC · lore
Hello,

While it's possible to filter commits in `git log` by their contents with --grep and -S options, it's not always possible for formulate desirable filter in their terms.

I think it would be very useful if git log provided new option named e.g. --hook or --script, which would take script path as an argument. git log would follow it's normal way of operation, applying other filtering options it was given, however intstead of printing info on commit that matches filters, it invokes script with commit hash as an argument. Script can do whatever it needs with hash, including any git operations, can print commit info to log if needed, or print something else, or keep silence. If script returns non-zero, parent git log command terminates, otherwise it continues.

-- 
Regards,
Konstantin
Konstantin Tokarev· Mar 12, 2020, 16:21 UTC · re: Konstantin Tokarev · lore

Re: [Feature request] "Hooks" for git log

12.03.2020, 18:06, "Konstantin Tokarev" <annulen@yandex.ru>:
Show 15 quoted lines
> Hello,
>
> While it's possible to filter commits in `git log` by their contents with
> --grep and -S options, it's not always possible for formulate desirable
> filter in their terms.
>
> I think it would be very useful if git log provided new option named e.g.
> --hook or --script, which would take script path as an argument.
> git log would follow it's normal way of operation, applying other filtering
> options it was given, however intstead of printing info on commit that
> matches filters, it invokes script with commit hash as an argument.
> Script can do whatever it needs with hash, including any git operations,
> can print commit info to log if needed, or print something else, or keep
> silence. If script returns non-zero, parent git log command terminates,
> otherwise it continues.

On the second thought, its user interface should probably be more like `git submodule foreach` to allow use of one-liners. For example, there is a bug which I've recently reported that prevents use of

git log --follow --full-diff <path>
It could have been worked around easily as
git log --follow <path> foreach git show $1
(syntax may be different)
-- 
Regards,
Konstantin
Junio C Hamano· Mar 12, 2020, 18:58 UTC · re: Konstantin Tokarev · lore

Re: [Feature request] "Hooks" for git log

Konstantin Tokarev <annulen@yandex.ru> writes:
Show 9 quoted lines
> I think it would be very useful if git log provided new option named e.g.
> --hook or --script, which would take script path as an argument.
> git log would follow it's normal way of operation, applying other filtering
> options it was given, however intstead of printing info on commit that
> matches filters, it invokes script with commit hash as an argument.
> Script can do whatever it needs with hash, including any git operations,
> can print commit info to log if needed, or print something else, or keep
> silence. If script returns non-zero, parent git log command terminates,
> otherwise it continues.
You do not need a hook for that, no?
 $ git log --format='%H' ...your other options here... |
   while read commit
   do
	... your "hook" that checks the $commit to see if
        ... it is "interesting" and shows or discard or whatever
        ... it does comes here
   done
Konstantin Tokarev· Mar 12, 2020, 19:08 UTC · re: Junio C Hamano · lore

Re: [Feature request] "Hooks" for git log

12.03.2020, 21:58, "Junio C Hamano" <gitster@pobox.com>:
Show 21 quoted lines
> Konstantin Tokarev <annulen@yandex.ru> writes:
>
>>  I think it would be very useful if git log provided new option named e.g.
>>  --hook or --script, which would take script path as an argument.
>>  git log would follow it's normal way of operation, applying other filtering
>>  options it was given, however intstead of printing info on commit that
>>  matches filters, it invokes script with commit hash as an argument.
>>  Script can do whatever it needs with hash, including any git operations,
>>  can print commit info to log if needed, or print something else, or keep
>>  silence. If script returns non-zero, parent git log command terminates,
>>  otherwise it continues.
>
> You do not need a hook for that, no?
>
>  $ git log --format='%H' ...your other options here... |
>    while read commit
>    do
>         ... your "hook" that checks the $commit to see if
>         ... it is "interesting" and shows or discard or whatever
>         ... it does comes here
>    done

When pager is in use, git log loads commits lazily when you scroll down. I find this feature rather crucial for working with any long history, and I don't see how to achieve this with pipe.

-- 
Regards,
Konstantin
Konstantin Tokarev· Mar 12, 2020, 19:24 UTC · re: Konstantin Tokarev · lore

Re: [Feature request] "Hooks" for git log

12.03.2020, 22:08, "Konstantin Tokarev" <annulen@yandex.ru>:
Show 26 quoted lines
> 12.03.2020, 21:58, "Junio C Hamano" <gitster@pobox.com>:
>>  Konstantin Tokarev <annulen@yandex.ru> writes:
>>
>>>   I think it would be very useful if git log provided new option named e.g.
>>>   --hook or --script, which would take script path as an argument.
>>>   git log would follow it's normal way of operation, applying other filtering
>>>   options it was given, however intstead of printing info on commit that
>>>   matches filters, it invokes script with commit hash as an argument.
>>>   Script can do whatever it needs with hash, including any git operations,
>>>   can print commit info to log if needed, or print something else, or keep
>>>   silence. If script returns non-zero, parent git log command terminates,
>>>   otherwise it continues.
>>
>>  You do not need a hook for that, no?
>>
>>   $ git log --format='%H' ...your other options here... |
>>     while read commit
>>     do
>>          ... your "hook" that checks the $commit to see if
>>          ... it is "interesting" and shows or discard or whatever
>>          ... it does comes here
>>     done
>
> When pager is in use, git log loads commits lazily when you scroll down.
> I find this feature rather crucial for working with any long history, and
> I don't see how to achieve this with pipe.

Nvm, passing to less -R makes it pause when needed. I've never realized it was that simple.

-- 
Regards,
Konstantin
Junio C Hamano· Mar 12, 2020, 19:31 UTC · re: Konstantin Tokarev · lore

Re: [Feature request] "Hooks" for git log

Konstantin Tokarev <annulen@yandex.ru> writes:
Show 6 quoted lines
>> When pager is in use, git log loads commits lazily when you scroll down.
>> I find this feature rather crucial for working with any long history, and
>> I don't see how to achieve this with pipe.
>
> Nvm, passing to less -R makes it pause when needed. I've never realized it
> was that simple.

Heh, after all once you realize "git log" internally pipes its output to the pager, doing the same thing yourself should become trivial ;-)

← back to recent threads