From a21fbb20765c0a1d89b8b398b279404b2927c294 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 23 Apr 2015 19:51:18 -0700 Subject: [PATCH] sed/grep: stop using [:space:] POSIX requires support for [[:space:]] to match any space character even in sed expressions. However, some broken systems do not support that. Instead define a `$tab` variable in shlib.sh that contains a single tab and then use [ $tab] inside "" instead. Signed-off-by: Kyle J. McKay --- jobd/gc.sh | 2 +- shlib.sh | 4 +++- taskd/clone.sh | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/jobd/gc.sh b/jobd/gc.sh index d704bea..caffccb 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -440,7 +440,7 @@ if [ ! -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then if [ -n "$pkfound" -a -n "$pkhead" ]; then { echo "# v2 git bundle" - sed -ne "/^$octet20 refs\/[^ ]*\$/ p" < packed-refs + sed -ne "/^$octet20 refs\/[^ $tab]*\$/ p" < packed-refs echo "$pkhead HEAD" echo "" } > "$pkbase.bndl" diff --git a/shlib.sh b/shlib.sh index 560e1e8..0535cc1 100644 --- a/shlib.sh +++ b/shlib.sh @@ -8,6 +8,8 @@ octet='[0-9a-f][0-9a-f]' octet4="$octet$octet$octet$octet" octet19="$octet4$octet4$octet4$octet4$octet$octet$octet" octet20="$octet4$octet4$octet4$octet4$octet4" +# tab +tab="$(printf '\t')" vcmp() { # Compare $1 to $2 each of which must match \d+(\.\d+)* @@ -316,7 +318,7 @@ is_git_dir() { $octet20) return 0;; ref:*) - _hr="${_hr##ref:*[[:space:]]}" + _hr="${_hr##ref:*[ $tab]}" case "$_hr" in "refs/"?*) return 0;; esac esac return 1 diff --git a/taskd/clone.sh b/taskd/clone.sh index 3a9c640..952bfe0 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -277,7 +277,7 @@ case "$url" in if [ -s .refs-temp ]; then # Nothing to do unless the remote repository has at least 1 ref # See if we got a HEAD ref - head="$(grep -E "^$octet20[[:space:]]+HEAD\$" <.refs-temp | awk '{print $1}')" + head="$(grep -E "^$octet20[ $tab]+HEAD\$" <.refs-temp | awk '{print $1}')" # If the remote has HEAD set to a symbolic ref that does not exist # then we will not receive a HEAD ref in the ls-remote output headref= @@ -285,8 +285,8 @@ case "$url" in symrefcap= if [ -n "$head" ]; then symrefcap="$(sed -ne <.pkts-temp \ - '/packet:.*git<.*[[:space:]]symref=HEAD:refs\/heads\/[^[:space:]][^[:space:]]*/'"\ - "'{s/^.*[[:space:]]symref=HEAD:\(refs\/heads\/[^[:space:]][^[:space:]]*\).*$/\1/;p;}')" + "/packet:.*git<.*[ $tab]symref="'HEAD:refs\/heads\/'"[^ $tab]/\ + {s/^.*[ $tab]symref="'HEAD:\(refs\/heads\/'"[^ $tab][^ $tab]*"'\).*$/\1/;p;}')" # prefer $symrefcap (refs/heads/master if no $symrefcap) if it # matches HEAD otherwise take the first refs/heads/... match matchcnt=0 @@ -298,7 +298,7 @@ case "$url" in fi [ "$headref" = "${symrefcap:-refs/heads/master}" -a $matchcnt -gt 1 ] && break done <<-EOT - $(grep -E "^$head[[:space:]]+refs/heads/[^[:space:]]+\$" <.refs-temp | \ + $(grep -E "^$head[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \ awk '{print $2}') EOT # Warn if there was more than one match and $symrefcap is empty @@ -323,7 +323,7 @@ case "$url" in fi [ "$headref" = "refs/heads/master" ] && break done <<-EOT - $(grep -E "^$octet20[[:space:]]+refs/heads/[^[:space:]]+\$" <.refs-temp | \ + $(grep -E "^$octet20[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \ awk '{print $2}') EOT fi -- 2.11.4.GIT