* [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility @ 2013-03-11 12:21 Matthieu Moy 2013-03-11 16:17 ` Junio C Hamano 0 siblings, 1 reply; 12+ messages in thread From: Matthieu Moy @ 2013-03-11 12:21 UTC (permalink / raw) To: git; +Cc: Matthieu Moy The function-wide redirection used for __git_ls_files_helper and __git_diff_index_helper work only with bash. Using ZSH, trying to complete an inexistant directory gave this: git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr> --- These two instances seem to be the only ones in the file. I'm not sure whether the 2>/dev/null would be needed for the command on the RHS of the && too (git ls-files and git diff-index). contrib/completion/git-completion.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b62bec0..0640274 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -300,8 +300,8 @@ __git_index_file_list_filter () __git_ls_files_helper () { # NOTE: $2 is not quoted in order to support multiple options - cd "$1" && git ls-files --exclude-standard $2 -} 2>/dev/null + cd "$1" 2>/dev/null && git ls-files --exclude-standard $2 +} # Execute git diff-index, returning paths relative to the directory @@ -309,8 +309,8 @@ __git_ls_files_helper () # specified in the second argument. __git_diff_index_helper () { - cd "$1" && git diff-index --name-only --relative "$2" -} 2>/dev/null + cd "$1" 2>/dev/null && git diff-index --name-only --relative "$2" +} # __git_index_files accepts 1 or 2 arguments: # 1: Options to pass to ls-files (required). -- 1.8.2.rc3.16.g0a33571.dirty ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 12:21 [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility Matthieu Moy @ 2013-03-11 16:17 ` Junio C Hamano 2013-03-11 16:41 ` Junio C Hamano 2013-03-11 17:09 ` Manlio Perillo 0 siblings, 2 replies; 12+ messages in thread From: Junio C Hamano @ 2013-03-11 16:17 UTC (permalink / raw) To: Matthieu Moy; +Cc: git, Manlio Perillo Matthieu Moy <Matthieu.Moy@imag•fr> writes: > The function-wide redirection used for __git_ls_files_helper and > __git_diff_index_helper work only with bash. Using ZSH, trying to > complete an inexistant directory gave this: > > git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ > > Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr> > --- This is not bash-ism but POSIX.1, even though it is not very well known. I recall commenting on this exact pattern during the review. http://thread.gmane.org/gmane.comp.version-control.git/213232/focus=213286 After all, I was right when I said that some implementations may get it wrong and we shouldn't use the construct X-<. > These two instances seem to be the only ones in the file. > > I'm not sure whether the 2>/dev/null would be needed for the command > on the RHS of the && too (git ls-files and git diff-index). It would not hurt to discard their standard error. > contrib/completion/git-completion.bash | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > index b62bec0..0640274 100644 > --- a/contrib/completion/git-completion.bash > +++ b/contrib/completion/git-completion.bash > @@ -300,8 +300,8 @@ __git_index_file_list_filter () > __git_ls_files_helper () > { > # NOTE: $2 is not quoted in order to support multiple options > - cd "$1" && git ls-files --exclude-standard $2 > -} 2>/dev/null > + cd "$1" 2>/dev/null && git ls-files --exclude-standard $2 > +} > > > # Execute git diff-index, returning paths relative to the directory > @@ -309,8 +309,8 @@ __git_ls_files_helper () > # specified in the second argument. > __git_diff_index_helper () > { > - cd "$1" && git diff-index --name-only --relative "$2" > -} 2>/dev/null > + cd "$1" 2>/dev/null && git diff-index --name-only --relative "$2" > +} > > # __git_index_files accepts 1 or 2 arguments: > # 1: Options to pass to ls-files (required). ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 16:17 ` Junio C Hamano @ 2013-03-11 16:41 ` Junio C Hamano 2013-03-11 16:47 ` Matthieu Moy 2013-03-11 17:09 ` Manlio Perillo 1 sibling, 1 reply; 12+ messages in thread From: Junio C Hamano @ 2013-03-11 16:41 UTC (permalink / raw) To: Matthieu Moy; +Cc: git, Manlio Perillo Junio C Hamano <gitster@pobox•com> writes: > After all, I was right when I said that some implementations may get > it wrong and we shouldn't use the construct X-<. > >> These two instances seem to be the only ones in the file. >> >> I'm not sure whether the 2>/dev/null would be needed for the command >> on the RHS of the && too (git ls-files and git diff-index). > > It would not hurt to discard their standard error. So here is an updated based on your patch. -- >8 -- From: Matthieu Moy <Matthieu.Moy@imag•fr> Date: Mon, 11 Mar 2013 13:21:27 +0100 Subject: [PATCH] git-completion.bash: zsh does not implement function redirection correctly A recent change added functions whose entire standard error stream is redirected to /dev/null using a construct that is valid POSIX.1 but is not widely used: funcname () { funcbody } 2>/dev/null Even though this file is "git-completion.bash", zsh completion support dot-sources it (instead of asking bash to grok it like tcsh completion does), and zsh does not implement this redirection correctly. With zsh, trying to complete an inexistant directory gave this: git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ It is easy to work around by refraining from using this construct. The correct thing to do in the longer term may be to stop dot-sourcing the source meant for bash into zsh, but this patch should suffice as a band-aid in the meantime. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr> Signed-off-by: Junio C Hamano <gitster@pobox•com> --- contrib/completion/git-completion.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 51b8b3b..3d4cc7c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -300,8 +300,8 @@ __git_index_file_list_filter () __git_ls_files_helper () { # NOTE: $2 is not quoted in order to support multiple options - cd "$1" && git ls-files --exclude-standard $2 -} 2>/dev/null + cd "$1" 2>/dev/null && git ls-files --exclude-standard $2 2>/dev/null +} # Execute git diff-index, returning paths relative to the directory @@ -309,8 +309,8 @@ __git_ls_files_helper () # specified in the second argument. __git_diff_index_helper () { - cd "$1" && git diff-index --name-only --relative "$2" -} 2>/dev/null + cd "$1" 2>/dev/null && git diff-index --name-only --relative "$2" 2>/dev/null +} # __git_index_files accepts 1 or 2 arguments: # 1: Options to pass to ls-files (required). -- 1.8.2-rc3-271-g00e868e ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 16:41 ` Junio C Hamano @ 2013-03-11 16:47 ` Matthieu Moy 2013-03-11 17:01 ` Junio C Hamano 0 siblings, 1 reply; 12+ messages in thread From: Matthieu Moy @ 2013-03-11 16:47 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Manlio Perillo Junio C Hamano <gitster@pobox•com> writes: > So here is an updated based on your patch. Perfect, thanks. > The correct thing to do in the longer term may be to stop dot-sourcing > the source meant for bash into zsh, but this patch should suffice as > a band-aid in the meantime. I disagree with this particular part though. I think using the same code for bash and zsh makes sense, and it implies restricting to the common subset. I don't consider it "band-aid", but "nice code factoring" ;-). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 16:47 ` Matthieu Moy @ 2013-03-11 17:01 ` Junio C Hamano 2013-03-11 17:12 ` Manlio Perillo 0 siblings, 1 reply; 12+ messages in thread From: Junio C Hamano @ 2013-03-11 17:01 UTC (permalink / raw) To: Matthieu Moy; +Cc: git, Manlio Perillo Matthieu Moy <Matthieu.Moy@grenoble-inp•fr> writes: > Junio C Hamano <gitster@pobox•com> writes: > >> So here is an updated based on your patch. > > Perfect, thanks. > >> The correct thing to do in the longer term may be to stop dot-sourcing >> the source meant for bash into zsh, but this patch should suffice as >> a band-aid in the meantime. > > I disagree with this particular part though. I think using the same code > for bash and zsh makes sense, and it implies restricting to the common > subset. Having to restrict to the common subset means that whenever bash adds new and useful features that this script could take advantage of to improve the user experience, they cannot be employed until zsh catches up (and worse yet, it is outside the control of this script if zsh may ever catch up in the specific feature). ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 17:01 ` Junio C Hamano @ 2013-03-11 17:12 ` Manlio Perillo 0 siblings, 0 replies; 12+ messages in thread From: Manlio Perillo @ 2013-03-11 17:12 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 11/03/2013 18:01, Junio C Hamano ha scritto: > [...] > Having to restrict to the common subset means that whenever bash > adds new and useful features that this script could take advantage > of to improve the user experience, they cannot be employed until zsh > catches up (and worse yet, it is outside the control of this script > if zsh may ever catch up in the specific feature). > Maybe, to avoid this problem and code duplication (the main reason bash script is sourced, as far as I can tell), it may be useful to add additional reusable git commands, for use in shell completion? E.g: git suggest <cmd> *args returns a line separed list of filenames affected by cmd. Regards Manlio -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlE+EJkACgkQscQJ24LbaURjNwCfdW73fET/n4FRGftKcSJPsK7M nu4An1CC0dspGxLe5zqR9BdXBBDHWl/Y =11j7 -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 16:17 ` Junio C Hamano 2013-03-11 16:41 ` Junio C Hamano @ 2013-03-11 17:09 ` Manlio Perillo 2013-03-11 17:23 ` Junio C Hamano 1 sibling, 1 reply; 12+ messages in thread From: Manlio Perillo @ 2013-03-11 17:09 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 11/03/2013 17:17, Junio C Hamano ha scritto: > Matthieu Moy <Matthieu.Moy@imag•fr> writes: > >> The function-wide redirection used for __git_ls_files_helper and >> __git_diff_index_helper work only with bash. Using ZSH, trying to >> complete an inexistant directory gave this: >> >> git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ >> >> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr> >> --- > > This is not bash-ism but POSIX.1, even though it is not very well > known. I recall commenting on this exact pattern during the review. > Yes, I was plainning to send another patch to fix this (and your other suggestion regarding the CDPATH environment variable, if I remember correctly), but I was busy with other things; sorry. > [...] Regards Manlio -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlE+D7QACgkQscQJ24LbaURBTgCffpMCPjmcsP53/WE/VIQ2FIIc fiIAn3obBJ1yrHVUEmslz32ezvESCZ4G =7nia -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 17:09 ` Manlio Perillo @ 2013-03-11 17:23 ` Junio C Hamano 2013-03-11 17:48 ` Matthieu Moy 0 siblings, 1 reply; 12+ messages in thread From: Junio C Hamano @ 2013-03-11 17:23 UTC (permalink / raw) To: Manlio Perillo; +Cc: Matthieu Moy, git Manlio Perillo <manlio.perillo@gmail•com> writes: > Yes, I was plainning to send another patch to fix this (and your other > suggestion regarding the CDPATH environment variable, if I remember > correctly),... Ahh, thanks for reminding me of this. You are right; these two functions are broken when the user has CDPATH set, I think. Here is a reroll. -- >8 -- From: Matthieu Moy <Matthieu.Moy@imag•fr> Date: Mon, 11 Mar 2013 13:21:27 +0100 Subject: [PATCH] git-completion.bash: zsh does not implement function redirection correctly A recent change added functions whose entire standard error stream is redirected to /dev/null using a construct that is valid POSIX.1 but is not widely used: funcname () { cd "$1" && run some command "$2" } 2>/dev/null Even though this file is "git-completion.bash", zsh completion support dot-sources it (instead of asking bash to grok it like tcsh completion does), and zsh does not implement this redirection correctly. With zsh, trying to complete an inexistant directory gave this: git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ Also these functions use "cd" to first go somewhere else before running a command, but the location the caller wants them to go that is given as an argument to them should not be affected by CDPATH variable the users may have set for their interactive session. To fix both of these, wrap the body of the function in a subshell, unset CDPATH at the beginning of the subshell, and redirect the standard error stream of the subshell to /dev/null. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr> Signed-off-by: Junio C Hamano <gitster@pobox•com> --- contrib/completion/git-completion.bash | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 51b8b3b..430566d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -299,9 +299,12 @@ __git_index_file_list_filter () # the second argument. __git_ls_files_helper () { - # NOTE: $2 is not quoted in order to support multiple options - cd "$1" && git ls-files --exclude-standard $2 -} 2>/dev/null + ( + test -n "${CDPATH+set}" && unset CDPATH + # NOTE: $2 is not quoted in order to support multiple options + cd "$1" && git ls-files --exclude-standard $2 + ) 2>/dev/null +} # Execute git diff-index, returning paths relative to the directory @@ -309,8 +312,11 @@ __git_ls_files_helper () # specified in the second argument. __git_diff_index_helper () { - cd "$1" && git diff-index --name-only --relative "$2" -} 2>/dev/null + ( + test -n "${CDPATH+set}" && unset CDPATH + cd "$1" && git diff-index --name-only --relative "$2" + ) 2>/dev/null +} # __git_index_files accepts 1 or 2 arguments: # 1: Options to pass to ls-files (required). -- 1.8.2-rc3-219-ge56455f ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 17:23 ` Junio C Hamano @ 2013-03-11 17:48 ` Matthieu Moy 2013-03-11 18:09 ` Junio C Hamano 0 siblings, 1 reply; 12+ messages in thread From: Matthieu Moy @ 2013-03-11 17:48 UTC (permalink / raw) To: Junio C Hamano; +Cc: Manlio Perillo, git Junio C Hamano <gitster@pobox•com> writes: > Ahh, thanks for reminding me of this. You are right; these two > functions are broken when the user has CDPATH set, I think. > > Here is a reroll. Thanks. Even nicer that the previous since the CDPATH implied the subshell anyway. -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 17:48 ` Matthieu Moy @ 2013-03-11 18:09 ` Junio C Hamano 2013-03-11 18:19 ` Paul Smith 2013-03-11 19:09 ` Manlio Perillo 0 siblings, 2 replies; 12+ messages in thread From: Junio C Hamano @ 2013-03-11 18:09 UTC (permalink / raw) To: Matthieu Moy; +Cc: Manlio Perillo, git Matthieu Moy <Matthieu.Moy@grenoble-inp•fr> writes: > Junio C Hamano <gitster@pobox•com> writes: > >> Ahh, thanks for reminding me of this. You are right; these two >> functions are broken when the user has CDPATH set, I think. >> >> Here is a reroll. > > Thanks. Even nicer that the previous since the CDPATH implied the > subshell anyway. Actually, "cd", not CDPATH, is what implies that the caller must be calling us in a subshell, e.g. result=$(__git_ls_files_helper dir/ args...) Otherwise the user's shell would have been taken to an unexpected place, with or without CDPATH. So strictly speaking there is no reason for an extra subshell here, but writing this in the way the patch does makes our intention crystal clear, I think. In any case, let's queue this fix for the 1.8.2 final. The CDPATH thing will affect not just zsh but bash users. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 18:09 ` Junio C Hamano @ 2013-03-11 18:19 ` Paul Smith 2013-03-11 19:09 ` Manlio Perillo 1 sibling, 0 replies; 12+ messages in thread From: Paul Smith @ 2013-03-11 18:19 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, Manlio Perillo, git On Mon, 2013-03-11 at 11:09 -0700, Junio C Hamano wrote: > So strictly speaking there is no reason for an extra subshell here, > but writing this in the way the patch does makes our intention > crystal clear, I think. If you're concerned about the extra processing of the new shell you can use {} instead of (): { test -n "${CDPATH+set}" && unset CDPATH # NOTE: $2 is not quoted in order to support multiple options cd "$1" && git ls-files --exclude-standard $2 } 2>/dev/null Zsh does support this properly in my testing. It's only redirection of an entire function body, as the original, that is working differently in zsh and bash. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility 2013-03-11 18:09 ` Junio C Hamano 2013-03-11 18:19 ` Paul Smith @ 2013-03-11 19:09 ` Manlio Perillo 1 sibling, 0 replies; 12+ messages in thread From: Manlio Perillo @ 2013-03-11 19:09 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 11/03/2013 19:09, Junio C Hamano ha scritto: > Matthieu Moy <Matthieu.Moy@grenoble-inp•fr> writes: > >> Junio C Hamano <gitster@pobox•com> writes: >> >>> Ahh, thanks for reminding me of this. You are right; these two >>> functions are broken when the user has CDPATH set, I think. >>> >>> Here is a reroll. >> >> Thanks. Even nicer that the previous since the CDPATH implied the >> subshell anyway. > > Actually, "cd", not CDPATH, is what implies that the caller must be > calling us in a subshell, e.g. > > result=$(__git_ls_files_helper dir/ args...) > > Otherwise the user's shell would have been taken to an unexpected > place, with or without CDPATH. > Right; this is the reason I used the `{` grouping, instead of `(`. However, since the `{` is already specified when the function is defined, I did not add another `{}` grouping. > [...] Regards Manlio Perillo -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlE+K/4ACgkQscQJ24LbaUQqvwCgmReHb4VtMJDT+tv+XF9RPmXE DlEAnjhsgXszSBVG1iW0WCLM6212+fdA =SYzh -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-03-11 19:10 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-03-11 12:21 [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility Matthieu Moy 2013-03-11 16:17 ` Junio C Hamano 2013-03-11 16:41 ` Junio C Hamano 2013-03-11 16:47 ` Matthieu Moy 2013-03-11 17:01 ` Junio C Hamano 2013-03-11 17:12 ` Manlio Perillo 2013-03-11 17:09 ` Manlio Perillo 2013-03-11 17:23 ` Junio C Hamano 2013-03-11 17:48 ` Matthieu Moy 2013-03-11 18:09 ` Junio C Hamano 2013-03-11 18:19 ` Paul Smith 2013-03-11 19:09 ` Manlio Perillo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox