threads / patch / 28767

patchcompletion: fix issue with process substitution not working on Git for Windows

Subject: [PATCH] completion: fix issue with process substitution not working on Git for Windows

## tl;dr

10 messages between Oct 25, 2011 and Oct 27, 2011. Diffs are folded; open one to read it.

replies: 9people: 6as markdown or json

Stefan Naewe· Oct 25, 2011, 18:01 UTC · lore

Git for Windows comes with a bash that doesn't support process substitution. It issues the following error when using git-completion.bash with GIT_PS1_SHOWUPSTREAM set:

$ export GIT_PS1_SHOWUPSTREAM=1 sh.exe": cannot make pipe for process substitution: Function not implemented sh.exe": cannot make pipe for process substitution: Function not implemented sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect

Replace the process substitution with a simple "echo $var | while...".
Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
---
 contrib/completion/git-completion.bash |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +3 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8648a36..926db80 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -110,6 +110,8 @@ __git_ps1_show_upstream ()
 	local upstream=git legacy="" verbose=""
 
 	# get some config options from git-config
+	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
+	echo "$output" | \
 	while read key value; do
 		case "$key" in
 		bash.showupstream)
@@ -125,7 +127,7 @@ __git_ps1_show_upstream ()
 			upstream=svn+git # default upstream is SVN if available, else git
 			;;
 		esac
-	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
+	done
 
 	# parse configuration values
 	for option in ${GIT_PS1_SHOWUPSTREAM}; do
-- 
1.7.7.1
Johannes Sixt· Oct 25, 2011, 20:39 UTC · re: Stefan Naewe · lore

Re: [PATCH] completion: fix issue with process substitution not working on Git for Windows

Am 25.10.2011 20:01, schrieb Stefan Naewe:
Show 38 quoted lines
> Git for Windows comes with a bash that doesn't support process substitution.
> It issues the following error when using git-completion.bash with
> GIT_PS1_SHOWUPSTREAM set:
> 
> $ export GIT_PS1_SHOWUPSTREAM=1
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
> 
> Replace the process substitution with a simple "echo $var | while...".
> 
> Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
> ---
>  contrib/completion/git-completion.bash |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 8648a36..926db80 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -110,6 +110,8 @@ __git_ps1_show_upstream ()
>  	local upstream=git legacy="" verbose=""
>  
>  	# get some config options from git-config
> +	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
> +	echo "$output" | \
>  	while read key value; do
>  		case "$key" in
>  		bash.showupstream)
> @@ -125,7 +127,7 @@ __git_ps1_show_upstream ()
>  			upstream=svn+git # default upstream is SVN if available, else git
>  			;;
>  		esac
> -	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
> +	done
>  
>  	# parse configuration values
>  	for option in ${GIT_PS1_SHOWUPSTREAM}; do

Are you sure that the result still works as intended? The while loop sets a few variables. When you place it in a pipe, the loop runs in a subshell, and subsequent code will not see the modified values. Unless bash knows how to optimize away the subshell, that is.

OTOH, when you use while ...; do ...; done < <(...), the while loop is not in a subshell.

An alternative is to use:  while ...; do ...; done <<< "$output"

BTW, you don't need to protect the end-of-line with a backslash if the line ends with the pipe symbol.

-- Hannes
Stefan Näwe· Oct 26, 2011, 06:52 UTC · re: Johannes Sixt · lore

Re: [PATCH] completion: fix issue with process substitution not working on Git for Windows

Am 25. Oktober 2011 22:39 schrieb Johannes Sixt <j6t@kdbg.org>:
Show 44 quoted lines
> Am 25.10.2011 20:01, schrieb Stefan Naewe:
>> Git for Windows comes with a bash that doesn't support process substitution.
>> It issues the following error when using git-completion.bash with
>> GIT_PS1_SHOWUPSTREAM set:
>>
>> $ export GIT_PS1_SHOWUPSTREAM=1
>> sh.exe": cannot make pipe for process substitution: Function not implemented
>> sh.exe": cannot make pipe for process substitution: Function not implemented
>> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
>>
>> Replace the process substitution with a simple "echo $var | while...".
>>
>> Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
>> ---
>>  contrib/completion/git-completion.bash |    4 +++-
>>  1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index 8648a36..926db80 100755
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -110,6 +110,8 @@ __git_ps1_show_upstream ()
>>       local upstream=git legacy="" verbose=""
>>
>>       # get some config options from git-config
>> +     output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
>> +     echo "$output" | \
>>       while read key value; do
>>               case "$key" in
>>               bash.showupstream)
>> @@ -125,7 +127,7 @@ __git_ps1_show_upstream ()
>>                       upstream=svn+git # default upstream is SVN if available, else git
>>                       ;;
>>               esac
>> -     done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
>> +     done
>>
>>       # parse configuration values
>>       for option in ${GIT_PS1_SHOWUPSTREAM}; do
>
> Are you sure that the result still works as intended? The while loop
> sets a few variables. When you place it in a pipe, the loop runs in a
> subshell, and subsequent code will not see the modified values. Unless
> bash knows how to optimize away the subshell, that is.
I doesn't work in the 'git svn' case, I guess.
> OTOH, when you use while ...; do ...; done < <(...), the while loop is
> not in a subshell.
>
> An alternative is to use:  while ...; do ...; done <<< "$output"
I'll try that.
> BTW, you don't need to protect the end-of-line with a backslash if the
> line ends with the pipe symbol.
OK. Will do.
> -- Hannes
Thanks,
  Stefan
-- 
----------------------------------------------------------------
python -c "print '73746566616e2e6e6165776540676d61696c2e636f6d'.decode('hex')"
Stefan Naewe· Oct 26, 2011, 19:13 UTC · re: Stefan Näwe · lore

[PATCH v2] completion: fix issue with process substitution not working on Git for Windows

Git for Windows comes with a bash that doesn't support process substitution. It issues the following error when using git-completion.bash with GIT_PS1_SHOWUPSTREAM set:

$ export GIT_PS1_SHOWUPSTREAM=1 sh.exe": cannot make pipe for process substitution: Function not implemented sh.exe": cannot make pipe for process substitution: Function not implemented sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect

Replace the process substitution with a 'here string'.
Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
---
 contrib/completion/git-completion.bash |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +2 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8648a36..0b3d47e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -110,6 +110,7 @@ __git_ps1_show_upstream ()
 	local upstream=git legacy="" verbose=""
 
 	# get some config options from git-config
+	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
 	while read key value; do
 		case "$key" in
 		bash.showupstream)
@@ -125,7 +126,7 @@ __git_ps1_show_upstream ()
 			upstream=svn+git # default upstream is SVN if available, else git
 			;;
 		esac
-	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
+	done <<< "$output"
 
 	# parse configuration values
 	for option in ${GIT_PS1_SHOWUPSTREAM}; do
-- 
1.7.7.1
Junio C Hamano· Oct 26, 2011, 20:02 UTC · re: Stefan Naewe · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

Stefan Naewe <stefan.naewe@gmail.com> writes:
Show 12 quoted lines
> Git for Windows comes with a bash that doesn't support process substitution.
> It issues the following error when using git-completion.bash with
> GIT_PS1_SHOWUPSTREAM set:
>
> $ export GIT_PS1_SHOWUPSTREAM=1
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
>
> Replace the process substitution with a 'here string'.
>
> Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>

Yuck, but I honestly shouldn't care about the yuckiness as this script is inherently intimately dependent on bash anyway ;-).

Show 24 quoted lines
>  contrib/completion/git-completion.bash |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 8648a36..0b3d47e 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -110,6 +110,7 @@ __git_ps1_show_upstream ()
>  	local upstream=git legacy="" verbose=""
>  
>  	# get some config options from git-config
> +	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
>  	while read key value; do
>  		case "$key" in
>  		bash.showupstream)
> @@ -125,7 +126,7 @@ __git_ps1_show_upstream ()
>  			upstream=svn+git # default upstream is SVN if available, else git
>  			;;
>  		esac
> -	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
> +	done <<< "$output"
>  
>  	# parse configuration values
>  	for option in ${GIT_PS1_SHOWUPSTREAM}; do
Junio C Hamano· Oct 26, 2011, 21:07 UTC · re: Stefan Naewe · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

Stefan Naewe <stefan.naewe@gmail.com> writes:
> $ export GIT_PS1_SHOWUPSTREAM=1
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect

Are these the exact strings you want to have in the commit log message? I am particularly wondering about the dq after (but not around) 'sh.exe'.

Stefan Näwe· Oct 27, 2011, 06:26 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

Am 26. Oktober 2011 23:07 schrieb Junio C Hamano <gitster@pobox.com>:
Show 9 quoted lines
> Stefan Naewe <stefan.naewe@gmail.com> writes:
>
>> $ export GIT_PS1_SHOWUPSTREAM=1
>> sh.exe": cannot make pipe for process substitution: Function not implemented
>> sh.exe": cannot make pipe for process substitution: Function not implemented
>> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
>
> Are these the exact strings you want to have in the commit log message? I
> am particularly wondering about the dq after (but not around) 'sh.exe'.
Yes. That's exactly what I get.
Stefan
-- 
----------------------------------------------------------------
python -c "print '73746566616e2e6e6165776540676d61696c2e636f6d'.decode('hex')"
SZEDER Gábor· Oct 27, 2011, 09:05 UTC · re: Stefan Naewe · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

On Wed, Oct 26, 2011 at 09:13:09PM +0200, Stefan Naewe wrote:
Show 34 quoted lines
> Git for Windows comes with a bash that doesn't support process substitution.
> It issues the following error when using git-completion.bash with
> GIT_PS1_SHOWUPSTREAM set:
> 
> $ export GIT_PS1_SHOWUPSTREAM=1
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": cannot make pipe for process substitution: Function not implemented
> sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
> 
> Replace the process substitution with a 'here string'.
> 
> Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
> ---
>  contrib/completion/git-completion.bash |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 8648a36..0b3d47e 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -110,6 +110,7 @@ __git_ps1_show_upstream ()
>  	local upstream=git legacy="" verbose=""
>  
>  	# get some config options from git-config
> +	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
>  	while read key value; do
>  		case "$key" in
>  		bash.showupstream)
> @@ -125,7 +126,7 @@ __git_ps1_show_upstream ()
>  			upstream=svn+git # default upstream is SVN if available, else git
>  			;;
>  		esac
> -	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
> +	done <<< "$output"

The $output variable is not declared as local and therefore it leaks into the environment. But instead of declaring it local, why not eliminate it altogether, and use the "$(git config ....)" command substitution as here string?

Gábor
Jonas Berlin· Oct 27, 2011, 10:27 UTC · re: SZEDER Gábor · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

On Thu, 27 Oct 2011 11:05:30 +0200 SZEDER Gábor <szeder@ira.uka.de> wrote:

Show 40 quoted lines
> On Wed, Oct 26, 2011 at 09:13:09PM +0200, Stefan Naewe wrote:
> > Git for Windows comes with a bash that doesn't support process substitution.
> > It issues the following error when using git-completion.bash with
> > GIT_PS1_SHOWUPSTREAM set:
> > 
> > $ export GIT_PS1_SHOWUPSTREAM=1
> > sh.exe": cannot make pipe for process substitution: Function not implemented
> > sh.exe": cannot make pipe for process substitution: Function not implemented
> > sh.exe": <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n '): ambiguous redirect
> > 
> > Replace the process substitution with a 'here string'.
> > 
> > Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
> > ---
> >  contrib/completion/git-completion.bash |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index 8648a36..0b3d47e 100755
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -110,6 +110,7 @@ __git_ps1_show_upstream ()
> >  	local upstream=git legacy="" verbose=""
> >  
> >  	# get some config options from git-config
> > +	output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
> >  	while read key value; do
> >  		case "$key" in
> >  		bash.showupstream)
> > @@ -125,7 +126,7 @@ __git_ps1_show_upstream ()
> >  			upstream=svn+git # default upstream is SVN if available, else git
> >  			;;
> >  		esac
> > -	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
> > +	done <<< "$output"
> 
> The $output variable is not declared as local and therefore it leaks
> into the environment.  But instead of declaring it local, why not
> eliminate it altogether, and use the "$(git config ....)" command
> substitution as here string?
Wouldn't this work:
	git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ' | \
	while read key value; do
		...
	done
- xkr47
Jonas Berlin· Oct 27, 2011, 10:40 UTC · re: Jonas Berlin · lore

Re: [PATCH v2] completion: fix issue with process substitution not working on Git for Windows

On Thu, 27 Oct 2011 13:27:54 +0300 Jonas Berlin <xkr47@outerspace.dyndns.org> wrote:

Show 13 quoted lines
> On Thu, 27 Oct 2011 11:05:30 +0200
> SZEDER Gábor <szeder@ira.uka.de> wrote:
> > The $output variable is not declared as local and therefore it leaks
> > into the environment.  But instead of declaring it local, why not
> > eliminate it altogether, and use the "$(git config ....)" command
> > substitution as here string?
> 
> Wouldn't this work:
> 
> 	git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ' | \
> 	while read key value; do
> 		...
> 	done
Sorry, please disregard, I didn't notice it was already dismissed in v1 of the PATCH..
- xkr47

← back to recent threads