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

Re: [PATCH 1/3] parse-options: fix completion format when first option is skipped

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 2, 2026, 07:19 UTC
Message-ID
<ar9bDza3ImB71AIN@pks.im>
In-Reply-To
<xmqqik3l5njz.fsf@gitster.g>
On Thu, Oct 01, 2026 at 10:38:08AM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > The "--git-completion-helper" option can be passed to any command or
> > subcommand that uses the parse-options interface. The output it
> > generates is a space-separated list of subcommands or options understood
> > by the command.
> >
> > The format is slightly broken though in the case where the first option
> > is not being printed, like for example a group or a hidden option. In
> > that case, `show_gitcomp()` will of course skip that first entry. But
> > when printing the next option it checks for `opts == original_opts` to
> > verify whether we're printing the first option. The check will evaluate
> > to false though as we have skipped it, and thus we'll print a leading
> > space even though we have printed nothing else yet.
> >
> > Fix that bug by tracking whether we have already printed anything via a
> > local variable.
> 
> Very clearly articulated.  I would have chosen 'shown' as the
> variable name to so do, but 'first' may also be OK.

That's a fair point. We explicitly _don't_ care whether it's the first entry or not, as that would match the old logic that caused this bug in the first place. So `shown` is a better name indeed.

Patrick
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 4 of 14 in “builtin/refs: introduce subcommand groups”
  1. 0/3 builtin/refs: introduce subcommand groupsPatrick Steinhardt, Oct 1, 2026
  2. 1/3 parse-options: fix completion format when first option is skippedPatrick Steinhardt, Oct 1, 2026
  3. Junio C HamanoOct 1, 2026
  4. Patrick SteinhardtOct 2, 2026
  5. 2/3 parse-options: allow grouping subcommandsPatrick Steinhardt, Oct 1, 2026
  6. Junio C HamanoOct 1, 2026
  7. Patrick SteinhardtOct 2, 2026
  8. 3/3 builtin/refs: introduce subcommand groupsPatrick Steinhardt, Oct 1, 2026
  9. Junio C HamanoOct 1, 2026
  10. 0/4 builtin/refs: introduce subcommand groupsPatrick Steinhardt, Oct 2, 2026
  11. 1/4 parse-options: fix completion format when first option is skippedPatrick Steinhardt, Oct 2, 2026
  12. 2/4 parse-options: extract functions to print single optionPatrick Steinhardt, Oct 2, 2026
  13. 3/4 parse-options: allow grouping subcommandsPatrick Steinhardt, Oct 2, 2026
  14. 4/4 builtin/refs: introduce subcommand groupsPatrick Steinhardt, Oct 2, 2026

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.