Thanks for all the helpful feedback. Here's a new series that drops the $(()) and test -a/-o patches, and otherwise hopefully incorporates all nits.
Cheers, Ralf
threads / patch / 10742
Subject: [PATCH 0/3] some shell portability fixes, v2
Thanks for all the helpful feedback. Here's a new series that drops the $(()) and test -a/-o patches, and otherwise hopefully incorporates all nits.
Cheers, Ralf
[PATCH 1/3] Avoid a few unportable, needlessly nested "...`...".
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de> --- git-rebase--interactive.sh | 2 +- git-request-pull.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
git-rebase--interactive.sh, git-request-pull.sh
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 6d14092..66c80d4 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -392,7 +392,7 @@ do -s|--strategy) case "$#,$1" in *,*=*) - STRATEGY="-s `expr "z$1" : 'z-[^=]*=\(.*\)'`" ;; + STRATEGY="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) usage ;; *) diff --git a/git-request-pull.sh b/git-request-pull.sh index 90d969c..068f5e0 100755 --- a/git-request-pull.sh +++ b/git-request-pull.sh @@ -25,13 +25,13 @@ headrev=`git rev-parse --verify "$head"^0` || exit merge_base=`git merge-base $baserev $headrev` || die "fatal: No commits in common between $base and $head" -url="`get_remote_url "$url"`" -branch=`git peek-remote "$url" \ +url=$(get_remote_url "$url") +branch=$(git peek-remote "$url" \ | sed -n -e "/^$headrev refs.heads./{ s/^.* refs.heads.// p q - }"` + }") if [ -z "$branch" ]; then echo "warn: No branch of $url is at:" >&2 git log --max-count=1 --pretty='format:warn: %h: %s' $headrev >&2
-- 1.5.3.5.561.g140d
[PATCH 2/3] Fix sed script to work with AIX and BSD sed.
\n is not portable in a s/// replacement string, only in the regex part. backslash-newline helps.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de> --- I'm a bit unsure whether you would prefer to avoid breaking the indentation with something like tr '|' '\n'
OTOH, \n in a tr set is not universally portable either (for example Solaris /usr/ucb/tr mishandles it, and \012 fails on EBCDIC), but I'm still on my way of finding out the level of portability you prefer. ;-)
Cheers, Ralf
git-bisect.sh | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/git-bisect.sh b/git-bisect.sh index c18bd32..3aac816 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -276,7 +276,8 @@ exit_if_skipped_commits () { if expr "$_tried" : ".*[|].*" > /dev/null ; then echo "There are only 'skip'ped commit left to test." echo "The first bad commit could be any of:" - echo "$_tried" | sed -e 's/[|]/\n/g' + echo "$_tried" | sed -e 's/[|]/\ +/g' echo "We cannot bisect more!" exit 2 fi
-- 1.5.3.5.561.g140d
Re: [PATCH 2/3] Fix sed script to work with AIX and BSD sed.
On Nov 8, 2007, at 10:48 PM, Ralf Wildenhues wrote:
> diff --git a/git-bisect.sh b/git-bisect.sh
> index c18bd32..3aac816 100755
> --- a/git-bisect.sh
> +++ b/git-bisect.sh
> @@ -276,7 +276,8 @@ exit_if_skipped_commits () {
> if expr "$_tried" : ".*[|].*" > /dev/null ; then
> echo "There are only 'skip'ped commit left to test."
> echo "The first bad commit could be any of:"
> - echo "$_tried" | sed -e 's/[|]/\n/g'
> + echo "$_tried" | sed -e 's/[|]/\Just out of curiosity, is there any valid reason to use `[' and `]' in this RE? By default sed does not use extended RE (at least none of the implementation I know of) so why not just use sed 's/|/...' ?
> +/g' > echo "We cannot bisect more!" > exit 2 > fi
-- Benoit Sigoure aka Tsuna EPITA Research and Development Laboratory
[PATCH 3/3] Fix sed string regex escaping in module_name.
When escaping a string to be used as a sed regex, it is important to only escape active characters. Escaping other characters is undefined according to POSIX, and in practice leads to issues with extensions such as GNU sed's \+.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de> --- git-submodule.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh index 1c656be..82ac28f 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -74,7 +74,7 @@ resolve_relative_url () module_name() { # Do we have "submodule.<something>.path = $1" defined in .gitmodules file? - re=$(printf '%s' "$1" | sed -e 's/\([^a-zA-Z0-9_]\)/\\\1/g') + re=$(printf '%s' "$1" | sed -e 's/[].[^$\\*]/\\&/g') name=$( GIT_CONFIG=.gitmodules \ git config --get-regexp '^submodule\..*\.path$' | sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
-- 1.5.3.5.561.g140d