
Enable the sparse index within the 'git diff' command. Its implementation already safely integrates with the sparse index because it shares code with the 'git status' and 'git checkout' commands that were already integrated. For more details see:d76723ee53
(status: use sparse-index throughout, 2021-07-14)1ba5f45132
(checkout: stop expanding sparse indexes, 2021-06-29) The most interesting thing to do is to add tests that verify that 'git diff' behaves correctly when the sparse index is enabled. These cases are: 1. The index is not expanded for 'diff' and 'diff --staged' 2. 'diff' and 'diff --staged' behave the same in full checkout, sparse checkout, and sparse index repositories in the following partially-staged scenarios (i.e. the index, HEAD, and working directory differ at a given path): 1. Path is within sparse-checkout cone 2. Path is outside sparse-checkout cone 3. A merge conflict exists for paths outside sparse-checkout cone The `p2000` tests demonstrate a ~44% execution time reduction for 'git diff' and a ~86% execution time reduction for 'git diff --staged' using a sparse index: Test before after ------------------------------------------------------------- 2000.30: git diff (full-v3) 0.33 0.34 +3.0% 2000.31: git diff (full-v4) 0.33 0.35 +6.1% 2000.32: git diff (sparse-v3) 0.53 0.31 -41.5% 2000.33: git diff (sparse-v4) 0.54 0.29 -46.3% 2000.34: git diff --cached (full-v3) 0.07 0.07 +0.0% 2000.35: git diff --cached (full-v4) 0.07 0.08 +14.3% 2000.36: git diff --cached (sparse-v3) 0.28 0.04 -85.7% 2000.37: git diff --cached (sparse-v4) 0.23 0.03 -87.0% Co-authored-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Lessley Dennington <lessleydennington@gmail.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
120 lines
2.9 KiB
Bash
Executable File
120 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description="test performance of Git operations using the index"
|
|
|
|
. ./perf-lib.sh
|
|
|
|
test_perf_default_repo
|
|
|
|
SPARSE_CONE=f2/f4
|
|
|
|
test_expect_success 'setup repo and indexes' '
|
|
git reset --hard HEAD &&
|
|
|
|
# Remove submodules from the example repo, because our
|
|
# duplication of the entire repo creates an unlikely data shape.
|
|
if git config --file .gitmodules --get-regexp "submodule.*.path" >modules
|
|
then
|
|
git rm $(awk "{print \$2}" modules) &&
|
|
git commit -m "remove submodules" || return 1
|
|
fi &&
|
|
|
|
echo bogus >a &&
|
|
cp a b &&
|
|
git add a b &&
|
|
git commit -m "level 0" &&
|
|
BLOB=$(git rev-parse HEAD:a) &&
|
|
OLD_COMMIT=$(git rev-parse HEAD) &&
|
|
OLD_TREE=$(git rev-parse HEAD^{tree}) &&
|
|
|
|
for i in $(test_seq 1 3)
|
|
do
|
|
cat >in <<-EOF &&
|
|
100755 blob $BLOB a
|
|
040000 tree $OLD_TREE f1
|
|
040000 tree $OLD_TREE f2
|
|
040000 tree $OLD_TREE f3
|
|
040000 tree $OLD_TREE f4
|
|
EOF
|
|
NEW_TREE=$(git mktree <in) &&
|
|
NEW_COMMIT=$(git commit-tree $NEW_TREE -p $OLD_COMMIT -m "level $i") &&
|
|
OLD_TREE=$NEW_TREE &&
|
|
OLD_COMMIT=$NEW_COMMIT || return 1
|
|
done &&
|
|
|
|
git sparse-checkout init --cone &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git checkout -b wide $OLD_COMMIT &&
|
|
|
|
for l2 in f1 f2 f3 f4
|
|
do
|
|
echo more bogus >>$SPARSE_CONE/$l2/a &&
|
|
git commit -a -m "edit $SPARSE_CONE/$l2/a" || return 1
|
|
done &&
|
|
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v3 &&
|
|
(
|
|
cd full-v3 &&
|
|
git sparse-checkout init --cone &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 3 &&
|
|
git update-index --index-version=3 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&
|
|
(
|
|
cd full-v4 &&
|
|
git sparse-checkout init --cone &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 4 &&
|
|
git update-index --index-version=4 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&
|
|
(
|
|
cd sparse-v3 &&
|
|
git sparse-checkout init --cone --sparse-index &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 3 &&
|
|
git update-index --index-version=3 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&
|
|
(
|
|
cd sparse-v4 &&
|
|
git sparse-checkout init --cone --sparse-index &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 4 &&
|
|
git update-index --index-version=4 &&
|
|
git checkout HEAD~4
|
|
)
|
|
'
|
|
|
|
test_perf_on_all () {
|
|
command="$@"
|
|
for repo in full-v3 full-v4 \
|
|
sparse-v3 sparse-v4
|
|
do
|
|
test_perf "$command ($repo)" "
|
|
(
|
|
cd $repo &&
|
|
echo >>$SPARSE_CONE/a &&
|
|
$command
|
|
)
|
|
"
|
|
done
|
|
}
|
|
|
|
test_perf_on_all git status
|
|
test_perf_on_all git add -A
|
|
test_perf_on_all git add .
|
|
test_perf_on_all git commit -a -m A
|
|
test_perf_on_all git checkout -f -
|
|
test_perf_on_all git reset
|
|
test_perf_on_all git reset --hard
|
|
test_perf_on_all git reset -- does-not-exist
|
|
test_perf_on_all git diff
|
|
test_perf_on_all git diff --cached
|
|
|
|
test_done
|