threads / patch / 28035

patchfilter-branch: Export variable `workdir' for --commit-filter

Subject: [PATCH] filter-branch: Export variable `workdir' for --commit-filter

## tl;dr

2 messages between Aug 7, 2011 and Aug 8, 2011. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Michael Witten· Aug 7, 2011, 02:03 UTC · lore
According to `git help filter-branch':
       --commit-filter <command>
           ...
           You can use the _map_ convenience function in this filter,
           and other convenience functions, too...
           ...

However, it turns out that `map' hasn't been usable because it depends on the variable `workdir', which is not propogated to the environment of the shell that runs the commit-filter <command> because the shell is created via a simple-command rather than a compound-command subshell:

 @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
                 $(git write-tree) $parentstr < ../message > ../map/$commit ||
                         die "could not write rewritten commit"

One solution is simply to export `workdir'. However, it seems rather heavy-handed to export `workdir' to the environments of all commands, so instead this commit exports `workdir' for only the duration of the shell command in question:

 workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
                 $(git write-tree) $parentstr < ../message > ../map/$commit ||
                         die "could not write rewritten commit"
Signed-off-by: Michael Witten <mfwitten@gmail.com>
---
 git-filter-branch.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to git-filter-branch.sh +1 −1
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 962a93b..6b5f225 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -363,7 +363,7 @@ while read commit parents; do
 	sed -e '1,/^$/d' <../commit | \
 		eval "$filter_msg" > ../message ||
 			die "msg filter failed: $filter_msg"
-	@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
+	workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
 		$(git write-tree) $parentstr < ../message > ../map/$commit ||
 			die "could not write rewritten commit"
 done <../revs
-- 
1.7.6.134.gcf13f6
Junio C Hamano· Aug 8, 2011, 19:11 UTC · re: Michael Witten · lore

Re: [PATCH] filter-branch: Export variable `workdir' for --commit-filter

Michael Witten <mfwitten@gmail.com> writes:
Show 11 quoted lines
> According to `git help filter-branch':
>
>        --commit-filter <command>
>            ...
>            You can use the _map_ convenience function in this filter,
>            and other convenience functions, too...
>            ...
>
> However, it turns out that `map' hasn't been usable because it depends
> on the variable `workdir', which is not propogated to the environment
> of the shell that runs the commit-filter <command>...
Thanks.

← back to recent threads