summaryrefslogtreecommitdiff
path: root/git-filter-branch.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-11-06 06:24:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-11-06 17:35:49 (GMT)
commit348d4f2fc5d3c4f7ba47079b96676b4e2dd831fc (patch)
tree068baef549634129847efcc77f7aa8cf3d20566c /git-filter-branch.sh
parentf34be46e47773d03e9d09641209121591a6b37c8 (diff)
downloadgit-348d4f2fc5d3c4f7ba47079b96676b4e2dd831fc.zip
git-348d4f2fc5d3c4f7ba47079b96676b4e2dd831fc.tar.gz
git-348d4f2fc5d3c4f7ba47079b96676b4e2dd831fc.tar.bz2
filter-branch: skip index read/write when possible
If the user specifies an index filter but not a tree filter, filter-branch cleverly avoids checking out the tree entirely. But we don't do the next level of optimization: if you have no index or tree filter, we do not need to read the index at all. This can greatly speed up cases where we are only changing the commit objects (e.g., cementing a graft into place). Here are numbers from the newly-added perf test: Test HEAD^ HEAD --------------------------------------------------------------- 7000.2: noop filter 13.81(4.95+0.83) 5.43(0.42+0.43) -60.7% Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-filter-branch.sh')
-rwxr-xr-xgit-filter-branch.sh23
1 files changed, 21 insertions, 2 deletions
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 27c9c54..d61f9ba 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -306,6 +306,15 @@ then
start_timestamp=$(date '+%s')
fi
+if test -n "$filter_index" ||
+ test -n "$filter_tree" ||
+ test -n "$filter_subdir"
+then
+ need_index=t
+else
+ need_index=
+fi
+
while read commit parents; do
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
@@ -313,7 +322,10 @@ while read commit parents; do
case "$filter_subdir" in
"")
- GIT_ALLOW_NULL_SHA1=1 git read-tree -i -m $commit
+ if test -n "$need_index"
+ then
+ GIT_ALLOW_NULL_SHA1=1 git read-tree -i -m $commit
+ fi
;;
*)
# The commit may not have the subdirectory at all
@@ -387,8 +399,15 @@ while read commit parents; do
} <../commit |
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
+
+ if test -n "$need_index"
+ then
+ tree=$(git write-tree)
+ else
+ tree="$commit^{tree}"
+ fi
workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ "$tree" $parentstr < ../message > ../map/$commit ||
die "could not write rewritten commit"
done <../revs