git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Todd Zullinger <tmz@pobox.com>
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [BUG] completion.commands does not remove multiple commands
Date: Sat, 2 Mar 2019 05:07:04 +0100	[thread overview]
Message-ID: <20190302040704.GN19739@szeder.dev> (raw)
In-Reply-To: <20190302024011.GF31362@zaya.teonanacatl.net>

On Fri, Mar 01, 2019 at 09:40:12PM -0500, Todd Zullinger wrote:
> Hi,
> 
> Junio C Hamano wrote:
> > Todd Zullinger <tmz@pobox.com> writes:
> > 
> >> Hmm.  The comments in list_cmds_by_config() made me wonder
> >> if not using a local repo config was intentional:
> >>
> >>         /*
> >>          * There's no actual repository setup at this point (and even
> >>          * if there is, we don't really care; only global config
> >>          * matters). If we accidentally set up a repository, it's ok
> >>          * too since the caller (git --list-cmds=) should exit shortly
> >>          * anyway.
> >>          */
> > 
> > Doesn't the output from list-cmds-by-config get cached at the
> > completion script layer in $__git_blah variables, and the cached
> > values are not cleared when you chdir around?
> 
> In testing, I didn't find any evidence of caching.  Setting
> commands to be added and removed in the global and local
> configs worked reasonably.
> 
> Duy's reply suggests that was considered but not
> implemented.  I there were caching (and if it were tedious
> for the completion code to keep fresh between repos), then
> it would a bad plan to allow per-repo config.

The completion script used to cache the list of porcelain commands,
but then Duy came along and removed it in 3301d36b29 (completion: add
and use --list-cmds=alias, 2018-05-20).

We cached the commands, because it was a bit involved to get them:
first we run 'git help -a' to list all commands, then extracted the
command names from the help output with 'grep', and finally an
enormous case statement removed all plumbing commands.  Caching spared
us the overhead of these external processes and maybe 2-3 subshells.
Note that because of this caching if you dropped a third-party
'git-foo' command in your $PATH, it didn't show up in completion until
you re-sourced the completion script, which was the standard way to
invalidate/refresh the caches.

However, even when we cached porcelain commands, we didn't cache
aliases, even though getting them is a bit involved as well, requiring
running 'git config', two subshells and a shell loop.  I presume that
back then the reason for not caching aliases was that they could be
repo-specific.

Now, ever since Duy revamped commands completion, we only run a simple
$(git --list-cmds=...), i.e. a git command and a subshell takes care
of all that.  IMO this is the best we ever had, because it uses one
less subshell than before to list both commands and aliases, and it
lists everything afresh, including third-party 'git-foo' commands.

I don't see the benefit of bringing back caching.  Yes, on one hand we
could complete commands with a single variable expansion, which is
clearly faster than that $(git --list-cmds=...).  OTOH, that's only
commands, but what about aliases?  If we cache aliases, too, then that
could be considered a regression by those who do have repo-specific
aliases; if we don't, then we are back at running 'git config' and two
subshells, i.e. one subshell more than we currently have.

And if we won't cache commands, then we might as well modify
list_cmds_by_config() to read 'completion.commands' from the
repo-specific config, too.  I'm fairly neutral on this, because I
can only imagine rather convoluted scenarios where a repo-specific
command list would be useful, but at least it would make it consistent
with aliases, which we read from the current repo's config and we
always have.


Note, however, that for completeness sake, if we choose to update
list_cmds_by_config() to read the repo's config as well, then we
should also update the completion script to run $(__git
--list-cmds=...), note the two leading underscores, so in case of 'git
-C over/there <TAB>' it would read 'completion.commands' from the right
repository.



  reply	other threads:[~2019-03-02  4:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 22:31 [BUG] completion.commands does not remove multiple commands Todd Zullinger
2019-02-28 23:05 ` Jeff King
2019-03-01 17:34   ` Todd Zullinger
2019-03-01 18:30     ` Jeff King
2019-03-01 22:15       ` Todd Zullinger
2019-03-01 23:08         ` Jeff King
2019-03-02  1:08           ` Duy Nguyen
2019-03-02  1:18         ` Junio C Hamano
2019-03-02  2:40           ` Todd Zullinger
2019-03-02  4:07             ` SZEDER Gábor [this message]
2019-03-03  1:34               ` Todd Zullinger
2019-03-03 17:06               ` Jeff King
2019-03-01 17:34   ` [PATCH 1/3] doc: note config file restrictions for completion.commands Todd Zullinger
2019-03-17 13:12     ` Duy Nguyen
2019-03-17 18:16       ` [PATCH v2 0/4] completion.commands: fix multiple command removals Todd Zullinger
2019-03-17 18:16       ` [PATCH v2 1/4] git: read local config in --list-cmds Todd Zullinger
2019-03-18  9:41         ` Duy Nguyen
2019-03-20 18:03           ` [PATCH v3 0/4] completion.commands: fix multiple command removals Todd Zullinger
2019-03-21  2:58             ` Junio C Hamano
2019-03-21 17:18               ` Todd Zullinger
2019-03-21  9:45             ` Duy Nguyen
2019-03-20 18:03           ` [PATCH v3 1/4] git: read local config in --list-cmds Todd Zullinger
2019-03-20 18:03           ` [PATCH v3 2/4] t9902: test multiple removals via completion.commands Todd Zullinger
2019-03-20 18:03           ` [PATCH v3 3/4] completion: fix multiple command removals Todd Zullinger
2019-03-20 18:03           ` [PATCH v3 4/4] completion: use __git when calling --list-cmds Todd Zullinger
2019-03-17 18:16       ` [PATCH v2 2/4] t9902: test multiple removals via completion.commands Todd Zullinger
2019-03-17 18:16       ` [PATCH v2 3/4] completion: fix multiple command removals Todd Zullinger
2019-03-17 18:16       ` [PATCH v2 4/4] completion: use __git when calling --list-cmds Todd Zullinger
2019-03-01 17:34   ` [PATCH 2/3] t9902: test multiple removals via completion.commands Todd Zullinger
2019-03-01 18:22     ` Eric Sunshine
2019-03-01 20:50       ` SZEDER Gábor
2019-03-01 21:56         ` Todd Zullinger
2019-03-01 17:34   ` [PATCH 3/3] completion: fix multiple command removals Todd Zullinger
2019-03-01 18:16     ` Jeff King
2019-02-28 23:05 ` [BUG] completion.commands does not remove multiple commands SZEDER Gábor

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190302040704.GN19739@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    --cc=tmz@pobox.com \
    /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.
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).