{"thread":{"id":"61994","subject":"[PATCH] diff-index: integrate with the sparse index","startedAt":"2024-08-22T16:03:33Z","lastAt":"2024-08-22T16:03:33Z","messageCount":1,"participants":["Derrick Stolee via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"501543","messageId":"pull.1777.git.1724342607793.gitgitgadget@gmail.com","threadId":"61994","inReplyTo":null,"subject":"[PATCH] diff-index: integrate with the sparse index","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-08-22T16:03:27Z","receivedAt":"2024-08-22T16:03:33Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <stolee@gmail.com>\n\nThe sparse index allows focusing the index data structure on the files\npresent in the sparse-checkout, leaving only tree entries for\ndirectories not within the sparse-checkout. Each builtin needs a\nrepository setting to indicate that it has been tested with the sparse\nindex before Git will allow the index to be loaded into memory in its\nsparse form. This is a safety precaution.\n\nThere are still some builtins that haven't been integrated due to the\ncomplexity of the integration and the lack of significant use. However,\n'git diff-index' was neglected only because of initial data showing low\nusage. The diff machinery was already integrated and there is no more\nwork to be done there but add some tests to be sure 'git diff-index'\nbehaves as expected.\n\nFor this purpose, we can follow the testing pattern used in 51ba65b5c35\n(diff: enable and test the sparse index, 2021-12-06). One difference\nhere is that we only verify that the sparse index case agrees with the\nfull index case, but do not generate the expected output. The 'git diff'\ntests use the '--name-status' option to ease the creation of the\nexpected output, but that's not an option for 'diff-index'. Since the\nunderlying diff machinery is the same, a simple comparison is sufficient\nto give some coverage.\n\nSigned-off-by: Derrick Stolee <stolee@gmail.com>\n---\n    diff-index: integrate with the sparse index\n    \n    This integration is motivated by an internal GUI tool using the 'git\n    diff-index' builtin. It is hitting the index expansion during every\n    execution, contributing significant performance issues. This was missed\n    in previous estimates of Git builtin usages because the numbers changed\n    as users started using this tool.\n    \n    Thanks, - Stolee\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1777%2Fderrickstolee%2Fdiff-index-sparse-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1777/derrickstolee/diff-index-sparse-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1777\n\n builtin/diff-index.c                     |  4 ++++\n t/t1092-sparse-checkout-compatibility.sh | 15 ++++++++++++---\n 2 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/diff-index.c b/builtin/diff-index.c\nindex 3e05260ac0e..685b60284fd 100644\n--- a/builtin/diff-index.c\n+++ b/builtin/diff-index.c\n@@ -25,6 +25,10 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)\n \t\tusage(diff_cache_usage);\n \n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n+\n+\tprepare_repo_settings(the_repository);\n+\tthe_repository->settings.command_requires_full_index = 0;\n+\n \trepo_init_revisions(the_repository, &rev, prefix);\n \trev.abbrev = 0;\n \tprefix = precompose_argv_prefix(argc, argv, prefix);\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex a2c0e1b4dcc..6fa7f5e9587 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -803,6 +803,8 @@ test_expect_success 'update-index --remove outside sparse definition' '\n \ttest_sparse_match git diff --cached --name-status &&\n \ttest_cmp expect sparse-checkout-out &&\n \n+\ttest_sparse_match git diff-index --cached HEAD &&\n+\n \t# Reset the state\n \ttest_all_match git reset --hard &&\n \n@@ -812,6 +814,8 @@ test_expect_success 'update-index --remove outside sparse definition' '\n \ttest_sparse_match git diff --cached --name-status &&\n \ttest_must_be_empty sparse-checkout-out &&\n \n+\ttest_sparse_match git diff-index --cached HEAD &&\n+\n \t# Reset the state\n \ttest_all_match git reset --hard &&\n \n@@ -823,7 +827,9 @@ test_expect_success 'update-index --remove outside sparse definition' '\n \tD\tfolder1/a\n \tEOF\n \ttest_sparse_match git diff --cached --name-status &&\n-\ttest_cmp expect sparse-checkout-out\n+\ttest_cmp expect sparse-checkout-out &&\n+\n+\ttest_sparse_match git diff-index --cached HEAD\n '\n \n test_expect_success 'update-index with directories' '\n@@ -1551,7 +1557,7 @@ test_expect_success 'sparse-index is not expanded: describe' '\n \tensure_not_expanded describe\n '\n \n-test_expect_success 'sparse index is not expanded: diff' '\n+test_expect_success 'sparse index is not expanded: diff and diff-index' '\n \tinit_repos &&\n \n \twrite_script edit-contents <<-\\EOF &&\n@@ -1568,6 +1574,7 @@ test_expect_success 'sparse index is not expanded: diff' '\n \ttest_all_match git diff --cached &&\n \tensure_not_expanded diff &&\n \tensure_not_expanded diff --cached &&\n+\tensure_not_expanded diff-index --cached HEAD &&\n \n \t# Add file outside cone\n \ttest_all_match git reset --hard &&\n@@ -1582,6 +1589,7 @@ test_expect_success 'sparse index is not expanded: diff' '\n \ttest_all_match git diff --cached &&\n \tensure_not_expanded diff &&\n \tensure_not_expanded diff --cached &&\n+\tensure_not_expanded diff-index --cached HEAD &&\n \n \t# Merge conflict outside cone\n \t# The sparse checkout will report a warning that is not in the\n@@ -1594,7 +1602,8 @@ test_expect_success 'sparse index is not expanded: diff' '\n \ttest_all_match git diff &&\n \ttest_all_match git diff --cached &&\n \tensure_not_expanded diff &&\n-\tensure_not_expanded diff --cached\n+\tensure_not_expanded diff --cached &&\n+\tensure_not_expanded diff-index --cached HEAD\n '\n \n test_expect_success 'sparse index is not expanded: show and rev-parse' '\n\nbase-commit: 80ccd8a2602820fdf896a8e8894305225f86f61d\n-- \ngitgitgadget\n"}]}