From: Jeff King <peff@peff.net>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org,
"Philippe Blain" <levraiphilippeblain@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: Re: [PATCH] completion: bash: support recursive aliases
Date: Mon, 9 Nov 2020 17:19:39 -0500 [thread overview]
Message-ID: <20201109221939.GA670413@coredump.intra.peff.net> (raw)
In-Reply-To: <20201109215248.461167-1-felipe.contreras@gmail.com>
On Mon, Nov 09, 2020 at 03:52:48PM -0600, Felipe Contreras wrote:
> It is possible to have a recursive aliases like:
>
> l = log --oneline
> lg = l --graph
>
> So the completion should detect such aliases as well.
Yeah, agreed that it would be nice to handle this case.
> __git_aliased_command ()
> {
> [...]
> + if [[ -n "$found" ]]; then
> + local expansion=$(__git_aliased_command "$found")
> + echo "${expansion:-$found}"
> + fi
So if we expanded X to Y, we recurse and try to expand Y. That makes
sense, but just thinking of some possible drawbacks:
- it's an extra process invocation for each alias lookup (to see "nope,
this doesn't expand further"). That's probably OK, since this is
triggered by human action.
I don't think there's a way to avoid this with the current set of Git
commands. "git help lg" isn't recursive, and anyway isn't suitable
for general use (if there is no such alias, it tries to load the
manpage!).
- there's no limit on the recursion if we do see a cycle. Doing:
git config alias.foo foo
git foo <Tab>
seems to fork-bomb the system with bash processes (well, perhaps not
a true fork-bomb because they expand linearly rather than
exponentially, but still...).
That's obviously a broken and useless, but the outcome is less than
ideal. We could avoid it by looking for repeats in the chain. Doing
so in posix shell is pretty painful, but perhaps bash associate
arrays would make it not too painful.
We do have "git <cmd> --git-completion-helper" these days. I wonder if
something like "git --expand-alias-to-command" would be a useful
addition, as it would let us directly ask which Git command would be
executed (if any). And it would make both downsides go away.
I don't mind this solution in the meantime, though.
-Peff
next prev parent reply other threads:[~2020-11-09 22:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 21:52 [PATCH] completion: bash: support recursive aliases Felipe Contreras
2020-11-09 22:01 ` Taylor Blau
2020-11-09 22:29 ` Junio C Hamano
2020-11-10 1:10 ` Felipe Contreras
2020-11-10 0:59 ` Felipe Contreras
2020-11-09 22:19 ` Jeff King [this message]
2020-11-10 1:06 ` Felipe Contreras
2020-11-10 1:19 ` Jeff King
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=20201109221939.GA670413@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=levraiphilippeblain@gmail.com \
--cc=szeder.dev@gmail.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).