git-commit-vandalism/t/t2022-checkout-paths.sh

65 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/sh
test_description='checkout $tree -- $paths'
. ./test-lib.sh
test_expect_success setup '
mkdir dir &&
>dir/master &&
echo common >dir/common &&
git add dir/master dir/common &&
test_tick && git commit -m "master has dir/master" &&
git checkout -b next &&
git mv dir/master dir/next0 &&
echo next >dir/next1 &&
git add dir &&
test_tick && git commit -m "next has dir/next but not dir/master"
'
test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' '
git checkout next &&
git reset --hard &&
rm dir/next0 &&
cat dir/common >expect.common &&
echo modified >expect.next1 &&
cat expect.next1 >dir/next1 &&
echo untracked >expect.next2 &&
cat expect.next2 >dir/next2 &&
git checkout master dir &&
test_cmp expect.common dir/common &&
test_path_is_file dir/master &&
git diff --exit-code master dir/master &&
test_path_is_missing dir/next0 &&
test_cmp expect.next1 dir/next1 &&
test_path_is_file dir/next2 &&
test_must_fail git ls-files --error-unmatch dir/next2 &&
test_cmp expect.next2 dir/next2
'
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>
2013-03-27 06:58:21 +01:00
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