{"thread":{"id":"59349","subject":"[PATCH v2 0/2] diff-files: integrate with sparse index","startedAt":"2023-03-07T06:45:36Z","lastAt":"2023-03-07T06:45:46Z","messageCount":3,"participants":["Shuqi Liang"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"473107","messageId":"20230307064506.76663-1-cheskaqiqi@gmail.com","threadId":"59349","inReplyTo":null,"subject":"[PATCH v2 0/2] diff-files: integrate with sparse index","fromName":"Shuqi Liang","fromEmail":"cheskaqiqi@gmail.com","sentAt":"2023-03-07T06:45:04Z","receivedAt":"2023-03-07T06:45:36Z","isPatch":true,"sender":{"key":"cheskaqiqi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109261504?v=4"},"body":"Turn on sparse-index feature within `git diff-files` command.\nAdd necessary modifications and test them.\n\nChanges since v1:\n\n1.Add an empty line between the previous test's closing quote\nand the start of new test.\n\n2.Use \"git add --sparse newdirectory/testfile\" instead of \n'git sparse-checkout set' to have staged changes outside \nof the sparse-checkout cone\n\n3.Edit commit message to be more informative\n\n\nShuqi Liang (2):\n  t1092: add tests for `git diff-files`\n  diff-files: integrate with sparse index\n\n builtin/diff-files.c                     |  4 ++\n t/perf/p2000-sparse-operations.sh        |  2 +\n t/t1092-sparse-checkout-compatibility.sh | 52 ++++++++++++++++++++++++\n 3 files changed, 58 insertions(+)\n\n\nbase-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1\n-- \n2.39.0\n\n"},{"id":"473108","messageId":"20230307064506.76663-2-cheskaqiqi@gmail.com","threadId":"59349","inReplyTo":"20230307064506.76663-1-cheskaqiqi@gmail.com","subject":"[PATCH v2 1/2] t1092: add tests for `git diff-files`","fromName":"Shuqi Liang","fromEmail":"cheskaqiqi@gmail.com","sentAt":"2023-03-07T06:45:05Z","receivedAt":"2023-03-07T06:45:40Z","isPatch":true,"sender":{"key":"cheskaqiqi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109261504?v=4"},"body":"Before integrating the 'git diff-files' builtin\nwith the sparse index feature, add tests to\nt1092-sparse-checkout-compatibility.sh to ensure it currently works\nwith sparse-checkout and will still work with sparse index\nafter that integration.\n\nWhen adding tests against a sparse-checkout\ndefinition, we test two modes: all changes are\nwithin the sparse-checkout cone and some changes are outside\nthe sparse-checkout cone.\n\nIn order to have staged changes outside of\nthe sparse-checkout cone, create a 'newdirectory/testfile' and\nadd it to the index, while leaving it outside of\nthe sparse-checkout definition.Test 'newdirectory/testfile'\nbeing present on-disk without modifications, then change content inside\n'newdirectory/testfile' in order to test 'newdirectory/testfile'\nbeing present on-disk with modifications.\n\nSigned-off-by: Shuqi Liang <cheskaqiqi@gmail.com>\n---\n t/t1092-sparse-checkout-compatibility.sh | 38 ++++++++++++++++++++++++\n 1 file changed, 38 insertions(+)\n\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e..9382428352 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -2055,4 +2055,42 @@ test_expect_success 'grep sparse directory within submodules' '\n \ttest_cmp actual expect\n '\n \n+test_expect_success 'diff-files with pathspec inside sparse definition' '\n+\tinit_repos &&\n+\n+\twrite_script edit-contents <<-\\EOF &&\n+\techo text >>$1\n+\tEOF\n+\n+\trun_on_all ../edit-contents deep/a &&\n+\n+\ttest_all_match git diff-files  &&\n+\ttest_all_match git diff-files deep/a &&\n+\ttest_all_match git diff-files --find-object=HEAD:a\n+'\n+\n+test_expect_success 'diff-files with pathspec outside sparse definition' '\n+\tinit_repos &&\n+\n+\twrite_script edit-contents <<-\\EOF &&\n+\techo text >>$1\n+\tEOF\n+\n+\t#add file to the index but outside of cone\n+\trun_on_sparse mkdir newdirectory &&\n+\trun_on_sparse ../edit-contents newdirectory/testfile &&\n+\ttest_sparse_match git add --sparse newdirectory/testfile &&\n+\n+\t#file present on-disk without modifications\n+\ttest_sparse_match git diff-files &&\n+\ttest_sparse_match git diff-files newdirectory/testfile &&\n+\ttest_sparse_match test_must_fail git diff-files --find-object=HEAD:testfile &&\n+\n+\t#file present on-disk with modifications\n+\trun_on_sparse ../edit-contents newdirectory/testfile &&\n+\ttest_sparse_match git diff-files &&\n+\ttest_sparse_match git diff-files newdirectory/testfile &&\n+\ttest_sparse_match test_must_fail git diff-files --find-object=HEAD:testfile\n+'\n+\n test_done\n-- \n2.39.0\n\n"},{"id":"473109","messageId":"20230307064506.76663-3-cheskaqiqi@gmail.com","threadId":"59349","inReplyTo":"20230307064506.76663-1-cheskaqiqi@gmail.com","subject":"[PATCH v2 2/2] diff-files: integrate with sparse index","fromName":"Shuqi Liang","fromEmail":"cheskaqiqi@gmail.com","sentAt":"2023-03-07T06:45:06Z","receivedAt":"2023-03-07T06:45:46Z","isPatch":true,"sender":{"key":"cheskaqiqi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/109261504?v=4"},"body":"Remove full index requirement for `git diff-files`\nand test to ensure the index is not expanded in `git diff-files`.\n\nThe `p2000` tests demonstrate a ~96% execution time reduction for 'git\ndiff-files' and a ~97% execution time reduction for 'git diff-files'\nfor a file using a sparse index:\n\nTest                                           before  after\n-----------------------------------------------------------------\n2000.78: git diff-files (full-v3)              0.09    0.08 -11.1%\n2000.79: git diff-files (full-v4)              0.09    0.09 +0.0%\n2000.80: git diff-files (sparse-v3)            0.52    0.02 -96.2%\n2000.81: git diff-files (sparse-v4)            0.51    0.02 -96.1%\n2000.82: git diff-files f2/f4/a (full-v3)      0.06    0.07 +16.7%\n2000.83: git diff-files f2/f4/a (full-v4)      0.08    0.08 +0.0%\n2000.84: git diff-files f2/f4/a (sparse-v3)    0.46    0.01 -97.8%\n2000.85: git diff-files f2/f4/a (sparse-v4)    0.51    0.02 -96.1%\n\nSigned-off-by: Shuqi Liang <cheskaqiqi@gmail.com>\n---\n builtin/diff-files.c                     |  4 ++++\n t/perf/p2000-sparse-operations.sh        |  2 ++\n t/t1092-sparse-checkout-compatibility.sh | 14 ++++++++++++++\n 3 files changed, 20 insertions(+)\n\ndiff --git a/builtin/diff-files.c b/builtin/diff-files.c\nindex dc991f753b..360464e6ef 100644\n--- a/builtin/diff-files.c\n+++ b/builtin/diff-files.c\n@@ -27,6 +27,10 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)\n \t\tusage(diff_files_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 \ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a..82751f2ca3 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -125,5 +125,7 @@ test_perf_on_all git checkout-index -f --all\n test_perf_on_all git update-index --add --remove $SPARSE_CONE/a\n test_perf_on_all \"git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a\"\n test_perf_on_all git grep --cached --sparse bogus -- \"f2/f1/f1/*\"\n+test_perf_on_all git diff-files\n+test_perf_on_all git diff-files $SPARSE_CONE/a\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 9382428352..7cc02b882b 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -2093,4 +2093,18 @@ test_expect_success 'diff-files with pathspec outside sparse definition' '\n \ttest_sparse_match test_must_fail git diff-files --find-object=HEAD:testfile\n '\n \n+test_expect_success 'sparse index is not expanded: diff-files' '\n+\tinit_repos &&\n+\n+\twrite_script edit-contents <<-\\EOF &&\n+\techo text >>$1\n+\tEOF\n+\n+\trun_on_all ../edit-contents deep/a &&\n+\n+\tensure_not_expanded diff-files  &&\n+\tensure_not_expanded diff-files deep/a &&\n+\tensure_not_expanded diff-files --find-object=HEAD:a\n+'\n+\n test_done\n-- \n2.39.0\n\n"}]}