From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: Felipe Contreras <felipe.contreras@gmail.com>,
git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 2/2] completion: bash: check for alias loop
Date: Thu, 12 Nov 2020 09:20:55 -0800 [thread overview]
Message-ID: <xmqqsg9ejxu0.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201112100204.GC4270@szeder.dev> ("SZEDER Gábor"'s message of "Thu, 12 Nov 2020 11:02:04 +0100")
SZEDER Gábor <szeder.dev@gmail.com> writes:
>> while [[ -n "$cur" ]]; do
>> + if [[ "$list" == *"$cur "* ]]; then
>
> I suspect the right hand side should be *" $cur "* ...
>
>> + # loop detected
>> + return
>> + fi
>> +
>> cmdline=$(__git config --get "alias.$cur")
>> - last=$cur
>> + list="$cur $list"
>
> ... and this should be list=" $cur $list", because otherwise a partial
> match is possible and would be mistaken for a loop (though I didn't
> actually test whether that's indeed the case).
Traditionist may use
list=
while :
do
cur=$(obtain cur somehow)
case " $list " in
*" $cur "*) : cur appears in list ;;
esac
list="$cur${list+ }$list"
done
to make the invariant "$list is a SP-separated tokens, no extra SP on
either ends" and I think the same idea would work with [[ $a == $b ]],
but "one SP on both ends, two SPs in between" like yours do is OK, too.
Not keeping excess SPs out of the list (unlike the above "no extra
SP on ends") means how "finally, take the first token in the list,
that's the answer" is coded, though. You'd need to split off the
leading SP from it (below).
>> cur=
>>
>> for word in $cmdline; do
>> @@ -1149,7 +1154,7 @@ __git_aliased_command ()
>> done
>> done
>>
>> - cur=$last
>> + cur="${list%% *}"
>> if [[ "$cur" != "$1" ]]; then
>> echo "$cur"
>> fi
>> --
>> 2.29.2
>>
prev parent reply other threads:[~2020-11-12 17:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 2:03 [PATCH v3 0/2] completion: bash: support for recursive aliases Felipe Contreras
2020-11-10 2:03 ` [PATCH v3 1/2] completion: bash: support " Felipe Contreras
2020-11-10 2:03 ` [PATCH v3 2/2] completion: bash: check for alias loop Felipe Contreras
2020-11-12 10:02 ` SZEDER Gábor
2020-11-12 17:20 ` Junio C Hamano [this message]
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=xmqqsg9ejxu0.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--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).