sh-setup: enclose setting of ${VAR=default} in double-quotes

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>

LE Manh Cuong committed Jun 19, 2016 at 03:26 UTC 01247e0299b34b9b46d96d5850a24583e39deabe
1 file changed +3 -3
git-sh-setup.sh
+3 -3
@@ -160,8 +160,8 @@ git_pager() {
160 else
161 GIT_PAGER=cat
162 fi
163 - : ${LESS=-FRX}
164 - : ${LV=-c}
163 + : "${LESS=-FRX}"
164 + : "${LV=-c}"
165 export LESS LV
166
167 eval "$GIT_PAGER" '"$@"'
@@ -344,7 +344,7 @@ git_dir_init () {
344 echo >&2 "Unable to determine absolute path of git directory"
345 exit 1
346 }
347 - : ${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}
347 + : "${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}"
348 }
349
350 if test -z "$NONGIT_OK"