From 709cfe848ad2312f80e6f4f7a27aa5d23992a0e3 Mon Sep 17 00:00:00 2001 From: Michael Barabanov Date: Mon, 25 Jun 2018 21:07:33 -0700 Subject: [PATCH] filter-branch: skip commits present on --state-branch The commits in state:filter.map have already been processed, so don't filter them again. This makes incremental git filter-branch much faster. Also add tests for --state-branch option. Signed-off-by: Michael Barabanov Acked-by: Ian Campbell Signed-off-by: Junio C Hamano --- git-filter-branch.sh | 1 + t/t7003-filter-branch.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 98c76ec589..10096cb999 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -360,6 +360,7 @@ while read commit parents; do git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1)) report_progress + test -f "$workdir"/../map/$commit && continue case "$filter_subdir" in "") diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 7cb60799be..451211280b 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -107,6 +107,21 @@ test_expect_success 'test that the directory was renamed' ' test dir/D = "$(cat diroh/D.t)" ' +V=$(git rev-parse HEAD) + +test_expect_success 'populate --state-branch' ' + git filter-branch --state-branch state -f --tree-filter "touch file || :" HEAD +' + +W=$(git rev-parse HEAD) + +test_expect_success 'using --state-branch to skip already rewritten commits' ' + test_when_finished git reset --hard $V && + git reset --hard $V && + git filter-branch --state-branch state -f --tree-filter "touch file || :" HEAD && + test_cmp_rev $W HEAD +' + git tag oldD HEAD~4 test_expect_success 'rewrite one branch, keeping a side branch' ' git branch modD oldD &&