sh-setup: enclose setting of ${VAR=default} in double-quotes
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Sat, 18 Jun 2016 20:26:03 +0000 (03:26 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 Jun 2016 21:07:04 +0000 (14:07 -0700)
We often make sure an environment variable is set to
something, either set by the user (in which case we do not
molest it) or set it to our default value (otherwise), with

: ${VAR=default value}

i.e. running the no-op command ":" with ${VAR} as its
parameters (or the default value we supply), relying on that
":" is a no-op.

This pattern, even though it is no-op from correctness point
of view, still can be expensive if the existing value in VAR
has shell glob (because they will be expanded against
filesystem entities) and IFS whitespaces (because the value
need to be split into multiple parameters). Our invocation
of ":" command does not care if the parameter given to it is
after the value in VAR goes through these processing.

Enclosing the whole thing in double-quote, i.e.

: "${VAR=default value}"

avoids paying the unnecessary cost, so let's do so.

Signed-off-by: LE Manh Cuong <cuong.manhle.vn@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-sh-setup.sh
index 4691fbcb64fe7ecbc58930bb96d4e6b28e2b87a7..c918ed779b8436976ee6c0a2a7489fc5d4ecc20f 100644 (file)
@@ -160,8 +160,8 @@ git_pager() {
        else
                GIT_PAGER=cat
        fi
-       : ${LESS=-FRX}
-       : ${LV=-c}
+       : "${LESS=-FRX}"
+       : "${LV=-c}"
        export LESS LV
 
        eval "$GIT_PAGER" '"$@"'
@@ -344,7 +344,7 @@ git_dir_init () {
                echo >&2 "Unable to determine absolute path of git directory"
                exit 1
        }
-       : ${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}
+       : "${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}"
 }
 
 if test -z "$NONGIT_OK"