filter-branch: skip commits present on --state-branch
authorMichael Barabanov <michael.barabanov@gmail.com>
Tue, 26 Jun 2018 04:07:33 +0000 (21:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Jun 2018 22:44:53 +0000 (15:44 -0700)
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 <michael.barabanov@gmail.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-filter-branch.sh
t/t7003-filter-branch.sh
index 98c76ec589b053c112ddc86b6821f2acf17b7ab0..10096cb99910e23626ca0b6d93e43af52c5fe50e 100755 (executable)
@@ -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
        "")
index 7cb60799be1a109e2210350137c8754a5bc4bb7d..451211280b84169213c439212715674f035eb13d 100755 (executable)
@@ -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 &&