public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] contrib: Avoid use of "echo -n" in git customization [PR102664]
@ 2022-03-09 12:15 Richard Earnshaw
  2022-03-09 15:05 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Earnshaw @ 2022-03-09 12:15 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

The -n option to echo is non-portable.  The generally recommended
alternative is to use the shell printf command.

contrib/ChangeLog:

	PR other/102664
	* gcc-git-customization.sh (ask): Use printf instead of echo -n.

[-- Attachment #2: echo-no-n.patch --]
[-- Type: text/x-patch, Size: 405 bytes --]

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index b24948d9874..cf46c494a6a 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -7,7 +7,7 @@ ask () {
     question=$1
     default=$2
     var=$3
-    echo -n $question "["$default"]? "
+    printf "%s" "$question [$default]? "
     read answer
     if [ "x$answer" = "x" ]
     then

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] contrib: Avoid use of "echo -n" in git customization [PR102664]
  2022-03-09 12:15 [PATCH] contrib: Avoid use of "echo -n" in git customization [PR102664] Richard Earnshaw
@ 2022-03-09 15:05 ` Jonathan Wakely
  2022-03-10 11:43   ` Richard Earnshaw
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2022-03-09 15:05 UTC (permalink / raw)
  To: Richard Earnshaw; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1203 bytes --]

On 09/03/22 12:15 +0000, Richard Earnshaw wrote:
>The -n option to echo is non-portable.  The generally recommended
>alternative is to use the shell printf command.
>
>contrib/ChangeLog:
>
>	PR other/102664
>	* gcc-git-customization.sh (ask): Use printf instead of echo -n.
>
>diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
>index b24948d9874..cf46c494a6a 100755
>--- a/contrib/gcc-git-customization.sh
>+++ b/contrib/gcc-git-customization.sh
>@@ -7,7 +7,7 @@ ask () {
>     question=$1
>     default=$2
>     var=$3
>-    echo -n $question "["$default"]? "
>+    printf "%s" "$question [$default]? "
>     read answer
>     if [ "x$answer" = "x" ]
>     then

This isn't enough to get the script working on AIX and Solaris. The
attached patch has been tested on Fedora Linux, NetBSD 9.2, AIX 7 and
Solaris 11.

The part checking the result of `git rev-parse --git-path hooks` was
needed to work around Git 2.4.0 on gcc211 in the compile farm, which
is a Solaris 11 sparc box. That's a truly ancient version, but
handling the error (and just skipping installation of the hook) isn't
difficult, so seems worthwhile. I can revert that part if preferred.

OK for trunk?



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3169 bytes --]

commit 1f23f091a8d6e3e337fd4647fec8afa8d2d8bd46
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 9 14:53:52 2022

    contrib: Fix non-portable shell commands in gcc-git-customization.sh [PR102664]
    
    Use printf instead of echo -n. Use Basic Regular Expressions instead of
    sed -r. Check for error from ancient Git versions that don't support the
    --git-path option for git-rev-parse. Remove -c flag from install
    command, as it's ignored by GNU and BSD install, but means something
    different for Solaris and AIX.
    
    contrib/ChangeLog:
    
            PR other/102664
            * gcc-git-customization.sh: Fix non-portable commands.

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index b24948d9874..914d868f7bd 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -7,7 +7,7 @@ ask () {
     question=$1
     default=$2
     var=$3
-    echo -n $question "["$default"]? "
+    printf "%s [%s]? " "$question" "$default"
     read answer
     if [ "x$answer" = "x" ]
     then
@@ -110,7 +110,7 @@ then
 	# This is a pure guess, but for many people it might be OK.
 	remote_id=$(whoami)
     else
-	remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
+	remote_id=$(echo $url | sed 's|^.*ssh://\(..*\)@gcc.gnu.org.*$|\1|')
 	if [ x$remote_id = x$url ]
 	then
 	    remote_id=$(whoami)
@@ -118,7 +118,7 @@ then
     fi
 fi
 
-ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
+ask "Account name on gcc.gnu.org (for your personal branches area)" "$remote_id" remote_id
 git config "gcc-config.user" "$remote_id"
 
 old_pfx=$(git config --get "gcc-config.userpfx")
@@ -135,16 +135,20 @@ git config "gcc-config.userpfx" "$new_pfx"
 echo
 ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook
 if [ "x$dohook" = xyes ]; then
-    hookdir=`git rev-parse --git-path hooks`
-    if [ -f "$hookdir/prepare-commit-msg" ]; then
-	echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak"
-	mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak"
+    hookdir=`git rev-parse --git-path hooks 2>/dev/null`
+    if [ $? -eq 0 ]; then
+	if [ -f "$hookdir/prepare-commit-msg" ]; then
+	    echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak"
+	    mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak"
+	fi
+	install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
+    else
+	echo " `git --version` is too old, cannot find hooks dir"
     fi
-    install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
 fi
 
 # Scan the existing settings to see if there are any we need to rewrite.
-vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed -r "s:.*refs/vendors/([^/]+)/.*:\1:" | sort | uniq)
+vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed 's:.*refs/vendors/\([^/][^/]*\)/.*:\1:' | sort | uniq)
 url=$(git config --get "remote.${upstream}.url")
 pushurl=$(git config --get "remote.${upstream}.pushurl")
 for v in $vendors

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] contrib: Avoid use of "echo -n" in git customization [PR102664]
  2022-03-09 15:05 ` Jonathan Wakely
@ 2022-03-10 11:43   ` Richard Earnshaw
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Earnshaw @ 2022-03-10 11:43 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches



On 09/03/2022 15:05, Jonathan Wakely via Gcc-patches wrote:
> On 09/03/22 12:15 +0000, Richard Earnshaw wrote:
>> The -n option to echo is non-portable.  The generally recommended
>> alternative is to use the shell printf command.
>>
>> contrib/ChangeLog:
>>
>>     PR other/102664
>>     * gcc-git-customization.sh (ask): Use printf instead of echo -n.
>>
>> diff --git a/contrib/gcc-git-customization.sh 
>> b/contrib/gcc-git-customization.sh
>> index b24948d9874..cf46c494a6a 100755
>> --- a/contrib/gcc-git-customization.sh
>> +++ b/contrib/gcc-git-customization.sh
>> @@ -7,7 +7,7 @@ ask () {
>>     question=$1
>>     default=$2
>>     var=$3
>> -    echo -n $question "["$default"]? "
>> +    printf "%s" "$question [$default]? "
>>     read answer
>>     if [ "x$answer" = "x" ]
>>     then
> 
> This isn't enough to get the script working on AIX and Solaris. The
> attached patch has been tested on Fedora Linux, NetBSD 9.2, AIX 7 and
> Solaris 11.
> 
> The part checking the result of `git rev-parse --git-path hooks` was
> needed to work around Git 2.4.0 on gcc211 in the compile farm, which
> is a Solaris 11 sparc box. That's a truly ancient version, but
> handling the error (and just skipping installation of the hook) isn't
> difficult, so seems worthwhile. I can revert that part if preferred.
> 
> OK for trunk?
> 
> 

OK.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-10 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 12:15 [PATCH] contrib: Avoid use of "echo -n" in git customization [PR102664] Richard Earnshaw
2022-03-09 15:05 ` Jonathan Wakely
2022-03-10 11:43   ` Richard Earnshaw

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).