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

Re: [PATCH 2/4] completion: introduce __gitcomp_2 ()

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 2, 2014, 23:47 UTC
Message-ID
<xmqqeh4qndxs.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1388415138-11011-3-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 15 quoted lines
> There are situations where two classes of completions possible. For
> example
>
>   branch.<TAB>
>
> should try to complete
>
>   branch.master.
>   branch.autosetupmerge
>   branch.autosetuprebase
>
> The first candidate has the suffix ".", and the second/ third candidates
> have the suffix " ". To facilitate completions of this kind, create a
> variation of __gitcomp_nl () that accepts two sets of arguments and two
> independent suffixes.

That sounds like a reasonable issue to address, but I do not quite get why you need a new helper to do this.

If the original only knows to throw "branch." + branch names + trailing dot into COMPREPLY[] and does so by calling gitcomp_nl, isn't it the matter of making another call to gitcomp_nl just after the existing call to stuff branch.autosetup* with trailing SP to append them to COMPREPLY[]?

Ahh, is that because the eventual call to __gitcompadd() starts the iteration starting from zero, essentially forbidding you to incrementally adding to COMPREPLY[] from multiple callers, even though it is called comp "add" not "replace with this single thing"?

What I am wondering is if a cleaner solution that can be reused by later needs that may have more than two data sources (or more than two suffixes) might be to create a variant of __gitcomp_nl that does not clear existing entries in COMPREPLY[] array, add a helper to clear the array, which would make the existing one to:

	__gitcomp_nl () {
        	__gitcomp_clear
                __gitcomp_nl_append "$@"
	}

and then complete branch.* using two calls to __gitcomp_*, letting the first one clear and later one(s) accumulate:

	__gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
	__gitcomp_nl_append $"autosetupmerge\nautosetuprebase\n" "$pfx" "$cur_" " "
Will queue as-is.
Thanks.
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 4 of 14 in “Fix branch.autosetup(merge|rebase) completion”
  1. 0/4 Fix branch.autosetup(merge|rebase) completionRamkumar Ramachandra, Dec 30, 2013
  2. 1/4 completion: prioritize ./git-completion.bashRamkumar Ramachandra, Dec 30, 2013
  3. 2/4 completion: introduce __gitcomp_2 ()Ramkumar Ramachandra, Dec 30, 2013
  4. Junio C HamanoJan 2, 2014
  5. Ramkumar RamachandraJan 3, 2014
  6. Junio C HamanoJan 3, 2014
  7. Ramkumar RamachandraJan 3, 2014
  8. 3/4 completion: fix branch.autosetup(merge|rebase)Ramkumar Ramachandra, Dec 30, 2013
  9. Junio C HamanoJan 2, 2014
  10. Ramkumar RamachandraJan 3, 2014
  11. Junio C HamanoJan 3, 2014
  12. Ramkumar RamachandraJan 3, 2014
  13. Junio C HamanoJan 3, 2014
  14. 4/4 completion: fix remote.pushdefaultRamkumar Ramachandra, Dec 30, 2013

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.