All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol@kernel.org>
To: Junio C Hamano <gitster@pobox.com>, Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Philippe Blain <levraiphilippeblain@gmail.com>
Subject: Re: [PATCH] completion: add 'git history' subcommands
Date: Wed, 5 Aug 2026 23:20:58 +0200	[thread overview]
Message-ID: <6a8e934e-5ccc-40cc-877b-d1f1752888de@kernel.org> (raw)
In-Reply-To: <xmqq7bm4sfvh.fsf@gitster.g>

On 05/08/2026 at 18:15, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
>> On Tue, Aug 04, 2026 at 09:56:32PM +0200, Vincent Mailhol wrote:
>>> Use the parse-options completion helpers for the "git history"
>>> subcommands and their options. Complete positional arguments as
>>> revisions, and add coverage for each kind of completion.
>>
>> Ah, great! I wanted to write shell completion for git-history(1) for a
>> while but never really found the time to actually do it.
>>
>>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>>> index e875787710..f10813c8d7 100644
>>> --- a/contrib/completion/git-completion.bash
>>> +++ b/contrib/completion/git-completion.bash
>>> @@ -2137,6 +2137,30 @@ _git_help ()
>>>  	fi
>>>  }
>>>  
>>> +_git_history ()
>>> +{
>>> +	local subcommands subcommand
>>> +
>>> +	__git_resolve_builtins "history"
>>> +
>>> +	subcommands="$___git_resolved_builtins"
>>> +	subcommand="$(__git_find_subcommand "$subcommands")"
>>> +
>>> +	if [ -z "$subcommand" ]; then
>>> +		__gitcomp "$subcommands"
>>> +		return
>>> +	fi
>>
>> Okay. We first try to figure out whether there is any subcommand passed
>> by the user already. If not, we complete available subcommands.
> 
> This may be a tangent, but anyway.  I was looking at this patch (not
> that I think I am capable of giving a completion patch a serious
> review), comparing with other completions, and the similarity of the
> boilerplate part above was so striking.  I suspect that these were
> organically grown, but at some point when the tree is quiescent, can
> we coalesce the completion routines for subcommands that share the
> same pattern for better maintainability?

I am not sure if this would increase the maintainability.

For example, I started looking at Patrick's suggestion ※ to cover the

  git history split

special case. If we add this, we would need to dispatch this in
_git_history() by adding something like:

	if [ "$subcommand" = "split" ]; then
		__git_complete_history_split
		return
	fi

but if we coalesce the completion routine for the subcommands, where
should this dispatcher go?

I see this boilerplate as a skeleton waiting for extensions. Of course,
maybe I am missing some points and maybe we can coalesce the code while
still allowing for extensions. But currently, I am not able to depict
how this should look like.


※ The fact that I started to look at the 'git history split' completion
doesn't mean that I am committing myself to implement it. I will do a
best effort try in my available time. If I get a decent result, I will
share, if not, I would ask you to bear with the current patch!


Yours sincerely,
Vincent Mailhol


  reply	other threads:[~2026-08-05 21:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 19:56 [PATCH] completion: add 'git history' subcommands Vincent Mailhol
2026-08-05  6:19 ` Patrick Steinhardt
2026-08-05 11:56   ` D. Ben Knoble
2026-08-05 16:15   ` Junio C Hamano
2026-08-05 21:20     ` Vincent Mailhol [this message]
2026-08-06  5:18       ` Patrick Steinhardt

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=6a8e934e-5ccc-40cc-877b-d1f1752888de@kernel.org \
    --to=mailhol@kernel.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=levraiphilippeblain@gmail.com \
    --cc=ps@pks.im \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.