login
Header Space

 
 

[PATCH 4/4] filter-branch: fix variable export logic

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <gitster@...>
Cc: <git@...>
Date: Tuesday, May 13, 2008 - 4:46 am

filter-branch tries to restore "old" copies of some
environment variables by using the construct:

  unset var
  test -z "$old_var" || var="$old_var" && export var

However, by the short-circuit logic, we will always run
'export var'. On bash and dash, exporting an unset variable
has no effect. However, on some shells (such as FreeBSD's
/bin/sh), the shell exports the empty value.

This manifested itself in this case as git-filter-branch
setting GIT_INDEX_FILE to the empty string, which in turn
caused its call to git-read-tree to fail, leaving the
working tree pointing at the original HEAD instead of the
rewritten one.

To fix this, we change the short-circuit logic to better
match the intent:

  test -z "$old_var" || { var="$old_var" && export var; }

Signed-off-by: Jeff King <peff@peff.net>
---
 git-filter-branch.sh |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 333f6a8..0304dc5 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -435,11 +435,11 @@ rm -rf "$tempdir"
 trap - 0
 
 unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
-test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
-test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
-	export GIT_WORK_TREE
-test -z "$ORIG_GIT_INDEX_FILE" || GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
-	export GIT_INDEX_FILE
+test -z "$ORIG_GIT_DIR" || { GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR; }
+test -z "$ORIG_GIT_WORK_TREE" || { GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
+	export GIT_WORK_TREE; }
+test -z "$ORIG_GIT_INDEX_FILE" || { GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
+	export GIT_INDEX_FILE; }
 git read-tree -u -m HEAD
 
 exit $ret
-- 
1.5.5.1.296.gf618c
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/4] freebsd portability fixes, Jeff King, (Tue May 13, 4:43 am)
Re: [PATCH 0/4] freebsd portability fixes, Jeff King, (Tue May 13, 5:04 am)
Re: [PATCH 0/4] freebsd portability fixes, Alex Riesen, (Tue May 13, 4:39 pm)
Re: [PATCH 0/4] freebsd portability fixes, Alex Riesen, (Tue May 13, 4:44 pm)
[PATCH 4/4] filter-branch: fix variable export logic, Jeff King, (Tue May 13, 4:46 am)
Re: [PATCH 4/4] filter-branch: fix variable export logic, Junio C Hamano, (Wed May 14, 12:18 am)
Re: [PATCH 4/4] filter-branch: fix variable export logic, Paolo Bonzini, (Wed May 14, 5:33 am)
[PATCH 3/4] clone: bsd shell portability fix, Jeff King, (Tue May 13, 4:45 am)
[PATCH 2/4] t5000: tar portability fix, Jeff King, (Tue May 13, 4:45 am)
[PATCH 1/4] fix bsd shell negation, Jeff King, (Tue May 13, 4:44 am)
Re: [PATCH 1/4] fix bsd shell negation, Junio C Hamano, (Tue May 13, 10:27 pm)
Re: [PATCH 1/4] fix bsd shell negation, Jeff King, (Wed May 14, 12:01 am)
speck-geostationary