Skip to content

Commit a727a15

Browse files
Cheskaqiqigitster
authored andcommitted
diff-files: integrate with sparse index
Remove full index requirement for `git diff-files` and test to ensure the index is not expanded in `git diff-files`. The `p2000` tests demonstrate a ~96% execution time reduction for 'git diff-files' and a ~97% execution time reduction for 'git diff-files' for a file using a sparse index: Test before after ----------------------------------------------------------------- 2000.78: git diff-files (full-v3) 0.09 0.08 -11.1% 2000.79: git diff-files (full-v4) 0.09 0.09 +0.0% 2000.80: git diff-files (sparse-v3) 0.52 0.02 -96.2% 2000.81: git diff-files (sparse-v4) 0.51 0.02 -96.1% 2000.82: git diff-files f2/f4/a (full-v3) 0.06 0.07 +16.7% 2000.83: git diff-files f2/f4/a (full-v4) 0.08 0.08 +0.0% 2000.84: git diff-files f2/f4/a (sparse-v3) 0.46 0.01 -97.8% 2000.85: git diff-files f2/f4/a (sparse-v4) 0.51 0.02 -96.1% Signed-off-by: Shuqi Liang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c572b9a commit a727a15

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

builtin/diff-files.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2727
usage(diff_files_usage);
2828

2929
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
30+
31+
prepare_repo_settings(the_repository);
32+
the_repository->settings.command_requires_full_index = 0;
33+
3034
repo_init_revisions(the_repository, &rev, prefix);
3135
rev.abbrev = 0;
3236

t/perf/p2000-sparse-operations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,7 @@ test_perf_on_all git checkout-index -f --all
125125
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
126126
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
127127
test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
128+
test_perf_on_all git diff-files
129+
test_perf_on_all git diff-files $SPARSE_CONE/a
128130

129131
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,4 +2103,17 @@ test_expect_success 'diff-files with pathspec outside sparse definition' '
21032103
test_cmp expect sparse-checkout-out
21042104
'
21052105

2106+
test_expect_success 'sparse index is not expanded: diff-files' '
2107+
init_repos &&
2108+
2109+
write_script edit-contents <<-\EOF &&
2110+
echo text >>"$1"
2111+
EOF
2112+
2113+
run_on_all ../edit-contents deep/a &&
2114+
2115+
ensure_not_expanded diff-files &&
2116+
ensure_not_expanded diff-files deep/a
2117+
'
2118+
21062119
test_done

0 commit comments

Comments
 (0)