git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [Feature request] "Hooks" for git log
@ 2020-03-12 15:06 Konstantin Tokarev
  2020-03-12 16:21 ` Konstantin Tokarev
  2020-03-12 18:58 ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Konstantin Tokarev @ 2020-03-12 15:06 UTC (permalink / raw)
  To: git@vger.kernel.org

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



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

* Re: [Feature request] "Hooks" for git log
  2020-03-12 15:06 [Feature request] "Hooks" for git log Konstantin Tokarev
@ 2020-03-12 16:21 ` Konstantin Tokarev
  2020-03-12 18:58 ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Konstantin Tokarev @ 2020-03-12 16:21 UTC (permalink / raw)
  To: git@vger.kernel.org



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


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

* Re: [Feature request] "Hooks" for git log
  2020-03-12 15:06 [Feature request] "Hooks" for git log Konstantin Tokarev
  2020-03-12 16:21 ` Konstantin Tokarev
@ 2020-03-12 18:58 ` Junio C Hamano
  2020-03-12 19:08   ` Konstantin Tokarev
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2020-03-12 18:58 UTC (permalink / raw)
  To: Konstantin Tokarev; +Cc: git@vger.kernel.org

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


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

* Re: [Feature request] "Hooks" for git log
  2020-03-12 18:58 ` Junio C Hamano
@ 2020-03-12 19:08   ` Konstantin Tokarev
  2020-03-12 19:24     ` Konstantin Tokarev
  0 siblings, 1 reply; 6+ messages in thread
From: Konstantin Tokarev @ 2020-03-12 19:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org



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


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

* Re: [Feature request] "Hooks" for git log
  2020-03-12 19:08   ` Konstantin Tokarev
@ 2020-03-12 19:24     ` Konstantin Tokarev
  2020-03-12 19:31       ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Konstantin Tokarev @ 2020-03-12 19:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org



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


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

* Re: [Feature request] "Hooks" for git log
  2020-03-12 19:24     ` Konstantin Tokarev
@ 2020-03-12 19:31       ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2020-03-12 19:31 UTC (permalink / raw)
  To: Konstantin Tokarev; +Cc: git@vger.kernel.org

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

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

end of thread, other threads:[~2020-03-12 19:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 15:06 [Feature request] "Hooks" for git log Konstantin Tokarev
2020-03-12 16:21 ` Konstantin Tokarev
2020-03-12 18:58 ` Junio C Hamano
2020-03-12 19:08   ` Konstantin Tokarev
2020-03-12 19:24     ` Konstantin Tokarev
2020-03-12 19:31       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).