summaryrefslogtreecommitdiff
path: root/t/t2022-checkout-paths.sh
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-03-27 05:58:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-03-27 15:53:15 (GMT)
commite721c1544f9166e8f08a7f8c0e6178ea3a45e255 (patch)
treeed4045ef266521a7cf4e1bfb7d0591b1a6f79b28 /t/t2022-checkout-paths.sh
parent7b592fadf1e23b10b913e0771b9f711770597266 (diff)
downloadgit-e721c1544f9166e8f08a7f8c0e6178ea3a45e255.zip
git-e721c1544f9166e8f08a7f8c0e6178ea3a45e255.tar.gz
git-e721c1544f9166e8f08a7f8c0e6178ea3a45e255.tar.bz2
checkout: avoid unnecessary match_pathspec calls
In checkout_paths() we do this - for all updated items, call match_pathspec - for all items, call match_pathspec (inside unmerge_cache) - for all items, call match_pathspec (for showing "path .. is unmerged) - for updated items, call match_pathspec and update paths That's a lot of duplicate match_pathspec(s) and the function is not exactly cheap to be called so many times, especially on large indexes. This patch makes it call match_pathspec once per updated index entry, save the result in ce_flags and reuse the results in the following loops. The changes in 0a1283b (checkout $tree $path: do not clobber local changes in $path not in $tree - 2011-09-30) limit the affected paths to ones we read from $tree. We do not do anything to other modified entries in this case, so the "for all items" above could be modified to "for all updated items". But.. The command's behavior now is modified slightly: unmerged entries that match $path, but not updated by $tree, are now NOT touched. Although this should be considered a bug fix, not a regression. A new test is added for this change. And while at there, free ps_matched after use. The following command is tested on webkit, 215k entries. The pattern is chosen mainly to make match_pathspec sweat: git checkout -- "*[a-zA-Z]*[a-zA-Z]*[a-zA-Z]*" before after real 0m3.493s 0m2.737s user 0m2.239s 0m1.586s sys 0m1.252s 0m1.151s Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2022-checkout-paths.sh')
-rwxr-xr-xt/t2022-checkout-paths.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh
index 56090d2..8e3545d 100755
--- a/t/t2022-checkout-paths.sh
+++ b/t/t2022-checkout-paths.sh
@@ -39,4 +39,26 @@ test_expect_success 'checking out paths out of a tree does not clobber unrelated
test_cmp expect.next2 dir/next2
'
+test_expect_success 'do not touch unmerged entries matching $path but not in $tree' '
+ git checkout next &&
+ git reset --hard &&
+
+ cat dir/common >expect.common &&
+ EMPTY_SHA1=$(git hash-object -w --stdin </dev/null) &&
+ git rm dir/next0 &&
+ cat >expect.next0 <<-EOF &&
+ 100644 $EMPTY_SHA1 1 dir/next0
+ 100644 $EMPTY_SHA1 2 dir/next0
+ EOF
+ git update-index --index-info <expect.next0 &&
+
+ git checkout master dir &&
+
+ test_cmp expect.common dir/common &&
+ test_path_is_file dir/master &&
+ git diff --exit-code master dir/master &&
+ git ls-files -s dir/next0 >actual.next0 &&
+ test_cmp expect.next0 actual.next0
+'
+
test_done