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

Re: [PATCH 2/9] completion: optimize refs completion

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 13, 2011, 00:50 UTC
Message-ID
<7v7h497m01.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1318085683-29830-3-git-send-email-szeder@ira.uka.de>
SZEDER Gábor <szeder@ira.uka.de> writes:
> After a unique command or option is completed, in most cases it is a
> good thing to add a trailing a space, but sometimes it doesn't makes
s/makes/make/;
Show 13 quoted lines
> __gitcomp() therefore iterates over all possible completion words it
> got as argument, and checks each word whether a trailing space is
> necessary or not.  This is ok for commands, options, etc., i.e. when
> the number of words is relatively small, but can be noticeably slow
> for large number of refs.  However, while options might or might not
> need that trailing space, refs are always handled uniformly and always
> get that trailing space (or a trailing '.' for 'git config
> branch.<head>.').
> ...
> So, add a specialized variant of __gitcomp() that only deals with
> possible completion words separated by a newline and uniformly appends
> the trailing space to all words using 'compgen -S' (or any other
> suffix, if specified), so no iteration over all words is done.
s/is done./is needed./;

I think I followed your logic (very well written ;-), but feel somewhat dirty, as you are conflating the "These things are separated with newlines" with "These things do not need inspection --- they all need suffix", which has one obvious drawback --- you may find other class of words that always want a SP after each of them but the source that generates such a class of words may not separate the list elements with a newline.

Because a ref cannot have $IFS whitespace in its name anyway, I think you can rename __gitcomp_nl to a name that conveys more clearly what it does (i.e. "complete and always append suffix"), drop the IFS fiddling from the function, and get the same optimization, no?

Previous: SZEDER GáborNext: SZEDER Gábor
Message 4 of 16 in “ref completion optimizations, fixes, and cleanups”
  1. 0/9 ref completion optimizations, fixes, and cleanupsSZEDER Gábor, Oct 8, 2011
  2. 1/9 completion: document __gitcomp()SZEDER Gábor, Oct 8, 2011
  3. 2/9 completion: optimize refs completionSZEDER Gábor, Oct 8, 2011
  4. Junio C HamanoOct 13, 2011
  5. SZEDER GáborOct 13, 2011
  6. Junio C HamanoOct 13, 2011
  7. SZEDER GáborOct 14, 2011
  8. 2/9 completion: optimize refs completionSZEDER Gábor, Oct 15, 2011
  9. Junio C HamanoOct 16, 2011
  10. 3/9 completion: make refs completion consistent for local and remote reposSZEDER Gábor, Oct 8, 2011
  11. 4/9 completion: improve ls-remote output filtering in __git_refs()SZEDER Gábor, Oct 8, 2011
  12. 5/9 completion: support full refs from remote repositoriesSZEDER Gábor, Oct 8, 2011
  13. 6/9 completion: query only refs/heads/ in __git_refs_remotes()SZEDER Gábor, Oct 8, 2011
  14. 7/9 completion: improve ls-remote output filtering in __git_refs_remotes()SZEDER Gábor, Oct 8, 2011
  15. 8/9 completion: fast initial completion for config 'remote.*.fetch' valueSZEDER Gábor, Oct 8, 2011
  16. 9/9 completion: remove broken dead code from __git_heads() and __git_tags()SZEDER Gábor, Oct 8, 2011

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.