{"thread":{"id":"54632","subject":"[PATCH] completion: bash: improve alias loop detection","startedAt":"2020-11-12T22:34:56Z","lastAt":"2020-11-17T19:52:30Z","messageCount":3,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"409805","messageId":"20201112223452.1526315-1-felipe.contreras@gmail.com","threadId":"54632","inReplyTo":null,"subject":"[PATCH] completion: bash: improve alias loop detection","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-11-12T22:34:52Z","receivedAt":"2020-11-12T22:34:56Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It is possible for the name of an alias to end with the name of another\nalias, in which case the code will incorrectly detect a loop.\n\nWe can fix that by adding an extra space between words.\n\nSuggested-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ce0dc1e0f8..cd2a02bafd 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1121,16 +1121,17 @@ __git_pretty_aliases ()\n # __git_aliased_command requires 1 argument\n __git_aliased_command ()\n {\n-\tlocal cur=$1 list word cmdline\n+\tlocal cur=$1 last list word cmdline\n \n \twhile [[ -n \"$cur\" ]]; do\n-\t\tif [[ \"$list\" == *\"$cur \"* ]]; then\n+\t\tif [[ \"$list\" == *\" $cur \"* ]]; then\n \t\t\t# loop detected\n \t\t\treturn\n \t\tfi\n \n \t\tcmdline=$(__git config --get \"alias.$cur\")\n-\t\tlist=\"$cur $list\"\n+\t\tlist=\" $cur $list\"\n+\t\tlast=$cur\n \t\tcur=\n \n \t\tfor word in $cmdline; do\n@@ -1154,7 +1155,7 @@ __git_aliased_command ()\n \t\tdone\n \tdone\n \n-\tcur=\"${list%% *}\"\n+\tcur=$last\n \tif [[ \"$cur\" != \"$1\" ]]; then\n \t\techo \"$cur\"\n \tfi\n-- \n2.29.2\n\n"},{"id":"410117","messageId":"xmqqtutn6ccp.fsf@gitster.c.googlers.com","threadId":"54632","inReplyTo":"20201112223452.1526315-1-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: bash: improve alias loop detection","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-17T18:56:54Z","receivedAt":"2020-11-17T18:57:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> It is possible for the name of an alias to end with the name of another\n> alias, in which case the code will incorrectly detect a loop.\n>\n> We can fix that by adding an extra space between words.\n>\n> Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 9 +++++----\n>  1 file changed, 5 insertions(+), 4 deletions(-)\n\nOK.  An extra local variable would not hurt and makes the code\neasier to read.\n\nWill queue.\n\n\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index ce0dc1e0f8..cd2a02bafd 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1121,16 +1121,17 @@ __git_pretty_aliases ()\n>  # __git_aliased_command requires 1 argument\n>  __git_aliased_command ()\n>  {\n> -\tlocal cur=$1 list word cmdline\n> +\tlocal cur=$1 last list word cmdline\n>  \n>  \twhile [[ -n \"$cur\" ]]; do\n> -\t\tif [[ \"$list\" == *\"$cur \"* ]]; then\n> +\t\tif [[ \"$list\" == *\" $cur \"* ]]; then\n>  \t\t\t# loop detected\n>  \t\t\treturn\n>  \t\tfi\n>  \n>  \t\tcmdline=$(__git config --get \"alias.$cur\")\n> -\t\tlist=\"$cur $list\"\n> +\t\tlist=\" $cur $list\"\n> +\t\tlast=$cur\n>  \t\tcur=\n>  \n>  \t\tfor word in $cmdline; do\n> @@ -1154,7 +1155,7 @@ __git_aliased_command ()\n>  \t\tdone\n>  \tdone\n>  \n> -\tcur=\"${list%% *}\"\n> +\tcur=$last\n>  \tif [[ \"$cur\" != \"$1\" ]]; then\n>  \t\techo \"$cur\"\n>  \tfi\n"},{"id":"410122","messageId":"CAMP44s3dFZ4EjOgYd_e5JvNQWH_6bjLAHCYMa7n2kOFXWHCwcg@mail.gmail.com","threadId":"54632","inReplyTo":"xmqqtutn6ccp.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] completion: bash: improve alias loop detection","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-11-17T19:52:16Z","receivedAt":"2020-11-17T19:52:30Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, Nov 17, 2020 at 12:57 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n> > It is possible for the name of an alias to end with the name of another\n> > alias, in which case the code will incorrectly detect a loop.\n> >\n> > We can fix that by adding an extra space between words.\n> >\n> > Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>\n> > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> > ---\n> >  contrib/completion/git-completion.bash | 9 +++++----\n> >  1 file changed, 5 insertions(+), 4 deletions(-)\n>\n> OK.  An extra local variable would not hurt and makes the code\n> easier to read.\n\nIt was there on v2. Which now may be a more reasonable sequence.\n\n-- \nFelipe Contreras\n"}]}