Code

filter-branch: Export variable `workdir' for --commit-filter
authorMichael Witten <mfwitten@gmail.com>
Sun, 7 Aug 2011 02:44:43 +0000 (02:44 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2011 19:09:38 +0000 (12:09 -0700)
commit0906f6e14e6e9df0c4ea4edb08ebe9f5d16c2391
tree3fa834f36f0f2ce1c330247ee1dfd8060f642dc0
parentae8044a2f542f5803c161ee510ac14492bc468d8
filter-branch: Export variable `workdir' for --commit-filter

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-filter-branch.sh