# [Feature request] "Hooks" for git log

6 messages from 2020-03-12 to 2020-03-12. Participants: Konstantin Tokarev, Junio C Hamano.
Thread: https://gitlist.dev/t/52983

## Konstantin Tokarev, 2020-03-12 15:06

Subject: [Feature request] "Hooks" for git log
Message-ID: <558831584024173@sas1-438a02fc058e.qloud-c.yandex.net>
URL: https://gitlist.dev/e/558831584024173%40sas1-438a02fc058e.qloud-c.yandex.net

```
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, 2020-03-12 16:21

Subject: Re: [Feature request] "Hooks" for git log
Message-ID: <628991584029077@iva6-9bda19f40fc4.qloud-c.yandex.net>
URL: https://gitlist.dev/e/628991584029077%40iva6-9bda19f40fc4.qloud-c.yandex.net
In-Reply-To: <558831584024173@sas1-438a02fc058e.qloud-c.yandex.net>

```


12.03.2020, 18:06, "Konstantin Tokarev" <annulen@yandex.ru>:
> 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, 2020-03-12 18:58

Subject: Re: [Feature request] "Hooks" for git log
Message-ID: <xmqqo8t1flin.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqo8t1flin.fsf%40gitster.c.googlers.com
In-Reply-To: <558831584024173@sas1-438a02fc058e.qloud-c.yandex.net>

```
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


```

## Konstantin Tokarev, 2020-03-12 19:08

Subject: Re: [Feature request] "Hooks" for git log
Message-ID: <79741584039971@myt6-4d759d962265.qloud-c.yandex.net>
URL: https://gitlist.dev/e/79741584039971%40myt6-4d759d962265.qloud-c.yandex.net
In-Reply-To: <xmqqo8t1flin.fsf@gitster.c.googlers.com>

```


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.


-- 
Regards,
Konstantin


```

## Konstantin Tokarev, 2020-03-12 19:24

Subject: Re: [Feature request] "Hooks" for git log
Message-ID: <87951584041001@myt5-5e0e3f348369.qloud-c.yandex.net>
URL: https://gitlist.dev/e/87951584041001%40myt5-5e0e3f348369.qloud-c.yandex.net
In-Reply-To: <79741584039971@myt6-4d759d962265.qloud-c.yandex.net>

```


12.03.2020, 22:08, "Konstantin Tokarev" <annulen@yandex.ru>:
> 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, 2020-03-12 19:31

Subject: Re: [Feature request] "Hooks" for git log
Message-ID: <xmqqblp1fjzb.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqblp1fjzb.fsf%40gitster.c.googlers.com
In-Reply-To: <87951584041001@myt5-5e0e3f348369.qloud-c.yandex.net>

```
Konstantin Tokarev <annulen@yandex.ru> writes:

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

```
