{"thread":{"id":"59483","subject":"[PATCH] describe: enable sparse index for describe","startedAt":"2023-03-27T14:22:46Z","lastAt":"2023-04-03T16:48:14Z","messageCount":21,"participants":["Raghul Nanth A via GitGitGadget","Junio C Hamano","Derrick Stolee","Victoria Dye","Raghul Nanth","Raghul Nanth A"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"474235","messageId":"pull.1480.git.git.1679926829475.gitgitgadget@gmail.com","threadId":"59483","inReplyTo":null,"subject":"[PATCH] describe: enable sparse index for describe","fromName":"Raghul Nanth A via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-03-27T14:20:29Z","receivedAt":"2023-03-27T14:22:46Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"From: Raghul Nanth A <nanth.raghul@gmail.com>\n\nAdd usage and performance tests for describe\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n    describe: enable sparse index for describe\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1480%2FNanthR%2Fdescribe-sparse-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1480/NanthR/describe-sparse-v1\nPull-Request: https://github.com/git/git/pull/1480\n\n builtin/describe.c                       |   2 +\n t/perf/p2000-sparse-operations.sh        |  14 +-\n t/t1092-sparse-checkout-compatibility.sh |  10 +\n t/t6121-describe-sparse.sh               | 675 +++++++++++++++++++++++\n 4 files changed, 697 insertions(+), 4 deletions(-)\n create mode 100755 t/t6121-describe-sparse.sh\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8c..7ff9b5e4b20 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a0..a8a9ed79441 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -59,7 +59,8 @@ test_expect_success 'setup repo and indexes' '\n \t\tgit sparse-checkout set $SPARSE_CONE &&\n \t\tgit config index.version 3 &&\n \t\tgit update-index --index-version=3 &&\n-\t\tgit checkout HEAD~4\n+\t\tgit checkout HEAD~4 &&\n+\t\tgit tag -a v1.0 -m \"Final\"\n \t) &&\n \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&\n \t(\n@@ -68,7 +69,8 @@ test_expect_success 'setup repo and indexes' '\n \t\tgit sparse-checkout set $SPARSE_CONE &&\n \t\tgit config index.version 4 &&\n \t\tgit update-index --index-version=4 &&\n-\t\tgit checkout HEAD~4\n+\t\tgit checkout HEAD~4 &&\n+\t\tgit tag -a v1.0 -m \"Final\"\n \t) &&\n \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&\n \t(\n@@ -77,7 +79,8 @@ test_expect_success 'setup repo and indexes' '\n \t\tgit sparse-checkout set $SPARSE_CONE &&\n \t\tgit config index.version 3 &&\n \t\tgit update-index --index-version=3 &&\n-\t\tgit checkout HEAD~4\n+\t\tgit checkout HEAD~4 &&\n+\t\tgit tag -a v1.0 -m \"Final\"\n \t) &&\n \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&\n \t(\n@@ -86,7 +89,8 @@ test_expect_success 'setup repo and indexes' '\n \t\tgit sparse-checkout set $SPARSE_CONE &&\n \t\tgit config index.version 4 &&\n \t\tgit update-index --index-version=4 &&\n-\t\tgit checkout HEAD~4\n+\t\tgit checkout HEAD~4 &&\n+\t\tgit tag -a v1.0 -m \"Final\"\n \t)\n '\n \n@@ -125,5 +129,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 describe --dirty\n+test_perf_on_all 'echo >> new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e1..dea6f50ca84 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,16 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\tensure_not_expanded tag -a v1.0 -m \"Version 1\" &&\n+\tensure_not_expanded describe --dirty &&\n+\tensure_not_expanded describe &&\n+\techo \"test\" >> sparse-index/extra.txt &&\n+\tensure_not_expanded describe --dirty &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \ndiff --git a/t/t6121-describe-sparse.sh b/t/t6121-describe-sparse.sh\nnew file mode 100755\nindex 00000000000..1eebcdb55dd\n--- /dev/null\n+++ b/t/t6121-describe-sparse.sh\n@@ -0,0 +1,675 @@\n+#!/bin/sh\n+\n+test_description='git describe in sparse checked out trees'\n+\n+#  o---o-----o----o----o-------o----x\n+#       \\   D,R   e           /\n+#        \\---o-------------o-'\n+#         \\  B            /\n+#          `-o----o----o-'\n+#                 A    c\n+#\n+# First parent of a merge commit is on the same line, second parent below.\n+\n+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n+\n+. ./test-lib.sh\n+\n+check_describe () {\n+\tindir= &&\n+\twhile test $# != 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-C)\n+\t\t\tindir=\"$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone &&\n+\tindir=${indir:+\"$indir\"/} &&\n+\texpect=\"$1\"\n+\tshift\n+\tdescribe_opts=\"$@\"\n+\ttest_expect_success \"describe $describe_opts\" '\n+\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >raw &&\n+\t\tsed -e \"s/-g[0-9a-f]*\\$/-gHASH/\" <raw >actual &&\n+\t\techo \"$expect\" >expect &&\n+\t\ttest_cmp expect actual\n+\t'\n+}\n+\n+test_expect_success setup '\n+\ttest_commit initial file one &&\n+\ttest_commit second file two &&\n+\ttest_commit third file three &&\n+\ttest_commit --annotate A file A &&\n+\ttest_commit c file c &&\n+\n+\tgit reset --hard second &&\n+\ttest_commit --annotate B side B &&\n+\n+\ttest_tick &&\n+\tgit merge -m Merged c &&\n+\tmerged=$(git rev-parse HEAD) &&\n+\n+\tgit reset --hard second &&\n+\ttest_commit --no-tag D another D &&\n+\n+\ttest_tick &&\n+\tgit tag -a -m R R &&\n+\n+\ttest_commit e another DD &&\n+\ttest_commit --no-tag \"yet another\" another DDD &&\n+\n+\ttest_tick &&\n+\tgit merge -m Merged $merged &&\n+\n+\ttest_commit --no-tag x file &&\n+\tgit sparse-checkout init --cone\n+'\n+\n+check_describe A-8-gHASH HEAD\n+check_describe A-7-gHASH HEAD^\n+check_describe R-2-gHASH HEAD^^\n+check_describe A-3-gHASH HEAD^^2\n+check_describe B HEAD^^2^\n+check_describe R-1-gHASH HEAD^^^\n+\n+check_describe c-7-gHASH --tags HEAD\n+check_describe c-6-gHASH --tags HEAD^\n+check_describe e-1-gHASH --tags HEAD^^\n+check_describe c-2-gHASH --tags HEAD^^2\n+check_describe B --tags HEAD^^2^\n+check_describe e --tags HEAD^^^\n+\n+check_describe heads/main --all HEAD\n+check_describe tags/c-6-gHASH --all HEAD^\n+check_describe tags/e --all HEAD^^^\n+\n+check_describe B-0-gHASH --long HEAD^^2^\n+check_describe A-3-gHASH --long HEAD^^2\n+\n+check_describe c-7-gHASH --tags\n+check_describe e-3-gHASH --first-parent --tags\n+\n+test_expect_success 'describe --contains defaults to HEAD without commit-ish' '\n+\techo \"A^0\" >expect &&\n+\tgit checkout A &&\n+\ttest_when_finished \"git checkout -\" &&\n+\tgit describe --contains >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+check_describe tags/A --all A^0\n+\n+test_expect_success 'renaming tag A to Q locally produces a warning' \"\n+\tgit update-ref refs/tags/Q $(git rev-parse refs/tags/A) &&\n+\tgit update-ref -d refs/tags/A &&\n+\tgit describe HEAD 2>err >out &&\n+\tcat >expected <<-\\EOF &&\n+\twarning: tag 'Q' is externally known as 'A'\n+\tEOF\n+\ttest_cmp expected err &&\n+\tgrep -E '^A-8-g[0-9a-f]+$' out\n+\"\n+\n+test_expect_success 'misnamed annotated tag forces long output' '\n+\tdescription=$(git describe --no-long Q^0) &&\n+\texpr \"$description\" : \"A-0-g[0-9a-f]*$\" &&\n+\tgit rev-parse --verify \"$description\" >actual &&\n+\tgit rev-parse --verify Q^0 >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'abbrev=0 will not break misplaced tag (1)' '\n+\tdescription=$(git describe --abbrev=0 Q^0) &&\n+\texpr \"$description\" : \"A-0-g[0-9a-f]*$\"\n+'\n+\n+test_expect_success 'abbrev=0 will not break misplaced tag (2)' '\n+\tdescription=$(git describe --abbrev=0 c^0) &&\n+\texpr \"$description\" : \"A-1-g[0-9a-f]*$\"\n+'\n+\n+test_expect_success 'rename tag Q back to A' '\n+\tgit update-ref refs/tags/A $(git rev-parse refs/tags/Q) &&\n+\tgit update-ref -d refs/tags/Q\n+'\n+\n+test_expect_success 'pack tag refs' 'git pack-refs'\n+check_describe A-8-gHASH HEAD\n+\n+test_expect_success 'describe works from outside repo using --git-dir' '\n+\tgit clone --bare \"$TRASH_DIRECTORY\" \"$TRASH_DIRECTORY/bare\" &&\n+\tgit --git-dir \"$TRASH_DIRECTORY/bare\" describe >out &&\n+\tgrep -E \"^A-8-g[0-9a-f]+$\" out\n+'\n+\n+check_describe \"A-8-gHASH\" --dirty\n+\n+test_expect_success 'describe --dirty with --work-tree' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep -E \"^A-8-g[0-9a-f]+$\" out\n+'\n+\n+test_expect_success 'set-up dirty work tree' '\n+\techo >>file\n+'\n+\n+test_expect_success 'describe --dirty with --work-tree (dirty)' '\n+\tgit describe --dirty >expected &&\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep -E \"^A-8-g[0-9a-f]+-dirty$\" out &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '\n+\tgit describe --dirty=.mod >expected &&\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty=.mod >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep -E \"^A-8-g[0-9a-f]+.mod$\" out &&\n+\ttest_cmp expected out\n+'\n+\n+test_expect_success 'describe --dirty HEAD' '\n+\ttest_must_fail git describe --dirty HEAD\n+'\n+\n+test_expect_success 'set-up matching pattern tests' '\n+\tgit tag -a -m test-annotated test-annotated &&\n+\techo >>file &&\n+\ttest_tick &&\n+\tgit commit -a -m \"one more\" &&\n+\tgit tag test1-lightweight &&\n+\techo >>file &&\n+\ttest_tick &&\n+\tgit commit -a -m \"yet another\" &&\n+\tgit tag test2-lightweight &&\n+\techo >>file &&\n+\ttest_tick &&\n+\tgit commit -a -m \"even more\"\n+\n+'\n+\n+check_describe \"test-annotated-3-gHASH\" --match=\"test-*\"\n+\n+check_describe \"test1-lightweight-2-gHASH\" --tags --match=\"test1-*\"\n+\n+check_describe \"test2-lightweight-1-gHASH\" --tags --match=\"test2-*\"\n+\n+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test2-*\" HEAD^\n+\n+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test1-*\" --match=\"test2-*\" HEAD^\n+\n+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test1-*\" --no-match --match=\"test2-*\" HEAD^\n+\n+check_describe \"test1-lightweight-2-gHASH\" --long --tags --match=\"test1-*\" --match=\"test3-*\" HEAD\n+\n+check_describe \"test1-lightweight-2-gHASH\" --long --tags --match=\"test3-*\" --match=\"test1-*\" HEAD\n+\n+test_expect_success 'set-up branches' '\n+\tgit branch branch_A A &&\n+\tgit branch branch_C c &&\n+\tgit update-ref refs/remotes/origin/remote_branch_A \"A^{commit}\" &&\n+\tgit update-ref refs/remotes/origin/remote_branch_C \"c^{commit}\" &&\n+\tgit update-ref refs/original/original_branch_A test-annotated~2\n+'\n+\n+check_describe \"heads/branch_A-11-gHASH\" --all --match=\"branch_*\" --exclude=\"branch_C\" HEAD\n+\n+check_describe \"remotes/origin/remote_branch_A-11-gHASH\" --all --match=\"origin/remote_branch_*\" --exclude=\"origin/remote_branch_C\" HEAD\n+\n+check_describe \"original/original_branch_A-6-gHASH\" --all test-annotated~1\n+\n+test_expect_success '--match does not work for other types' '\n+\ttest_must_fail git describe --all --match=\"*original_branch_*\" test-annotated~1\n+'\n+\n+test_expect_success '--exclude does not work for other types' '\n+\tR=$(git describe --all --exclude=\"any_pattern_even_not_matching\" test-annotated~1) &&\n+\tcase \"$R\" in\n+\t*original_branch_A*) echo \"fail: Found unknown reference $R with --exclude\"\n+\t\tfalse;;\n+\t*) echo ok: Found some known type;;\n+\tesac\n+'\n+\n+test_expect_success 'name-rev with exact tags' '\n+\techo A >expect &&\n+\ttag_object=$(git rev-parse refs/tags/A) &&\n+\tgit name-rev --tags --name-only $tag_object >actual &&\n+\ttest_cmp expect actual &&\n+\n+\techo \"A^0\" >expect &&\n+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n+\tgit name-rev --tags --name-only $tagged_commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'name-rev --all' '\n+\t>expect.unsorted &&\n+\tfor rev in $(git rev-list --all)\n+\tdo\n+\t\tgit name-rev $rev >>expect.unsorted || return 1\n+\tdone &&\n+\tsort <expect.unsorted >expect &&\n+\tgit name-rev --all >actual.unsorted &&\n+\tsort <actual.unsorted >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'name-rev --annotate-stdin' '\n+\t>expect.unsorted &&\n+\tfor rev in $(git rev-list --all)\n+\tdo\n+\t\tname=$(git name-rev --name-only $rev) &&\n+\t\techo \"$rev ($name)\" >>expect.unsorted || return 1\n+\tdone &&\n+\tsort <expect.unsorted >expect &&\n+\tgit rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&\n+\tsort <actual.unsorted >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'name-rev --stdin deprecated' \"\n+\tgit rev-list --all | git name-rev --stdin 2>actual &&\n+\tgrep -E 'warning: --stdin is deprecated' actual\n+\"\n+\n+test_expect_success 'describe --contains with the exact tags' '\n+\techo \"A^0\" >expect &&\n+\ttag_object=$(git rev-parse refs/tags/A) &&\n+\tgit describe --contains $tag_object >actual &&\n+\ttest_cmp expect actual &&\n+\n+\techo \"A^0\" >expect &&\n+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n+\tgit describe --contains $tagged_commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe --contains and --match' '\n+\techo \"A^0\" >expect &&\n+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n+\ttest_must_fail git describe --contains --match=\"B\" $tagged_commit &&\n+\tgit describe --contains --match=\"B\" --match=\"A\" $tagged_commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe --exclude' '\n+\techo \"c~1\" >expect &&\n+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n+\ttest_must_fail git describe --contains --match=\"B\" $tagged_commit &&\n+\tgit describe --contains --match=\"?\" --exclude=\"A\" $tagged_commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe --contains and --no-match' '\n+\techo \"A^0\" >expect &&\n+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n+\tgit describe --contains --match=\"B\" --no-match $tagged_commit >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup and absorb a submodule' '\n+\tgit init sub1 &&\n+\ttest_commit -C sub1 initial &&\n+\tgit sparse-checkout add sub1 &&\n+\tgit submodule add ./sub1 &&\n+\tgit submodule absorbgitdirs &&\n+\tgit commit -a -m \"add submodule\" &&\n+\tgit describe --dirty >expect &&\n+\tgit describe --broken >out &&\n+\ttest_cmp expect out\n+'\n+\n+test_expect_success 'describe chokes on severely broken submodules' '\n+\tmv .git/modules/sub1/ .git/modules/sub_moved &&\n+\ttest_must_fail git describe --dirty\n+'\n+\n+test_expect_success 'describe ignoring a broken submodule' '\n+\tgit describe --broken >out &&\n+\tgrep broken out\n+'\n+\n+test_expect_success 'describe with --work-tree ignoring a broken submodule' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --broken >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\ttest_when_finished \"mv .git/modules/sub_moved .git/modules/sub1\" &&\n+\tgrep broken out\n+'\n+\n+test_expect_success 'describe a blob at a directly tagged commit' '\n+\techo \"make it a unique blob\" >file &&\n+\tgit add file && git commit -m \"content in file\" &&\n+\tgit tag -a -m \"latest annotated tag\" unique-file &&\n+\tgit describe HEAD:file >actual &&\n+\techo \"unique-file:file\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe a blob with its first introduction' '\n+\tgit commit --allow-empty -m \"empty commit\" &&\n+\tgit rm file &&\n+\tgit commit -m \"delete blob\" &&\n+\tgit revert HEAD &&\n+\tgit commit --allow-empty -m \"empty commit\" &&\n+\tgit describe HEAD:file >actual &&\n+\techo \"unique-file:file\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe directly tagged blob' '\n+\tgit tag test-blob unique-file:file &&\n+\tgit describe test-blob >actual &&\n+\techo \"unique-file:file\" >expect &&\n+\t# suboptimal: we rather want to see \"test-blob\"\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'describe tag object' '\n+\tgit tag test-blob-1 -a -m msg unique-file:file &&\n+\ttest_must_fail git describe test-blob-1 2>actual &&\n+\ttest_i18ngrep \"fatal: test-blob-1 is neither a commit nor blob\" actual\n+'\n+\n+test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '\n+\ti=1 &&\n+\twhile test $i -lt 8000\n+\tdo\n+\t\techo \"commit refs/heads/main\n+committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200\n+data <<EOF\n+commit #$i\n+EOF\" &&\n+\t\tif test $i = 1\n+\t\tthen\n+\t\t\techo \"from refs/heads/main^0\"\n+\t\tfi &&\n+\t\ti=$(($i + 1)) || return 1\n+\tdone | git fast-import &&\n+\tgit checkout main &&\n+\tgit tag far-far-away HEAD^ &&\n+\techo \"HEAD~4000 tags/far-far-away~3999\" >expect &&\n+\tgit name-rev HEAD~4000 >actual &&\n+\ttest_cmp expect actual &&\n+\trun_with_limited_stack git name-rev HEAD~4000 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' '\n+\tgit tag -f far-far-away HEAD~7999 &&\n+\techo \"far-far-away\" >expect &&\n+\tgit describe --tags --abbrev=0 HEAD~4000 >actual &&\n+\ttest_cmp expect actual &&\n+\trun_with_limited_stack git describe --tags --abbrev=0 HEAD~4000 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+check_describe tags/A --all A\n+check_describe tags/c --all c\n+check_describe heads/branch_A --all --match='branch_*' branch_A\n+\n+test_expect_success 'describe complains about tree object' '\n+\ttest_must_fail git describe HEAD^{tree}\n+'\n+\n+test_expect_success 'describe complains about missing object' '\n+\ttest_must_fail git describe $ZERO_OID\n+'\n+\n+test_expect_success 'name-rev a rev shortly after epoch' '\n+\ttest_when_finished \"git checkout main\" &&\n+\n+\tgit checkout --orphan no-timestamp-underflow &&\n+\t# Any date closer to epoch than the CUTOFF_DATE_SLOP constant\n+\t# in builtin/name-rev.c.\n+\tGIT_COMMITTER_DATE=\"@1234 +0000\" \\\n+\tgit commit -m \"committer date shortly after epoch\" &&\n+\told_commit_oid=$(git rev-parse HEAD) &&\n+\n+\techo \"$old_commit_oid no-timestamp-underflow\" >expect &&\n+\tgit name-rev $old_commit_oid >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+# A--------------main\n+#  \\            /\n+#   \\----------M2\n+#    \\        /\n+#     \\---M1-C\n+#      \\ /\n+#       B\n+test_expect_success 'name-rev covers all conditions while looking at parents' '\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\n+\t\techo A >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m A &&\n+\t\tA=$(git rev-parse HEAD) &&\n+\n+\t\tgit checkout --detach &&\n+\t\techo B >file &&\n+\t\tgit commit -m B file &&\n+\t\tB=$(git rev-parse HEAD) &&\n+\n+\t\tgit checkout $A &&\n+\t\tgit merge --no-ff $B &&  # M1\n+\n+\t\techo C >file &&\n+\t\tgit commit -m C file &&\n+\n+\t\tgit checkout $A &&\n+\t\tgit merge --no-ff HEAD@{1} && # M2\n+\n+\t\tgit checkout main &&\n+\t\tgit merge --no-ff HEAD@{1} &&\n+\n+\t\techo \"$B main^2^2~1^2\" >expect &&\n+\t\tgit name-rev $B >actual &&\n+\n+\t\ttest_cmp expect actual &&\n+\t\tgit sparse-checkout init --cone\n+\t)\n+'\n+\n+# A-B-C-D-E-main\n+#\n+# Where C has a non-monotonically increasing commit timestamp w.r.t. other\n+# commits\n+test_expect_success 'non-monotonic commit dates setup' '\n+\tUNIX_EPOCH_ZERO=\"@0 +0000\" &&\n+\tgit init non-monotonic &&\n+\ttest_commit -C non-monotonic A &&\n+\ttest_commit -C non-monotonic --no-tag B &&\n+\ttest_commit -C non-monotonic --no-tag --date \"$UNIX_EPOCH_ZERO\" C &&\n+\ttest_commit -C non-monotonic D &&\n+\ttest_commit -C non-monotonic E &&\n+\t(\n+\t\tcd non-monotonic &&\n+\t\tgit sparse-checkout init --cone\n+\t)\n+'\n+\n+test_expect_success 'name-rev with commitGraph handles non-monotonic timestamps' '\n+\ttest_config -C non-monotonic core.commitGraph true &&\n+\t(\n+\t\tcd non-monotonic &&\n+\n+\t\tgit commit-graph write --reachable &&\n+\n+\t\techo \"main~3 tags/D~2\" >expect &&\n+\t\tgit name-rev --tags main~3 >actual &&\n+\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'name-rev --all works with non-monotonic timestamps' '\n+\ttest_config -C non-monotonic core.commitGraph false &&\n+\t(\n+\t\tcd non-monotonic &&\n+\n+\t\trm -rf .git/info/commit-graph* &&\n+\n+\t\tcat >tags <<-\\EOF &&\n+\t\ttags/E\n+\t\ttags/D\n+\t\ttags/D~1\n+\t\ttags/D~2\n+\t\ttags/A\n+\t\tEOF\n+\n+\t\tgit log --pretty=%H >revs &&\n+\n+\t\tpaste -d\" \" revs tags | sort >expect &&\n+\n+\t\tgit name-rev --tags --all | sort >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'name-rev --annotate-stdin works with non-monotonic timestamps' '\n+\ttest_config -C non-monotonic core.commitGraph false &&\n+\t(\n+\t\tcd non-monotonic &&\n+\n+\t\trm -rf .git/info/commit-graph* &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tE\n+\t\tD\n+\t\tD~1\n+\t\tD~2\n+\t\tA\n+\t\tEOF\n+\n+\t\tgit log --pretty=%H >revs &&\n+\t\tgit name-rev --tags --annotate-stdin --name-only <revs >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'name-rev --all works with commitGraph' '\n+\ttest_config -C non-monotonic core.commitGraph true &&\n+\t(\n+\t\tcd non-monotonic &&\n+\n+\t\tgit commit-graph write --reachable &&\n+\n+\t\tcat >tags <<-\\EOF &&\n+\t\ttags/E\n+\t\ttags/D\n+\t\ttags/D~1\n+\t\ttags/D~2\n+\t\ttags/A\n+\t\tEOF\n+\n+\t\tgit log --pretty=%H >revs &&\n+\n+\t\tpaste -d\" \" revs tags | sort >expect &&\n+\n+\t\tgit name-rev --tags --all | sort >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'name-rev --annotate-stdin works with commitGraph' '\n+\ttest_config -C non-monotonic core.commitGraph true &&\n+\t(\n+\t\tcd non-monotonic &&\n+\n+\t\tgit commit-graph write --reachable &&\n+\n+\t\tcat >expect <<-\\EOF &&\n+\t\tE\n+\t\tD\n+\t\tD~1\n+\t\tD~2\n+\t\tA\n+\t\tEOF\n+\n+\t\tgit log --pretty=%H >revs &&\n+\t\tgit name-rev --tags --annotate-stdin --name-only <revs >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+#               B\n+#               o\n+#                \\\n+#  o-----o---o----x\n+#        A\n+#\n+test_expect_success 'setup: describe commits with disjoint bases' '\n+\tgit init disjoint1 &&\n+\t(\n+\t\tcd disjoint1 &&\n+\n+\t\techo o >> file && git add file && git commit -m o &&\n+\t\techo A >> file && git add file && git commit -m A &&\n+\t\tgit tag A -a -m A &&\n+\t\techo o >> file && git add file && git commit -m o &&\n+\n+\t\tgit checkout --orphan branch && rm file &&\n+\t\techo B > file2 && git add file2 && git commit -m B &&\n+\t\tgit tag B -a -m B &&\n+\t\tgit merge --no-ff --allow-unrelated-histories main -m x &&\n+\t\tgit sparse-checkout init --cone\n+\t)\n+'\n+\n+check_describe -C disjoint1 \"A-3-gHASH\" HEAD\n+\n+#           B\n+#   o---o---o------------.\n+#                         \\\n+#                  o---o---x\n+#                  A\n+#\n+test_expect_success 'setup: describe commits with disjoint bases 2' '\n+\tgit init disjoint2 &&\n+\t(\n+\t\tcd disjoint2 &&\n+\n+\t\techo A >> file && git add file && GIT_COMMITTER_DATE=\"2020-01-01 18:00\" git commit -m A &&\n+\t\tgit tag A -a -m A &&\n+\t\techo o >> file && git add file && GIT_COMMITTER_DATE=\"2020-01-01 18:01\" git commit -m o &&\n+\n+\t\tgit checkout --orphan branch &&\n+\t\techo o >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:00\" git commit -m o &&\n+\t\techo o >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:01\" git commit -m o &&\n+\t\techo B >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:02\" git commit -m B &&\n+\t\tgit tag B -a -m B &&\n+\t\tgit merge --no-ff --allow-unrelated-histories main -m x &&\n+\t\tgit sparse-checkout init --cone\n+\t)\n+'\n+\n+check_describe -C disjoint2 \"B-3-gHASH\" HEAD\n+\n+test_expect_success 'setup misleading taggerdates' '\n+\tGIT_COMMITTER_DATE=\"2006-12-12 12:31\" git tag -a -m \"another tag\" newer-tag-older-commit unique-file~1\n+'\n+\n+check_describe newer-tag-older-commit~1 --contains unique-file~2\n+\n+test_done\n\nbase-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n-- \ngitgitgadget\n"},{"id":"474252","messageId":"xmqqjzz29hkw.fsf@gitster.g","threadId":"59483","inReplyTo":"pull.1480.git.git.1679926829475.gitgitgadget@gmail.com","subject":"Re: [PATCH] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-27T18:26:07Z","receivedAt":"2023-03-27T18:26:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Raghul Nanth A via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  builtin/describe.c                       |   2 +\n>  t/perf/p2000-sparse-operations.sh        |  14 +-\n>  t/t1092-sparse-checkout-compatibility.sh |  10 +\n>  t/t6121-describe-sparse.sh               | 675 +++++++++++++++++++++++\n>  4 files changed, 697 insertions(+), 4 deletions(-)\n>  create mode 100755 t/t6121-describe-sparse.sh\n\nThis copying of a file with 600+ lines only to touch up a handful\nlines (like a 20+ lines patch) is almost criminal.  Imagine the\neffort to keep them in sync over time, when \"describe\" itself may\nlearn new features and improved output, independent from the\nsparse-index compatibility.\n\nCan't we do better than this with a bit of refactoring?\n\n> diff --git a/builtin/describe.c b/builtin/describe.c\n> index 5b5930f5c8c..7ff9b5e4b20 100644\n> --- a/builtin/describe.c\n> +++ b/builtin/describe.c\n> @@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>  \t\t\tint fd, result;\n>  \n>  \t\t\tsetup_work_tree();\n> +\t\t\tprepare_repo_settings(the_repository);\n> +\t\t\tthe_repository->settings.command_requires_full_index = 0;\n\nOffhand, the only case I know that \"describe\" even _needs_ a working\ntree or the index is when asked to do the \"--dirty\" thing.  To\nfigure out if the working tree files are modified, the code calls\ninto run_diff_index(), but has that codepath been made sparse-index\naware already?\n\n> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\n> index 3242cfe91a0..a8a9ed79441 100755\n> --- a/t/perf/p2000-sparse-operations.sh\n> +++ b/t/perf/p2000-sparse-operations.sh\n> @@ -59,7 +59,8 @@ test_expect_success 'setup repo and indexes' '\n>  \t\tgit sparse-checkout set $SPARSE_CONE &&\n>  \t\tgit config index.version 3 &&\n>  \t\tgit update-index --index-version=3 &&\n> -\t\tgit checkout HEAD~4\n> +\t\tgit checkout HEAD~4 &&\n> +\t\tgit tag -a v1.0 -m \"Final\"\n>  \t) &&\n>  \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&\n>  \t(\n> @@ -68,7 +69,8 @@ test_expect_success 'setup repo and indexes' '\n>  \t\tgit sparse-checkout set $SPARSE_CONE &&\n>  \t\tgit config index.version 4 &&\n>  \t\tgit update-index --index-version=4 &&\n> -\t\tgit checkout HEAD~4\n> +\t\tgit checkout HEAD~4 &&\n> +\t\tgit tag -a v1.0 -m \"Final\"\n>  \t) &&\n>  \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&\n>  \t(\n> @@ -77,7 +79,8 @@ test_expect_success 'setup repo and indexes' '\n>  \t\tgit sparse-checkout set $SPARSE_CONE &&\n>  \t\tgit config index.version 3 &&\n>  \t\tgit update-index --index-version=3 &&\n> -\t\tgit checkout HEAD~4\n> +\t\tgit checkout HEAD~4 &&\n> +\t\tgit tag -a v1.0 -m \"Final\"\n>  \t) &&\n>  \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&\n>  \t(\n> @@ -86,7 +89,8 @@ test_expect_success 'setup repo and indexes' '\n>  \t\tgit sparse-checkout set $SPARSE_CONE &&\n>  \t\tgit config index.version 4 &&\n>  \t\tgit update-index --index-version=4 &&\n> -\t\tgit checkout HEAD~4\n> +\t\tgit checkout HEAD~4 &&\n> +\t\tgit tag -a v1.0 -m \"Final\"\n>  \t)\n>  '\n\nIt is unclear from the proposed commit log what the relevance of\nadding a step to create an annotated tag to these tests.  It is not\nlike any later step uses that tag to figure out anything.  There may\nbe good reasons to add these tags (otherwise you would not be adding\nthem to these tests), but please explain why in the proposed log\nmessage so that future readers of the \"git log -p\" do not have to\nask this question.\n\n> @@ -125,5 +129,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 describe --dirty\n> +test_perf_on_all 'echo >> new && git describe --dirty'\n>  \n>  test_done\n\nJust like '>', '>>' is a rediraction operator and should have SP\nbefore it (you got it right) and no SP between it and its operand.\nI.e.\n\n\techo >>new && git describe --dirty\n\nYou have the same in t1092, I think.\n\n"},{"id":"474357","messageId":"ff521177-b0ad-c567-c51a-a6c191584d7c@github.com","threadId":"59483","inReplyTo":"xmqqjzz29hkw.fsf@gitster.g","subject":"Re: [PATCH] describe: enable sparse index for describe","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2023-03-28T19:46:38Z","receivedAt":"2023-03-28T19:46:43Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 3/27/23 2:26 PM, Junio C Hamano wrote:\n> \"Raghul Nanth A via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> \n>>  builtin/describe.c                       |   2 +\n>>  t/perf/p2000-sparse-operations.sh        |  14 +-\n>>  t/t1092-sparse-checkout-compatibility.sh |  10 +\n>>  t/t6121-describe-sparse.sh               | 675 +++++++++++++++++++++++\n>>  4 files changed, 697 insertions(+), 4 deletions(-)\n>>  create mode 100755 t/t6121-describe-sparse.sh\n> \n> This copying of a file with 600+ lines only to touch up a handful\n> lines (like a 20+ lines patch) is almost criminal.  Imagine the\n> effort to keep them in sync over time, when \"describe\" itself may\n> learn new features and improved output, independent from the\n> sparse-index compatibility.\n> \n> Can't we do better than this with a bit of refactoring?\n> \n>> diff --git a/builtin/describe.c b/builtin/describe.c\n>> index 5b5930f5c8c..7ff9b5e4b20 100644\n>> --- a/builtin/describe.c\n>> +++ b/builtin/describe.c\n>> @@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>>  \t\t\tint fd, result;\n>>  \n>>  \t\t\tsetup_work_tree();\n>> +\t\t\tprepare_repo_settings(the_repository);\n>> +\t\t\tthe_repository->settings.command_requires_full_index = 0;\n> \n> Offhand, the only case I know that \"describe\" even _needs_ a working\n> tree or the index is when asked to do the \"--dirty\" thing.  To\n> figure out if the working tree files are modified, the code calls\n> into run_diff_index(), but has that codepath been made sparse-index\n> aware already?\n\nIt seems that this is a case where we can rely on the existing\nchanges around run_diff_index(), which is nice. We get a very\neasy win for a narrow case.\n\nAnd I agree about the test case situation. It would suffice to\nshow some checks that the result is the same across all cases\nin t1092 for 'git describe --dirty'. Those should be the only\nnew correctness tests necessary for this change.\n\n>> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\n\n>> @@ -86,7 +89,8 @@ test_expect_success 'setup repo and indexes' '\n>>  \t\tgit sparse-checkout set $SPARSE_CONE &&\n>>  \t\tgit config index.version 4 &&\n>>  \t\tgit update-index --index-version=4 &&\n>> -\t\tgit checkout HEAD~4\n>> +\t\tgit checkout HEAD~4 &&\n>> +\t\tgit tag -a v1.0 -m \"Final\"\n>>  \t)\n>>  '\n> \n> It is unclear from the proposed commit log what the relevance of\n> adding a step to create an annotated tag to these tests.  It is not\n> like any later step uses that tag to figure out anything.  There may\n> be good reasons to add these tags (otherwise you would not be adding\n> them to these tests), but please explain why in the proposed log\n> message so that future readers of the \"git log -p\" do not have to\n> ask this question.\n\nI imagine that 'git describe' reports something better when a tag\nis reachable from HEAD. Would be good to make that clear.\n\nIndeed, when removing these lines and running the test on a repo\nwithout any tags, the test fails with this message:\n\n  fatal: No names found, cannot describe anything.\n\nThese tags could be added earlier in the test, in one step:\n\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a0..ba13317c942 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -45,6 +45,7 @@ test_expect_success 'setup repo and indexes' '\n \tgit sparse-checkout init --cone &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n+\tgit tag -a v1.0 -m \"final\" &&\n \n \tfor l2 in f1 f2 f3 f4\n \tdo\n\nThe tests then run on the four examples cloned from this copy.\n\n>> @@ -125,5 +129,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 describe --dirty\n>> +test_perf_on_all 'echo >> new && git describe --dirty'\n>>  \n>>  test_done\n> \n> Just like '>', '>>' is a rediraction operator and should have SP\n> before it (you got it right) and no SP between it and its operand.\n> I.e.\n> \n> \techo >>new && git describe --dirty\n> \n> You have the same in t1092, I think.\n\nAlso, since you are adding these performance tests, it would be\nnice to see their results in the commit message. You can get\nvalues without and with this change using (from t/perf/):\n\nGIT_PERF_REPEAT_COUNT=10 ./run HEAD~1 HEAD -- p2000-sparse-operations.sh\n\nFor example, I ran this on my machine (after deleting the other tests\nso it ran faster) and got these results:\n\nTest                                                      HEAD~1            HEAD                  \n--------------------------------------------------------------------------------------------------\n2000.2: git describe --dirty (full-v3)                    0.36(0.07+0.32)   0.45(0.08+0.37) +25.0%\n2000.3: git describe --dirty (full-v4)                    0.39(0.08+0.32)   0.42(0.08+0.35) +7.7% \n2000.4: git describe --dirty (sparse-v3)                  1.49(0.91+0.58)   0.33(0.04+0.59) -77.9%\n2000.5: git describe --dirty (sparse-v4)                  1.48(0.92+0.57)   0.34(0.04+0.60) -77.0%\n2000.6: echo >> new && git describe --dirty (full-v3)     0.37(0.07+0.32)   0.44(0.08+0.36) +18.9%\n2000.7: echo >> new && git describe --dirty (full-v4)     0.40(0.08+0.32)   0.42(0.08+0.36) +5.0% \n2000.8: echo >> new && git describe --dirty (sparse-v3)   1.59(0.97+0.62)   0.33(0.04+0.57) -79.2%\n2000.9: echo >> new && git describe --dirty (sparse-v4)   1.64(0.98+0.64)   0.31(0.03+0.54) -81.1%\n\nThanks,\n-Stolee\n"},{"id":"474365","messageId":"xmqqo7oceiab.fsf@gitster.g","threadId":"59483","inReplyTo":"ff521177-b0ad-c567-c51a-a6c191584d7c@github.com","subject":"Re: [PATCH] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-28T20:24:12Z","receivedAt":"2023-03-28T20:24:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <derrickstolee@github.com> writes:\n\n>>>  \t\t\tsetup_work_tree();\n>>> +\t\t\tprepare_repo_settings(the_repository);\n>>> +\t\t\tthe_repository->settings.command_requires_full_index = 0;\n>> \n>> Offhand, the only case I know that \"describe\" even _needs_ a working\n>> tree or the index is when asked to do the \"--dirty\" thing.  To\n>> figure out if the working tree files are modified, the code calls\n>> into run_diff_index(), but has that codepath been made sparse-index\n>> aware already?\n>\n> It seems that this is a case where we can rely on the existing\n> changes around run_diff_index(), which is nice. We get a very\n> easy win for a narrow case.\n\nHmph, so \"diff-index\" is already sparse-index aware?  I looked for\nany old commit that flips .command_requires_full_index to false for\nthe command and didn't find it, and if I recall correctly (I only\nchecked when I wrote the comment you are responding to),\ncmd_diff_index() does not do that, either, so I assumed that nobody\nhas converted run_diff_index() yet.  And that was where my question\ncame from.\n\nThanks.\n"},{"id":"474368","messageId":"2c420712-148e-65a4-2aea-9cfdc920ce2f@github.com","threadId":"59483","inReplyTo":"xmqqo7oceiab.fsf@gitster.g","subject":"Re: [PATCH] describe: enable sparse index for describe","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2023-03-28T20:35:06Z","receivedAt":"2023-03-28T20:35:11Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 3/28/23 4:24 PM, Junio C Hamano wrote:\n> Derrick Stolee <derrickstolee@github.com> writes:\n> \n>>>>  \t\t\tsetup_work_tree();\n>>>> +\t\t\tprepare_repo_settings(the_repository);\n>>>> +\t\t\tthe_repository->settings.command_requires_full_index = 0;\n>>>\n>>> Offhand, the only case I know that \"describe\" even _needs_ a working\n>>> tree or the index is when asked to do the \"--dirty\" thing.  To\n>>> figure out if the working tree files are modified, the code calls\n>>> into run_diff_index(), but has that codepath been made sparse-index\n>>> aware already?\n>>\n>> It seems that this is a case where we can rely on the existing\n>> changes around run_diff_index(), which is nice. We get a very\n>> easy win for a narrow case.\n> \n> Hmph, so \"diff-index\" is already sparse-index aware?  I looked for\n> any old commit that flips .command_requires_full_index to false for\n> the command and didn't find it, and if I recall correctly (I only\n> checked when I wrote the comment you are responding to),\n> cmd_diff_index() does not do that, either, so I assumed that nobody\n> has converted run_diff_index() yet.  And that was where my question\n> came from.\n\nSince 'git diff --cached' is covered as of 51ba65b5c35 (diff:\nenable and test the sparse index, 2021-12-06), that means that\nthe implementation run_diff_index() is covered.\n\nIn fact, it's likely that the reason it's covered is because\nrun_diff_index() calls diff_cache() which calls unpack_trees() and\nunpack_trees() needs to work for _anything_ to work, especially\n'git status' and 'git checkout'.\n\nThe only thing keeping us from enabling the sparse index on many\nof these \"diff\" builtins is the necessary testing in t1092. I'm\nsure that diff-index is very easy to convert. Hopefully, we will\nhave a GSoC student this summer who can tackle most of these easy\nones, as well as a tricky one or two.\n\nThanks,\n-Stolee\n"},{"id":"474413","messageId":"pull.1480.v2.git.git.1680107154078.gitgitgadget@gmail.com","threadId":"59483","inReplyTo":"pull.1480.git.git.1679926829475.gitgitgadget@gmail.com","subject":"[PATCH v2] describe: enable sparse index for describe","fromName":"Raghul Nanth A via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-03-29T16:25:53Z","receivedAt":"2023-03-29T16:26:02Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"From: Raghul Nanth A <nanth.raghul@gmail.com>\n\nAdd usage and performance tests for describe\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n    describe: enable sparse index for describe\n    \n     * Removed describe tests not concerned with sparse index\n    \n     * Added performance metric to commit message\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1480%2FNanthR%2Fdescribe-sparse-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1480/NanthR/describe-sparse-v2\nPull-Request: https://github.com/git/git/pull/1480\n\nRange-diff vs v1:\n\n 1:  4689f6512db ! 1:  03176f64607 describe: enable sparse index for describe\n     @@ Commit message\n      \n          Add usage and performance tests for describe\n      \n     +    Performance metrics\n     +\n     +      Test                                                     HEAD~1            HEAD\n     +      -------------------------------------------------------------------------------------------------\n     +      2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n     +      2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n     +      2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n     +      2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n     +      2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n     +      2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n     +      2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n     +      2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n     +\n          Signed-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n      \n       ## builtin/describe.c ##\n     @@ builtin/describe.c: int cmd_describe(int argc, const char **argv, const char *pr\n      \n       ## t/perf/p2000-sparse-operations.sh ##\n      @@ t/perf/p2000-sparse-operations.sh: test_expect_success 'setup repo and indexes' '\n     - \t\tgit sparse-checkout set $SPARSE_CONE &&\n     - \t\tgit config index.version 3 &&\n     - \t\tgit update-index --index-version=3 &&\n     --\t\tgit checkout HEAD~4\n     -+\t\tgit checkout HEAD~4 &&\n     -+\t\tgit tag -a v1.0 -m \"Final\"\n     - \t) &&\n     - \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&\n     - \t(\n     -@@ t/perf/p2000-sparse-operations.sh: test_expect_success 'setup repo and indexes' '\n     - \t\tgit sparse-checkout set $SPARSE_CONE &&\n     - \t\tgit config index.version 4 &&\n     - \t\tgit update-index --index-version=4 &&\n     --\t\tgit checkout HEAD~4\n     -+\t\tgit checkout HEAD~4 &&\n     -+\t\tgit tag -a v1.0 -m \"Final\"\n     - \t) &&\n     - \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&\n     - \t(\n     -@@ t/perf/p2000-sparse-operations.sh: test_expect_success 'setup repo and indexes' '\n     - \t\tgit sparse-checkout set $SPARSE_CONE &&\n     - \t\tgit config index.version 3 &&\n     - \t\tgit update-index --index-version=3 &&\n     --\t\tgit checkout HEAD~4\n     -+\t\tgit checkout HEAD~4 &&\n     -+\t\tgit tag -a v1.0 -m \"Final\"\n     - \t) &&\n     - \tgit -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&\n     - \t(\n     -@@ t/perf/p2000-sparse-operations.sh: test_expect_success 'setup repo and indexes' '\n     - \t\tgit sparse-checkout set $SPARSE_CONE &&\n     - \t\tgit config index.version 4 &&\n     - \t\tgit update-index --index-version=4 &&\n     --\t\tgit checkout HEAD~4\n     -+\t\tgit checkout HEAD~4 &&\n     -+\t\tgit tag -a v1.0 -m \"Final\"\n     - \t)\n     - '\n     + \tdone &&\n     + \n     + \tgit sparse-checkout init --cone &&\n     ++\tgit tag -a v1.0 -m \"Final\" &&\n     + \tgit sparse-checkout set $SPARSE_CONE &&\n     + \tgit checkout -b wide $OLD_COMMIT &&\n       \n      @@ t/perf/p2000-sparse-operations.sh: 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 describe --dirty\n     -+test_perf_on_all 'echo >> new && git describe --dirty'\n     ++test_perf_on_all 'echo >>new && git describe --dirty'\n       \n       test_done\n      \n     @@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n\n       \n      +test_expect_success 'sparse-index is not expanded: describe' '\n      +\tinit_repos &&\n     ++\t# Add tag to be read by describe\n      +\tensure_not_expanded tag -a v1.0 -m \"Version 1\" &&\n      +\tensure_not_expanded describe --dirty &&\n      +\tensure_not_expanded describe &&\n     -+\techo \"test\" >> sparse-index/extra.txt &&\n     ++\techo \"test\" >>sparse-index/extra.txt &&\n      +\tensure_not_expanded describe --dirty &&\n      +\tensure_not_expanded describe\n      +'\n     @@ t/t6121-describe-sparse.sh (new)\n      +\n      +test_description='git describe in sparse checked out trees'\n      +\n     -+#  o---o-----o----o----o-------o----x\n     -+#       \\   D,R   e           /\n     -+#        \\---o-------------o-'\n     -+#         \\  B            /\n     -+#          `-o----o----o-'\n     -+#                 A    c\n     -+#\n     -+# First parent of a merge commit is on the same line, second parent below.\n     -+\n      +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n      +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n      +\n     @@ t/t6121-describe-sparse.sh (new)\n      +\tshift\n      +\tdescribe_opts=\"$@\"\n      +\ttest_expect_success \"describe $describe_opts\" '\n     -+\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >raw &&\n     -+\t\tsed -e \"s/-g[0-9a-f]*\\$/-gHASH/\" <raw >actual &&\n     ++\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >actual &&\n      +\t\techo \"$expect\" >expect &&\n      +\t\ttest_cmp expect actual\n      +\t'\n     @@ t/t6121-describe-sparse.sh (new)\n      +\n      +test_expect_success setup '\n      +\ttest_commit initial file one &&\n     -+\ttest_commit second file two &&\n     -+\ttest_commit third file three &&\n      +\ttest_commit --annotate A file A &&\n     -+\ttest_commit c file c &&\n     -+\n     -+\tgit reset --hard second &&\n     -+\ttest_commit --annotate B side B &&\n     -+\n     -+\ttest_tick &&\n     -+\tgit merge -m Merged c &&\n     -+\tmerged=$(git rev-parse HEAD) &&\n     -+\n     -+\tgit reset --hard second &&\n     -+\ttest_commit --no-tag D another D &&\n      +\n      +\ttest_tick &&\n     -+\tgit tag -a -m R R &&\n      +\n     -+\ttest_commit e another DD &&\n     -+\ttest_commit --no-tag \"yet another\" another DDD &&\n     -+\n     -+\ttest_tick &&\n     -+\tgit merge -m Merged $merged &&\n     -+\n     -+\ttest_commit --no-tag x file &&\n      +\tgit sparse-checkout init --cone\n      +'\n      +\n     -+check_describe A-8-gHASH HEAD\n     -+check_describe A-7-gHASH HEAD^\n     -+check_describe R-2-gHASH HEAD^^\n     -+check_describe A-3-gHASH HEAD^^2\n     -+check_describe B HEAD^^2^\n     -+check_describe R-1-gHASH HEAD^^^\n     -+\n     -+check_describe c-7-gHASH --tags HEAD\n     -+check_describe c-6-gHASH --tags HEAD^\n     -+check_describe e-1-gHASH --tags HEAD^^\n     -+check_describe c-2-gHASH --tags HEAD^^2\n     -+check_describe B --tags HEAD^^2^\n     -+check_describe e --tags HEAD^^^\n     -+\n     -+check_describe heads/main --all HEAD\n     -+check_describe tags/c-6-gHASH --all HEAD^\n     -+check_describe tags/e --all HEAD^^^\n     -+\n     -+check_describe B-0-gHASH --long HEAD^^2^\n     -+check_describe A-3-gHASH --long HEAD^^2\n     -+\n     -+check_describe c-7-gHASH --tags\n     -+check_describe e-3-gHASH --first-parent --tags\n     -+\n     -+test_expect_success 'describe --contains defaults to HEAD without commit-ish' '\n     -+\techo \"A^0\" >expect &&\n     -+\tgit checkout A &&\n     -+\ttest_when_finished \"git checkout -\" &&\n     -+\tgit describe --contains >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+check_describe tags/A --all A^0\n     -+\n     -+test_expect_success 'renaming tag A to Q locally produces a warning' \"\n     -+\tgit update-ref refs/tags/Q $(git rev-parse refs/tags/A) &&\n     -+\tgit update-ref -d refs/tags/A &&\n     -+\tgit describe HEAD 2>err >out &&\n     -+\tcat >expected <<-\\EOF &&\n     -+\twarning: tag 'Q' is externally known as 'A'\n     -+\tEOF\n     -+\ttest_cmp expected err &&\n     -+\tgrep -E '^A-8-g[0-9a-f]+$' out\n     -+\"\n     -+\n     -+test_expect_success 'misnamed annotated tag forces long output' '\n     -+\tdescription=$(git describe --no-long Q^0) &&\n     -+\texpr \"$description\" : \"A-0-g[0-9a-f]*$\" &&\n     -+\tgit rev-parse --verify \"$description\" >actual &&\n     -+\tgit rev-parse --verify Q^0 >expect &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'abbrev=0 will not break misplaced tag (1)' '\n     -+\tdescription=$(git describe --abbrev=0 Q^0) &&\n     -+\texpr \"$description\" : \"A-0-g[0-9a-f]*$\"\n     -+'\n     -+\n     -+test_expect_success 'abbrev=0 will not break misplaced tag (2)' '\n     -+\tdescription=$(git describe --abbrev=0 c^0) &&\n     -+\texpr \"$description\" : \"A-1-g[0-9a-f]*$\"\n     -+'\n     -+\n     -+test_expect_success 'rename tag Q back to A' '\n     -+\tgit update-ref refs/tags/A $(git rev-parse refs/tags/Q) &&\n     -+\tgit update-ref -d refs/tags/Q\n     -+'\n     -+\n     -+test_expect_success 'pack tag refs' 'git pack-refs'\n     -+check_describe A-8-gHASH HEAD\n     -+\n     -+test_expect_success 'describe works from outside repo using --git-dir' '\n     -+\tgit clone --bare \"$TRASH_DIRECTORY\" \"$TRASH_DIRECTORY/bare\" &&\n     -+\tgit --git-dir \"$TRASH_DIRECTORY/bare\" describe >out &&\n     -+\tgrep -E \"^A-8-g[0-9a-f]+$\" out\n     -+'\n     -+\n     -+check_describe \"A-8-gHASH\" --dirty\n     ++check_describe A HEAD\n      +\n      +test_expect_success 'describe --dirty with --work-tree' '\n      +\t(\n      +\t\tcd \"$TEST_DIRECTORY\" &&\n      +\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n      +\t) &&\n     -+\tgrep -E \"^A-8-g[0-9a-f]+$\" out\n     ++\tgrep \"A\" out\n      +'\n      +\n      +test_expect_success 'set-up dirty work tree' '\n     @@ t/t6121-describe-sparse.sh (new)\n      +\t\tcd \"$TEST_DIRECTORY\" &&\n      +\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n      +\t) &&\n     -+\tgrep -E \"^A-8-g[0-9a-f]+-dirty$\" out &&\n     -+\ttest_cmp expected out\n     -+'\n     -+\n     -+test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '\n     -+\tgit describe --dirty=.mod >expected &&\n     -+\t(\n     -+\t\tcd \"$TEST_DIRECTORY\" &&\n     -+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty=.mod >\"$TRASH_DIRECTORY/out\"\n     -+\t) &&\n     -+\tgrep -E \"^A-8-g[0-9a-f]+.mod$\" out &&\n      +\ttest_cmp expected out\n      +'\n     -+\n     -+test_expect_success 'describe --dirty HEAD' '\n     -+\ttest_must_fail git describe --dirty HEAD\n     -+'\n     -+\n     -+test_expect_success 'set-up matching pattern tests' '\n     -+\tgit tag -a -m test-annotated test-annotated &&\n     -+\techo >>file &&\n     -+\ttest_tick &&\n     -+\tgit commit -a -m \"one more\" &&\n     -+\tgit tag test1-lightweight &&\n     -+\techo >>file &&\n     -+\ttest_tick &&\n     -+\tgit commit -a -m \"yet another\" &&\n     -+\tgit tag test2-lightweight &&\n     -+\techo >>file &&\n     -+\ttest_tick &&\n     -+\tgit commit -a -m \"even more\"\n     -+\n     -+'\n     -+\n     -+check_describe \"test-annotated-3-gHASH\" --match=\"test-*\"\n     -+\n     -+check_describe \"test1-lightweight-2-gHASH\" --tags --match=\"test1-*\"\n     -+\n     -+check_describe \"test2-lightweight-1-gHASH\" --tags --match=\"test2-*\"\n     -+\n     -+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test2-*\" HEAD^\n     -+\n     -+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test1-*\" --match=\"test2-*\" HEAD^\n     -+\n     -+check_describe \"test2-lightweight-0-gHASH\" --long --tags --match=\"test1-*\" --no-match --match=\"test2-*\" HEAD^\n     -+\n     -+check_describe \"test1-lightweight-2-gHASH\" --long --tags --match=\"test1-*\" --match=\"test3-*\" HEAD\n     -+\n     -+check_describe \"test1-lightweight-2-gHASH\" --long --tags --match=\"test3-*\" --match=\"test1-*\" HEAD\n     -+\n     -+test_expect_success 'set-up branches' '\n     -+\tgit branch branch_A A &&\n     -+\tgit branch branch_C c &&\n     -+\tgit update-ref refs/remotes/origin/remote_branch_A \"A^{commit}\" &&\n     -+\tgit update-ref refs/remotes/origin/remote_branch_C \"c^{commit}\" &&\n     -+\tgit update-ref refs/original/original_branch_A test-annotated~2\n     -+'\n     -+\n     -+check_describe \"heads/branch_A-11-gHASH\" --all --match=\"branch_*\" --exclude=\"branch_C\" HEAD\n     -+\n     -+check_describe \"remotes/origin/remote_branch_A-11-gHASH\" --all --match=\"origin/remote_branch_*\" --exclude=\"origin/remote_branch_C\" HEAD\n     -+\n     -+check_describe \"original/original_branch_A-6-gHASH\" --all test-annotated~1\n     -+\n     -+test_expect_success '--match does not work for other types' '\n     -+\ttest_must_fail git describe --all --match=\"*original_branch_*\" test-annotated~1\n     -+'\n     -+\n     -+test_expect_success '--exclude does not work for other types' '\n     -+\tR=$(git describe --all --exclude=\"any_pattern_even_not_matching\" test-annotated~1) &&\n     -+\tcase \"$R\" in\n     -+\t*original_branch_A*) echo \"fail: Found unknown reference $R with --exclude\"\n     -+\t\tfalse;;\n     -+\t*) echo ok: Found some known type;;\n     -+\tesac\n     -+'\n     -+\n     -+test_expect_success 'name-rev with exact tags' '\n     -+\techo A >expect &&\n     -+\ttag_object=$(git rev-parse refs/tags/A) &&\n     -+\tgit name-rev --tags --name-only $tag_object >actual &&\n     -+\ttest_cmp expect actual &&\n     -+\n     -+\techo \"A^0\" >expect &&\n     -+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n     -+\tgit name-rev --tags --name-only $tagged_commit >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'name-rev --all' '\n     -+\t>expect.unsorted &&\n     -+\tfor rev in $(git rev-list --all)\n     -+\tdo\n     -+\t\tgit name-rev $rev >>expect.unsorted || return 1\n     -+\tdone &&\n     -+\tsort <expect.unsorted >expect &&\n     -+\tgit name-rev --all >actual.unsorted &&\n     -+\tsort <actual.unsorted >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'name-rev --annotate-stdin' '\n     -+\t>expect.unsorted &&\n     -+\tfor rev in $(git rev-list --all)\n     -+\tdo\n     -+\t\tname=$(git name-rev --name-only $rev) &&\n     -+\t\techo \"$rev ($name)\" >>expect.unsorted || return 1\n     -+\tdone &&\n     -+\tsort <expect.unsorted >expect &&\n     -+\tgit rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&\n     -+\tsort <actual.unsorted >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'name-rev --stdin deprecated' \"\n     -+\tgit rev-list --all | git name-rev --stdin 2>actual &&\n     -+\tgrep -E 'warning: --stdin is deprecated' actual\n     -+\"\n     -+\n     -+test_expect_success 'describe --contains with the exact tags' '\n     -+\techo \"A^0\" >expect &&\n     -+\ttag_object=$(git rev-parse refs/tags/A) &&\n     -+\tgit describe --contains $tag_object >actual &&\n     -+\ttest_cmp expect actual &&\n     -+\n     -+\techo \"A^0\" >expect &&\n     -+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n     -+\tgit describe --contains $tagged_commit >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe --contains and --match' '\n     -+\techo \"A^0\" >expect &&\n     -+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n     -+\ttest_must_fail git describe --contains --match=\"B\" $tagged_commit &&\n     -+\tgit describe --contains --match=\"B\" --match=\"A\" $tagged_commit >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe --exclude' '\n     -+\techo \"c~1\" >expect &&\n     -+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n     -+\ttest_must_fail git describe --contains --match=\"B\" $tagged_commit &&\n     -+\tgit describe --contains --match=\"?\" --exclude=\"A\" $tagged_commit >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe --contains and --no-match' '\n     -+\techo \"A^0\" >expect &&\n     -+\ttagged_commit=$(git rev-parse \"refs/tags/A^0\") &&\n     -+\tgit describe --contains --match=\"B\" --no-match $tagged_commit >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'setup and absorb a submodule' '\n     -+\tgit init sub1 &&\n     -+\ttest_commit -C sub1 initial &&\n     -+\tgit sparse-checkout add sub1 &&\n     -+\tgit submodule add ./sub1 &&\n     -+\tgit submodule absorbgitdirs &&\n     -+\tgit commit -a -m \"add submodule\" &&\n     -+\tgit describe --dirty >expect &&\n     -+\tgit describe --broken >out &&\n     -+\ttest_cmp expect out\n     -+'\n     -+\n     -+test_expect_success 'describe chokes on severely broken submodules' '\n     -+\tmv .git/modules/sub1/ .git/modules/sub_moved &&\n     -+\ttest_must_fail git describe --dirty\n     -+'\n     -+\n     -+test_expect_success 'describe ignoring a broken submodule' '\n     -+\tgit describe --broken >out &&\n     -+\tgrep broken out\n     -+'\n     -+\n     -+test_expect_success 'describe with --work-tree ignoring a broken submodule' '\n     -+\t(\n     -+\t\tcd \"$TEST_DIRECTORY\" &&\n     -+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --broken >\"$TRASH_DIRECTORY/out\"\n     -+\t) &&\n     -+\ttest_when_finished \"mv .git/modules/sub_moved .git/modules/sub1\" &&\n     -+\tgrep broken out\n     -+'\n     -+\n     -+test_expect_success 'describe a blob at a directly tagged commit' '\n     -+\techo \"make it a unique blob\" >file &&\n     -+\tgit add file && git commit -m \"content in file\" &&\n     -+\tgit tag -a -m \"latest annotated tag\" unique-file &&\n     -+\tgit describe HEAD:file >actual &&\n     -+\techo \"unique-file:file\" >expect &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe a blob with its first introduction' '\n     -+\tgit commit --allow-empty -m \"empty commit\" &&\n     -+\tgit rm file &&\n     -+\tgit commit -m \"delete blob\" &&\n     -+\tgit revert HEAD &&\n     -+\tgit commit --allow-empty -m \"empty commit\" &&\n     -+\tgit describe HEAD:file >actual &&\n     -+\techo \"unique-file:file\" >expect &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe directly tagged blob' '\n     -+\tgit tag test-blob unique-file:file &&\n     -+\tgit describe test-blob >actual &&\n     -+\techo \"unique-file:file\" >expect &&\n     -+\t# suboptimal: we rather want to see \"test-blob\"\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'describe tag object' '\n     -+\tgit tag test-blob-1 -a -m msg unique-file:file &&\n     -+\ttest_must_fail git describe test-blob-1 2>actual &&\n     -+\ttest_i18ngrep \"fatal: test-blob-1 is neither a commit nor blob\" actual\n     -+'\n     -+\n     -+test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '\n     -+\ti=1 &&\n     -+\twhile test $i -lt 8000\n     -+\tdo\n     -+\t\techo \"commit refs/heads/main\n     -+committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200\n     -+data <<EOF\n     -+commit #$i\n     -+EOF\" &&\n     -+\t\tif test $i = 1\n     -+\t\tthen\n     -+\t\t\techo \"from refs/heads/main^0\"\n     -+\t\tfi &&\n     -+\t\ti=$(($i + 1)) || return 1\n     -+\tdone | git fast-import &&\n     -+\tgit checkout main &&\n     -+\tgit tag far-far-away HEAD^ &&\n     -+\techo \"HEAD~4000 tags/far-far-away~3999\" >expect &&\n     -+\tgit name-rev HEAD~4000 >actual &&\n     -+\ttest_cmp expect actual &&\n     -+\trun_with_limited_stack git name-rev HEAD~4000 >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' '\n     -+\tgit tag -f far-far-away HEAD~7999 &&\n     -+\techo \"far-far-away\" >expect &&\n     -+\tgit describe --tags --abbrev=0 HEAD~4000 >actual &&\n     -+\ttest_cmp expect actual &&\n     -+\trun_with_limited_stack git describe --tags --abbrev=0 HEAD~4000 >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+check_describe tags/A --all A\n     -+check_describe tags/c --all c\n     -+check_describe heads/branch_A --all --match='branch_*' branch_A\n     -+\n     -+test_expect_success 'describe complains about tree object' '\n     -+\ttest_must_fail git describe HEAD^{tree}\n     -+'\n     -+\n     -+test_expect_success 'describe complains about missing object' '\n     -+\ttest_must_fail git describe $ZERO_OID\n     -+'\n     -+\n     -+test_expect_success 'name-rev a rev shortly after epoch' '\n     -+\ttest_when_finished \"git checkout main\" &&\n     -+\n     -+\tgit checkout --orphan no-timestamp-underflow &&\n     -+\t# Any date closer to epoch than the CUTOFF_DATE_SLOP constant\n     -+\t# in builtin/name-rev.c.\n     -+\tGIT_COMMITTER_DATE=\"@1234 +0000\" \\\n     -+\tgit commit -m \"committer date shortly after epoch\" &&\n     -+\told_commit_oid=$(git rev-parse HEAD) &&\n     -+\n     -+\techo \"$old_commit_oid no-timestamp-underflow\" >expect &&\n     -+\tgit name-rev $old_commit_oid >actual &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+# A--------------main\n     -+#  \\            /\n     -+#   \\----------M2\n     -+#    \\        /\n     -+#     \\---M1-C\n     -+#      \\ /\n     -+#       B\n     -+test_expect_success 'name-rev covers all conditions while looking at parents' '\n     -+\tgit init repo &&\n     -+\t(\n     -+\t\tcd repo &&\n     -+\n     -+\t\techo A >file &&\n     -+\t\tgit add file &&\n     -+\t\tgit commit -m A &&\n     -+\t\tA=$(git rev-parse HEAD) &&\n     -+\n     -+\t\tgit checkout --detach &&\n     -+\t\techo B >file &&\n     -+\t\tgit commit -m B file &&\n     -+\t\tB=$(git rev-parse HEAD) &&\n     -+\n     -+\t\tgit checkout $A &&\n     -+\t\tgit merge --no-ff $B &&  # M1\n     -+\n     -+\t\techo C >file &&\n     -+\t\tgit commit -m C file &&\n     -+\n     -+\t\tgit checkout $A &&\n     -+\t\tgit merge --no-ff HEAD@{1} && # M2\n     -+\n     -+\t\tgit checkout main &&\n     -+\t\tgit merge --no-ff HEAD@{1} &&\n     -+\n     -+\t\techo \"$B main^2^2~1^2\" >expect &&\n     -+\t\tgit name-rev $B >actual &&\n     -+\n     -+\t\ttest_cmp expect actual &&\n     -+\t\tgit sparse-checkout init --cone\n     -+\t)\n     -+'\n     -+\n     -+# A-B-C-D-E-main\n     -+#\n     -+# Where C has a non-monotonically increasing commit timestamp w.r.t. other\n     -+# commits\n     -+test_expect_success 'non-monotonic commit dates setup' '\n     -+\tUNIX_EPOCH_ZERO=\"@0 +0000\" &&\n     -+\tgit init non-monotonic &&\n     -+\ttest_commit -C non-monotonic A &&\n     -+\ttest_commit -C non-monotonic --no-tag B &&\n     -+\ttest_commit -C non-monotonic --no-tag --date \"$UNIX_EPOCH_ZERO\" C &&\n     -+\ttest_commit -C non-monotonic D &&\n     -+\ttest_commit -C non-monotonic E &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\t\tgit sparse-checkout init --cone\n     -+\t)\n     -+'\n     -+\n     -+test_expect_success 'name-rev with commitGraph handles non-monotonic timestamps' '\n     -+\ttest_config -C non-monotonic core.commitGraph true &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\n     -+\t\tgit commit-graph write --reachable &&\n     -+\n     -+\t\techo \"main~3 tags/D~2\" >expect &&\n     -+\t\tgit name-rev --tags main~3 >actual &&\n     -+\n     -+\t\ttest_cmp expect actual\n     -+\t)\n     -+'\n     -+\n     -+test_expect_success 'name-rev --all works with non-monotonic timestamps' '\n     -+\ttest_config -C non-monotonic core.commitGraph false &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\n     -+\t\trm -rf .git/info/commit-graph* &&\n     -+\n     -+\t\tcat >tags <<-\\EOF &&\n     -+\t\ttags/E\n     -+\t\ttags/D\n     -+\t\ttags/D~1\n     -+\t\ttags/D~2\n     -+\t\ttags/A\n     -+\t\tEOF\n     -+\n     -+\t\tgit log --pretty=%H >revs &&\n     -+\n     -+\t\tpaste -d\" \" revs tags | sort >expect &&\n     -+\n     -+\t\tgit name-rev --tags --all | sort >actual &&\n     -+\t\ttest_cmp expect actual\n     -+\t)\n     -+'\n     -+\n     -+test_expect_success 'name-rev --annotate-stdin works with non-monotonic timestamps' '\n     -+\ttest_config -C non-monotonic core.commitGraph false &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\n     -+\t\trm -rf .git/info/commit-graph* &&\n     -+\n     -+\t\tcat >expect <<-\\EOF &&\n     -+\t\tE\n     -+\t\tD\n     -+\t\tD~1\n     -+\t\tD~2\n     -+\t\tA\n     -+\t\tEOF\n     -+\n     -+\t\tgit log --pretty=%H >revs &&\n     -+\t\tgit name-rev --tags --annotate-stdin --name-only <revs >actual &&\n     -+\t\ttest_cmp expect actual\n     -+\t)\n     -+'\n     -+\n     -+test_expect_success 'name-rev --all works with commitGraph' '\n     -+\ttest_config -C non-monotonic core.commitGraph true &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\n     -+\t\tgit commit-graph write --reachable &&\n     -+\n     -+\t\tcat >tags <<-\\EOF &&\n     -+\t\ttags/E\n     -+\t\ttags/D\n     -+\t\ttags/D~1\n     -+\t\ttags/D~2\n     -+\t\ttags/A\n     -+\t\tEOF\n     -+\n     -+\t\tgit log --pretty=%H >revs &&\n     -+\n     -+\t\tpaste -d\" \" revs tags | sort >expect &&\n     -+\n     -+\t\tgit name-rev --tags --all | sort >actual &&\n     -+\t\ttest_cmp expect actual\n     -+\t)\n     -+'\n     -+\n     -+test_expect_success 'name-rev --annotate-stdin works with commitGraph' '\n     -+\ttest_config -C non-monotonic core.commitGraph true &&\n     -+\t(\n     -+\t\tcd non-monotonic &&\n     -+\n     -+\t\tgit commit-graph write --reachable &&\n     -+\n     -+\t\tcat >expect <<-\\EOF &&\n     -+\t\tE\n     -+\t\tD\n     -+\t\tD~1\n     -+\t\tD~2\n     -+\t\tA\n     -+\t\tEOF\n     -+\n     -+\t\tgit log --pretty=%H >revs &&\n     -+\t\tgit name-rev --tags --annotate-stdin --name-only <revs >actual &&\n     -+\t\ttest_cmp expect actual\n     -+\t)\n     -+'\n     -+\n     -+#               B\n     -+#               o\n     -+#                \\\n     -+#  o-----o---o----x\n     -+#        A\n     -+#\n     -+test_expect_success 'setup: describe commits with disjoint bases' '\n     -+\tgit init disjoint1 &&\n     -+\t(\n     -+\t\tcd disjoint1 &&\n     -+\n     -+\t\techo o >> file && git add file && git commit -m o &&\n     -+\t\techo A >> file && git add file && git commit -m A &&\n     -+\t\tgit tag A -a -m A &&\n     -+\t\techo o >> file && git add file && git commit -m o &&\n     -+\n     -+\t\tgit checkout --orphan branch && rm file &&\n     -+\t\techo B > file2 && git add file2 && git commit -m B &&\n     -+\t\tgit tag B -a -m B &&\n     -+\t\tgit merge --no-ff --allow-unrelated-histories main -m x &&\n     -+\t\tgit sparse-checkout init --cone\n     -+\t)\n     -+'\n     -+\n     -+check_describe -C disjoint1 \"A-3-gHASH\" HEAD\n     -+\n     -+#           B\n     -+#   o---o---o------------.\n     -+#                         \\\n     -+#                  o---o---x\n     -+#                  A\n     -+#\n     -+test_expect_success 'setup: describe commits with disjoint bases 2' '\n     -+\tgit init disjoint2 &&\n     -+\t(\n     -+\t\tcd disjoint2 &&\n     -+\n     -+\t\techo A >> file && git add file && GIT_COMMITTER_DATE=\"2020-01-01 18:00\" git commit -m A &&\n     -+\t\tgit tag A -a -m A &&\n     -+\t\techo o >> file && git add file && GIT_COMMITTER_DATE=\"2020-01-01 18:01\" git commit -m o &&\n     -+\n     -+\t\tgit checkout --orphan branch &&\n     -+\t\techo o >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:00\" git commit -m o &&\n     -+\t\techo o >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:01\" git commit -m o &&\n     -+\t\techo B >> file2 && git add file2 && GIT_COMMITTER_DATE=\"2020-01-01 15:02\" git commit -m B &&\n     -+\t\tgit tag B -a -m B &&\n     -+\t\tgit merge --no-ff --allow-unrelated-histories main -m x &&\n     -+\t\tgit sparse-checkout init --cone\n     -+\t)\n     -+'\n     -+\n     -+check_describe -C disjoint2 \"B-3-gHASH\" HEAD\n     -+\n     -+test_expect_success 'setup misleading taggerdates' '\n     -+\tGIT_COMMITTER_DATE=\"2006-12-12 12:31\" git tag -a -m \"another tag\" newer-tag-older-commit unique-file~1\n     -+'\n     -+\n     -+check_describe newer-tag-older-commit~1 --contains unique-file~2\n     -+\n      +test_done\n\n\n builtin/describe.c                       |  2 +\n t/perf/p2000-sparse-operations.sh        |  3 ++\n t/t1092-sparse-checkout-compatibility.sh | 11 ++++\n t/t6121-describe-sparse.sh               | 67 ++++++++++++++++++++++++\n 4 files changed, 83 insertions(+)\n create mode 100755 t/t6121-describe-sparse.sh\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8c..7ff9b5e4b20 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a0..db7887470f9 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e1..9a4db09178f 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,17 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\t# Add tag to be read by describe\n+\tensure_not_expanded tag -a v1.0 -m \"Version 1\" &&\n+\tensure_not_expanded describe --dirty &&\n+\tensure_not_expanded describe &&\n+\techo \"test\" >>sparse-index/extra.txt &&\n+\tensure_not_expanded describe --dirty &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \ndiff --git a/t/t6121-describe-sparse.sh b/t/t6121-describe-sparse.sh\nnew file mode 100755\nindex 00000000000..ce53603c387\n--- /dev/null\n+++ b/t/t6121-describe-sparse.sh\n@@ -0,0 +1,67 @@\n+#!/bin/sh\n+\n+test_description='git describe in sparse checked out trees'\n+\n+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n+\n+. ./test-lib.sh\n+\n+check_describe () {\n+\tindir= &&\n+\twhile test $# != 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-C)\n+\t\t\tindir=\"$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone &&\n+\tindir=${indir:+\"$indir\"/} &&\n+\texpect=\"$1\"\n+\tshift\n+\tdescribe_opts=\"$@\"\n+\ttest_expect_success \"describe $describe_opts\" '\n+\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >actual &&\n+\t\techo \"$expect\" >expect &&\n+\t\ttest_cmp expect actual\n+\t'\n+}\n+\n+test_expect_success setup '\n+\ttest_commit initial file one &&\n+\ttest_commit --annotate A file A &&\n+\n+\ttest_tick &&\n+\n+\tgit sparse-checkout init --cone\n+'\n+\n+check_describe A HEAD\n+\n+test_expect_success 'describe --dirty with --work-tree' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep \"A\" out\n+'\n+\n+test_expect_success 'set-up dirty work tree' '\n+\techo >>file\n+'\n+\n+test_expect_success 'describe --dirty with --work-tree (dirty)' '\n+\tgit describe --dirty >expected &&\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\ttest_cmp expected out\n+'\n+test_done\n\nbase-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n-- \ngitgitgadget\n"},{"id":"474414","messageId":"xmqq355nbii5.fsf@gitster.g","threadId":"59483","inReplyTo":"pull.1480.v2.git.git.1680107154078.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-29T17:00:02Z","receivedAt":"2023-03-29T17:00:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Raghul Nanth A via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Raghul Nanth A <nanth.raghul@gmail.com>\n>\n> Add usage and performance tests for describe\n>\n> Performance metrics\n> ...\n\nThe description is a bit skimpy.  At least it should explain why\nblindly flipping the \"requires-full-index\" bit off is all that is\nnecessary. I think in the review discussion on v1, Derrick gave some\nexplanation you can regurgitate and reuse.\n\n> Signed-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n> ...\n\n> diff --git a/t/t6121-describe-sparse.sh b/t/t6121-describe-sparse.sh\n> new file mode 100755\n> index 00000000000..ce53603c387\n> --- /dev/null\n> +++ b/t/t6121-describe-sparse.sh\n> @@ -0,0 +1,67 @@\n> +#!/bin/sh\n> +\n> +test_description='git describe in sparse checked out trees'\n> +\n> +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n> +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n> +\n> +. ./test-lib.sh\n> +\n> +check_describe () {\n> +\tindir= &&\n> +...\n> +\t'\n> +}\n\nHaving this almost identical helper copied from a near-by test\nscript means maintenance nightmare.  People will forget to side port\nto this copy any fixes they make to the other one.\n\nI was hoping there would be a cleaner approach to reuse t6120, by\ndoing something similar to either how t8001-annotate shares blame\ntests, or how t5559 takes advantage of t5551.  One way might be ...\n\n * prepare a prerequisite like so near the beginning of t6120\n\n\ttest_lazy_prereq WITH_SPARSE_INDEX '\n\t\ttest \"$TEST_NAME\" = t6121-describe\n\t'\n\n * add tests to be run with sparse-index enabled, but guarded with\n   some variable, e.g.\n\n\ttest_expect_success TESTING_SPARSE_INDEX 'a new test' '\n\t\t... do sparse-index testing specific code ...\n\t'\n\n   Such \"sparse-index testing specific\" code may include turning the\n   working tree the previous test already prepared into sparse\n   (i.e. additional \"setup\"), or running commands under\n   \"ensure_not_expanded\" (i.e. new tests).\n\n * create t6121 that works similar to how t5559 takes advantage of\n   t5551, something like\n\n\t#/bin/sh\n\t. ./t6120-describe.sh\n\nIdeally we should be able to do this without adding a new t6121, by\nadding new tests that are specific to sparse-index at the end of\nt6120, and avoid duplicated code.\n\nAnother possibility that may take the least amount of effort (but\nmay give us a lot less satisfactory outcome) may be to add a\nlib-describe.sh library that is sourced from t6120 and t6121, and\nmove check_describe there.  If check_describe has to behave slightly\ndifferently, have a new conditional in the implementation so that\nthe caller can make a choice.\n\n\n"},{"id":"474415","messageId":"8cb2b7a2-78f2-9221-1234-62814557d2d3@github.com","threadId":"59483","inReplyTo":"pull.1480.v2.git.git.1680107154078.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] describe: enable sparse index for describe","fromName":"Victoria Dye","fromEmail":"vdye@github.com","sentAt":"2023-03-29T17:49:38Z","receivedAt":"2023-03-29T17:49:44Z","isPatch":true,"sender":{"key":"vdye@github.com","avatar":"https://avatars.githubusercontent.com/u/3619353?v=4"},"body":"Raghul Nanth A via GitGitGadget wrote:\n> From: Raghul Nanth A <nanth.raghul@gmail.com>\n\nHello! Thanks for working on this patch, it's always nice to get more sparse\nindex support. Since this is your first contribution to the mailing list,\nthough, it's unclear to me whether you're working on this as an independent\ncontributor or if you're interested in the Google Summer of Code project\n\"More Sparse Index Integrations\" [1]. If you're doing this for GSoC, could\nyou please prefix the title of this patch with \"[GSoC]\" (as noted in the\napplication details [2])?\n\nOn the topic of GSoC applications - if you are submitting this for GSoC, I'm\na bit curious as to why you jumped right into sparse index rather than first\nsubmitting a microproject [3]. This is a good first pass at a sparse index\nintegration, but the microproject is a better way to get acquainted with the\nconventions and requirements of contributing to Git, hence the strong\nrecommendation to complete one first.\n\n[1] https://git.github.io/SoC-2023-Ideas/\n[2] https://git.github.io/General-Application-Information/\n[3] https://git.github.io/General-Microproject-Information/\n\n> \n> Add usage and performance tests for describe\n> \n> Performance metrics\n> \n>   Test                                                     HEAD~1            HEAD\n>   -------------------------------------------------------------------------------------------------\n>   2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n>   2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n>   2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n>   2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n>   2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n>   2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n>   2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n>   2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nAs Junio noted [4], this description doesn't provide much information to a\nreader. Commit messages should (at a minimum) explain what the code change\nin a commit does, as well as why it's necessary. \n\n[4] https://lore.kernel.org/git/xmqq355nbii5.fsf@gitster.g/ \n\n> \n> Signed-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n> ---\n>     describe: enable sparse index for describe\n>     \n>      * Removed describe tests not concerned with sparse index\n>     \n>      * Added performance metric to commit message\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1480%2FNanthR%2Fdescribe-sparse-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1480/NanthR/describe-sparse-v2\n> Pull-Request: https://github.com/git/git/pull/1480\n> \n>  builtin/describe.c                       |  2 +\n>  t/perf/p2000-sparse-operations.sh        |  3 ++\n>  t/t1092-sparse-checkout-compatibility.sh | 11 ++++\n>  t/t6121-describe-sparse.sh               | 67 ++++++++++++++++++++++++\n>  4 files changed, 83 insertions(+)\n>  create mode 100755 t/t6121-describe-sparse.sh\n> \n> diff --git a/builtin/describe.c b/builtin/describe.c\n> index 5b5930f5c8c..7ff9b5e4b20 100644\n> --- a/builtin/describe.c\n> +++ b/builtin/describe.c\n> @@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>  \t\t\tint fd, result;\n>  \n>  \t\t\tsetup_work_tree();\n> +\t\t\tprepare_repo_settings(the_repository);\n> +\t\t\tthe_repository->settings.command_requires_full_index = 0;\n\nLooks good.\n\n>  \t\t\trepo_read_index(the_repository);\n>  \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n>  \t\t\t\t      NULL, NULL, NULL);\n> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\n> index 3242cfe91a0..db7887470f9 100755\n> --- a/t/perf/p2000-sparse-operations.sh\n> +++ b/t/perf/p2000-sparse-operations.sh\n> @@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n>  \tdone &&\n>  \n>  \tgit sparse-checkout init --cone &&\n> +\tgit tag -a v1.0 -m \"Final\" &&\n\nThis isn't disruptive to the existing performance tests, but allows you to\neasily test 'git describe'. Nice!\n\n>  \tgit sparse-checkout set $SPARSE_CONE &&\n>  \tgit checkout -b wide $OLD_COMMIT &&\n>  \n> @@ -125,5 +126,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 describe --dirty\n> +test_perf_on_all 'echo >>new && git describe --dirty'\n>  \n>  test_done\n> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\n> index 801919009e1..9a4db09178f 100755\n> --- a/t/t1092-sparse-checkout-compatibility.sh\n> +++ b/t/t1092-sparse-checkout-compatibility.sh\n> @@ -1514,6 +1514,17 @@ test_expect_success 'sparse-index is not expanded: stash' '\n>  \tensure_not_expanded stash pop\n>  '\n>  \n> +test_expect_success 'sparse-index is not expanded: describe' '\n> +\tinit_repos &&\n> +\t# Add tag to be read by describe\n> +\tensure_not_expanded tag -a v1.0 -m \"Version 1\" &&\n\nThe test you've added isn't verifying the sparse index compatibility of 'git\ntag' (which doesn't use the index at all, IIRC), so 'ensure_not_expanded'\nisn't needed on this line. You should use 'git -C sparse-index tag ...' to\nperform the action instead.\n\n> +\tensure_not_expanded describe --dirty &&\n> +\tensure_not_expanded describe &&\n> +\techo \"test\" >>sparse-index/extra.txt &&\n> +\tensure_not_expanded describe --dirty &&\n> +\tensure_not_expanded describe\n> +'\n> +\n>  test_expect_success 'sparse index is not expanded: diff' '\n>  \tinit_repos &&\n>  \n> diff --git a/t/t6121-describe-sparse.sh b/t/t6121-describe-sparse.sh\n> new file mode 100755\n> index 00000000000..ce53603c387\n> --- /dev/null\n> +++ b/t/t6121-describe-sparse.sh\n\nIs there a specific reason you've created a new test file instead of adding\nthe tests to 't1092-sparse-checkout-compatibility.sh'? Historically, we've\nused 't1092' for validating both the functional correctness of a command\nwith sparse index enable and the preservation of a sparse index with\n'ensure_not_expanded'; you've done the latter in 't1092', but put the former\nin this new 't6121'. 't1092' also uses a more \"interesting\" test repo &\nincludes comparison functions for full checkout/sparse-checkout/sparse\nindex, so the tests added for 'git describe' can be more thorough.\n\n> @@ -0,0 +1,67 @@\n> +#!/bin/sh\n> +\n> +test_description='git describe in sparse checked out trees'\n> +\n> +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n> +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n> +\n> +. ./test-lib.sh\n> +\n> +check_describe () {\n> +\tindir= &&\n> +\twhile test $# != 0\n> +\tdo\n> +\t\tcase \"$1\" in\n> +\t\t-C)\n> +\t\t\tindir=\"$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\tbreak\n> +\t\t\t;;\n> +\t\tesac\n> +\t\tshift\n> +\tdone &&\n> +\tindir=${indir:+\"$indir\"/} &&\n> +\texpect=\"$1\"\n> +\tshift\n> +\tdescribe_opts=\"$@\"\n> +\ttest_expect_success \"describe $describe_opts\" '\n> +\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >actual &&\n> +\t\techo \"$expect\" >expect &&\n> +\t\ttest_cmp expect actual\n> +\t'\n> +}\n> +\n> +test_expect_success setup '\n> +\ttest_commit initial file one &&\n> +\ttest_commit --annotate A file A &&\n> +\n> +\ttest_tick &&\n> +\n> +\tgit sparse-checkout init --cone\n> +'\n> +\n> +check_describe A HEAD\n> +\n> +test_expect_success 'describe --dirty with --work-tree' '\n> +\t(\n> +\t\tcd \"$TEST_DIRECTORY\" &&\n> +\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n> +\t) &&\n> +\tgrep \"A\" out\n> +'\n> +\n> +test_expect_success 'set-up dirty work tree' '\n> +\techo >>file\n> +'\n> +\n> +test_expect_success 'describe --dirty with --work-tree (dirty)' '\n> +\tgit describe --dirty >expected &&\n> +\t(\n> +\t\tcd \"$TEST_DIRECTORY\" &&\n> +\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n> +\t) &&\n> +\ttest_cmp expected out\n> +'\n> +test_done\n> \n> base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n\n"},{"id":"474416","messageId":"xmqqr0t79zvm.fsf@gitster.g","threadId":"59483","inReplyTo":"8cb2b7a2-78f2-9221-1234-62814557d2d3@github.com","subject":"Re: [PATCH v2] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-29T18:27:41Z","receivedAt":"2023-03-29T18:28:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Victoria Dye <vdye@github.com> writes:\n\n>> diff --git a/t/t6121-describe-sparse.sh b/t/t6121-describe-sparse.sh\n>> new file mode 100755\n>> index 00000000000..ce53603c387\n>> --- /dev/null\n>> +++ b/t/t6121-describe-sparse.sh\n>\n> Is there a specific reason you've created a new test file instead of adding\n> the tests to 't1092-sparse-checkout-compatibility.sh'? Historically, ...\n> ... 't1092' also uses a more \"interesting\" test repo &\n> includes comparison functions for full checkout/sparse-checkout/sparse\n> index, so the tests added for 'git describe' can be more thorough.\n\nAhh...  I mentioned t6120 in my response, but t1092 does sound like\na lot more appropriate place for adding tests for these.\n\nThanks for pointing it out.\n"},{"id":"474445","messageId":"pull.1480.v3.git.git.1680155957146.gitgitgadget@gmail.com","threadId":"59483","inReplyTo":"pull.1480.v2.git.git.1680107154078.gitgitgadget@gmail.com","subject":"[PATCH v3] describe: enable sparse index for describe","fromName":"Raghul Nanth A via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-03-30T05:59:16Z","receivedAt":"2023-03-30T05:59:25Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"From: Raghul Nanth A <nanth.raghul@gmail.com>\n\nAdd usage and performance tests for describe\n\nDescribe uses the index when it is run with --dirty flag, which uses the\nrun_diff_index commmand. The command is sparse-index aware and hence we\ncan just set the requires-full-index to false\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n    describe: enable sparse index for describe\n    \n     * Removed describe tests not concerned with sparse index\n    \n     * Added performance metric to commit message\n    \n     * Moved tests to t1092.sh\n    \n     * Explained reason for changes in commit message\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1480%2FNanthR%2Fdescribe-sparse-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1480/NanthR/describe-sparse-v3\nPull-Request: https://github.com/git/git/pull/1480\n\nRange-diff vs v2:\n\n 1:  03176f64607 ! 1:  01838ca3ab0 describe: enable sparse index for describe\n     @@ Commit message\n      \n          Add usage and performance tests for describe\n      \n     +    Describe uses the index when it is run with --dirty flag, which uses the\n     +    run_diff_index commmand. The command is sparse-index aware and hence we\n     +    can just set the requires-full-index to false\n     +\n          Performance metrics\n      \n            Test                                                     HEAD~1            HEAD\n     @@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n\n      +test_expect_success 'sparse-index is not expanded: describe' '\n      +\tinit_repos &&\n      +\t# Add tag to be read by describe\n     -+\tensure_not_expanded tag -a v1.0 -m \"Version 1\" &&\n     ++\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n      +\tensure_not_expanded describe --dirty &&\n     ++\tcp sparse-index-out sparse-index-dirty &&\n      +\tensure_not_expanded describe &&\n     -+\techo \"test\" >>sparse-index/extra.txt &&\n     ++\tcp sparse-index-out sparse-index-normal &&\n     ++\t# Check describe has same output on clean tree\n     ++\ttest_cmp sparse-index-dirty sparse-index-normal &&\n     ++\techo \"test\" >>sparse-index/g &&\n      +\tensure_not_expanded describe --dirty &&\n     ++\techo \"v1.0-dirty\" > actual &&\n     ++\t# Check describe on dirty work tree\n     ++\ttest_cmp sparse-index-out actual &&\n      +\tensure_not_expanded describe\n      +'\n      +\n       test_expect_success 'sparse index is not expanded: diff' '\n       \tinit_repos &&\n       \n     -\n     - ## t/t6121-describe-sparse.sh (new) ##\n     -@@\n     -+#!/bin/sh\n     -+\n     -+test_description='git describe in sparse checked out trees'\n     -+\n     -+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n     -+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n     -+\n     -+. ./test-lib.sh\n     -+\n     -+check_describe () {\n     -+\tindir= &&\n     -+\twhile test $# != 0\n     -+\tdo\n     -+\t\tcase \"$1\" in\n     -+\t\t-C)\n     -+\t\t\tindir=\"$2\"\n     -+\t\t\tshift\n     -+\t\t\t;;\n     -+\t\t*)\n     -+\t\t\tbreak\n     -+\t\t\t;;\n     -+\t\tesac\n     -+\t\tshift\n     -+\tdone &&\n     -+\tindir=${indir:+\"$indir\"/} &&\n     -+\texpect=\"$1\"\n     -+\tshift\n     -+\tdescribe_opts=\"$@\"\n     -+\ttest_expect_success \"describe $describe_opts\" '\n     -+\t\tgit ${indir:+ -C \"$indir\"} describe $describe_opts >actual &&\n     -+\t\techo \"$expect\" >expect &&\n     -+\t\ttest_cmp expect actual\n     -+\t'\n     -+}\n     -+\n     -+test_expect_success setup '\n     -+\ttest_commit initial file one &&\n     -+\ttest_commit --annotate A file A &&\n     -+\n     -+\ttest_tick &&\n     -+\n     -+\tgit sparse-checkout init --cone\n     -+'\n     -+\n     -+check_describe A HEAD\n     -+\n     -+test_expect_success 'describe --dirty with --work-tree' '\n     -+\t(\n     -+\t\tcd \"$TEST_DIRECTORY\" &&\n     -+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n     -+\t) &&\n     -+\tgrep \"A\" out\n     -+'\n     -+\n     -+test_expect_success 'set-up dirty work tree' '\n     -+\techo >>file\n     -+'\n     -+\n     -+test_expect_success 'describe --dirty with --work-tree (dirty)' '\n     -+\tgit describe --dirty >expected &&\n     -+\t(\n     -+\t\tcd \"$TEST_DIRECTORY\" &&\n     -+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n     -+\t) &&\n     -+\ttest_cmp expected out\n     -+'\n     -+test_done\n\n\n builtin/describe.c                       |  2 ++\n t/perf/p2000-sparse-operations.sh        |  3 +++\n t/t1092-sparse-checkout-compatibility.sh | 18 ++++++++++++++++++\n 3 files changed, 23 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8c..7ff9b5e4b20 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a0..db7887470f9 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e1..8bc35c51426 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,24 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\t# Add tag to be read by describe\n+\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n+\tensure_not_expanded describe --dirty &&\n+\tcp sparse-index-out sparse-index-dirty &&\n+\tensure_not_expanded describe &&\n+\tcp sparse-index-out sparse-index-normal &&\n+\t# Check describe has same output on clean tree\n+\ttest_cmp sparse-index-dirty sparse-index-normal &&\n+\techo \"test\" >>sparse-index/g &&\n+\tensure_not_expanded describe --dirty &&\n+\techo \"v1.0-dirty\" > actual &&\n+\t# Check describe on dirty work tree\n+\ttest_cmp sparse-index-out actual &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \n\nbase-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n-- \ngitgitgadget\n"},{"id":"474459","messageId":"xmqq1ql64796.fsf@gitster.g","threadId":"59483","inReplyTo":"pull.1480.v3.git.git.1680155957146.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-30T14:57:09Z","receivedAt":"2023-03-30T14:57:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Raghul Nanth A via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Raghul Nanth A <nanth.raghul@gmail.com>\n>\n> Add usage and performance tests for describe\n\nI think this sentence can easily go.\n\n> Describe uses the index when it is run with --dirty flag, which uses the\n> run_diff_index commmand. The command is sparse-index aware and hence we\n> can just set the requires-full-index to false\n\nEnd the sentence with full-stop.  More importantly, it would be\nnicer to have something to substantiate the \"this is sparse aware\"\nclaim here, something like \"since commit X\" or \"as shown in the test\ntXXXX.YY\".\n\nUpdated tests do look good, and the code change is of course minimal\nand to the point, which is also good.\n\nThanks.\n\n> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\n> index 3242cfe91a0..db7887470f9 100755\n> --- a/t/perf/p2000-sparse-operations.sh\n> +++ b/t/perf/p2000-sparse-operations.sh\n> @@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n>  \tdone &&\n>  \n>  \tgit sparse-checkout init --cone &&\n> +\tgit tag -a v1.0 -m \"Final\" &&\n>  \tgit sparse-checkout set $SPARSE_CONE &&\n>  \tgit checkout -b wide $OLD_COMMIT &&\n>  \n> @@ -125,5 +126,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 describe --dirty\n> +test_perf_on_all 'echo >>new && git describe --dirty'\n>  \n>  test_done\n> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\n> index 801919009e1..8bc35c51426 100755\n> --- a/t/t1092-sparse-checkout-compatibility.sh\n> +++ b/t/t1092-sparse-checkout-compatibility.sh\n> @@ -1514,6 +1514,24 @@ test_expect_success 'sparse-index is not expanded: stash' '\n>  \tensure_not_expanded stash pop\n>  '\n>  \n> +test_expect_success 'sparse-index is not expanded: describe' '\n> +\tinit_repos &&\n> +\t# Add tag to be read by describe\n> +\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n> +\tensure_not_expanded describe --dirty &&\n> +\tcp sparse-index-out sparse-index-dirty &&\n> +\tensure_not_expanded describe &&\n> +\tcp sparse-index-out sparse-index-normal &&\n> +\t# Check describe has same output on clean tree\n> +\ttest_cmp sparse-index-dirty sparse-index-normal &&\n> +\techo \"test\" >>sparse-index/g &&\n> +\tensure_not_expanded describe --dirty &&\n> +\techo \"v1.0-dirty\" > actual &&\n> +\t# Check describe on dirty work tree\n> +\ttest_cmp sparse-index-out actual &&\n> +\tensure_not_expanded describe\n> +'\n> +\n>  test_expect_success 'sparse index is not expanded: diff' '\n>  \tinit_repos &&\n>  \n>\n> base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n"},{"id":"474460","messageId":"xmqqtty22ry9.fsf@gitster.g","threadId":"59483","inReplyTo":"xmqq1ql64796.fsf@gitster.g","subject":"Re: [PATCH v3] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-30T15:13:02Z","receivedAt":"2023-03-30T15:16:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"Raghul Nanth A via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n>> From: Raghul Nanth A <nanth.raghul@gmail.com>\n>>\n>> Add usage and performance tests for describe\n>\n> I think this sentence can easily go.\n>\n>> Describe uses the index when it is run with --dirty flag, which uses the\n>> run_diff_index commmand. The command is sparse-index aware and hence we\n>> can just set the requires-full-index to false\n>\n> End the sentence with full-stop.  More importantly, it would be\n> nicer to have something to substantiate the \"this is sparse aware\"\n> claim here, something like \"since commit X\" or \"as shown in the test\n> tXXXX.YY\".\n\nWith a bit of digging into the history, I think the topic that was\nmerged at 8d2c3732 (Merge branch 'ld/sparse-diff-blame', 2021-12-21)\nmade various modes of \"git diff\" to be sparse-index aware.  t1092\nhas tests for \"git diff --cached\", which uses the same machinery.\n\n    Subject: [PATCH] describe: make it sparse-index aware\n\n    \"git describe\" needs to compare the index and the working tree\n    when (and only when) it is run with the \"--dirty\" flag.  This is\n    done by calling the run_diff_index() function, which has been\n    already made aware of the sparse-index in the series that led to\n    8d2c3732 (Merge branch 'ld/sparse-diff-blame', 2021-12-21).\n    t1092 has tests for \"git diff --cached\", which uses this exact\n    machinery.\n\n    Mark \"git describe\" that the command does not require the index\n    to be expanded fully beforehand.\n\nor something like that.\n\n> Updated tests do look good, and the code change is of course minimal\n> and to the point, which is also good.\n\nThanks.\n"},{"id":"474466","messageId":"945ec6f2-8370-0d99-0537-a3724eefde3f@gmail.com","threadId":"59483","inReplyTo":"8cb2b7a2-78f2-9221-1234-62814557d2d3@github.com","subject":"Re: [PATCH v2] describe: enable sparse index for describe","fromName":"Raghul Nanth","fromEmail":"nanth.raghul@gmail.com","sentAt":"2023-03-30T16:10:28Z","receivedAt":"2023-03-30T16:11:44Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"\n\nOn 3/29/23 23:19, Victoria Dye wrote:\n> Raghul Nanth A via GitGitGadget wrote:\n>> From: Raghul Nanth A <nanth.raghul@gmail.com>\n> \n> Hello! Thanks for working on this patch, it's always nice to get more sparse\n> index support. Since this is your first contribution to the mailing list,\n> though, it's unclear to me whether you're working on this as an independent\n> contributor or if you're interested in the Google Summer of Code project\n> \"More Sparse Index Integrations\" [1]. If you're doing this for GSoC, could\n> you please prefix the title of this patch with \"[GSoC]\" (as noted in the\n> application details [2])?\n> \n> On the topic of GSoC applications - if you are submitting this for GSoC, I'm\n> a bit curious as to why you jumped right into sparse index rather than first\n> submitting a microproject [3]. This is a good first pass at a sparse index\n> integration, but the microproject is a better way to get acquainted with the\n> conventions and requirements of contributing to Git, hence the strong\n> recommendation to complete one first.\n> \n> [1] https://git.github.io/SoC-2023-Ideas/\n> [2] https://git.github.io/General-Application-Information/\n> [3] https://git.github.io/General-Microproject-Information/\n> \n\nHello. So, yes, I am interested in GSOC. As for the reason for choosing \nto do sparse-index, I had just missed the part about the micro-projects. \nSorry about that. So, do I submit a micro-project patch?\n\nAnd as for the changes mentioned, I will make the changes in the title\n"},{"id":"474467","messageId":"4f2fda36-111d-5bac-2322-1ebb3e508e4d@github.com","threadId":"59483","inReplyTo":"pull.1480.v3.git.git.1680155957146.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] describe: enable sparse index for describe","fromName":"Victoria Dye","fromEmail":"vdye@github.com","sentAt":"2023-03-30T16:23:38Z","receivedAt":"2023-03-30T16:24:23Z","isPatch":true,"sender":{"key":"vdye@github.com","avatar":"https://avatars.githubusercontent.com/u/3619353?v=4"},"body":"Raghul Nanth A via GitGitGadget wrote:\n> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\n> index 801919009e1..8bc35c51426 100755\n> --- a/t/t1092-sparse-checkout-compatibility.sh\n> +++ b/t/t1092-sparse-checkout-compatibility.sh\n> @@ -1514,6 +1514,24 @@ test_expect_success 'sparse-index is not expanded: stash' '\n>  \tensure_not_expanded stash pop\n>  '\n>  \n> +test_expect_success 'sparse-index is not expanded: describe' '\n> +\tinit_repos &&\n> +\t# Add tag to be read by describe\n\nPlease add newlines before these comments to visually space out the test &\nmake it more readable.\n\n> +\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n> +\tensure_not_expanded describe --dirty &&\n> +\tcp sparse-index-out sparse-index-dirty &&\n> +\tensure_not_expanded describe &&\n> +\tcp sparse-index-out sparse-index-normal &&\n> +\t# Check describe has same output on clean tree\n> +\ttest_cmp sparse-index-dirty sparse-index-normal &&\n> +\techo \"test\" >>sparse-index/g &&\n> +\tensure_not_expanded describe --dirty &&\n> +\techo \"v1.0-dirty\" > actual &&\n> +\t# Check describe on dirty work tree\n> +\ttest_cmp sparse-index-out actual &&\n> +\tensure_not_expanded describe\n\nSorry if I was unclear in my last review [1], but I did not mean that you\nshould add cases to this test (and, to be honest, the comparison of\n'sparse-index-dirty' and 'sparse-index-normal' doesn't add much here).\nPlease add separate tests (as in, full 'test_expect_success' blocks) for\nchecking that the functionality of 'git describe' is consistent across\n'full-checkout', 'sparse-checkout', and 'sparse-index'. Past sparse index\nintegrations ('git grep' [2], 'git read-tree' [3], 'git show' [4], etc.) are\na good reference for the types of tests that should be added.\n\n[1] https://lore.kernel.org/git/8cb2b7a2-78f2-9221-1234-62814557d2d3@github.com/\n[2] https://lore.kernel.org/git/20220923041842.27817-2-shaoxuan.yuan02@gmail.com/\n[3] https://lore.kernel.org/git/90ebcb7b8ff4b4f1ba09abcbe636d639fa597e74.1646166271.git.gitgitgadget@gmail.com/\n[4] https://lore.kernel.org/git/8c2fdb5a4fc3317c05324da54692036e36fc15f3.1651005800.git.gitgitgadget@gmail.com/\n\n> +'\n> +\n>  test_expect_success 'sparse index is not expanded: diff' '\n>  \tinit_repos &&\n>  \n> \n> base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n\n"},{"id":"474508","messageId":"20230331154329.121958-1-nanth.raghul@gmail.com","threadId":"59483","inReplyTo":"4f2fda36-111d-5bac-2322-1ebb3e508e4d@github.com","subject":"[GSOC][PATCH] describe: enable sparse index for describe","fromName":"Raghul Nanth A","fromEmail":"nanth.raghul@gmail.com","sentAt":"2023-03-31T15:43:29Z","receivedAt":"2023-03-31T15:43:57Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"Add usage and performance tests for describe\n\ngit describe compares the index with the working tree when (and only\nwhen) it is run with the \"--dirty\" flag. This is done by the\nrun_diff_index() function. The function has been made aware of the\nsparse-index in the series that led to 8d2c3732 (Merge branch\n'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the\nrequires-full-index to false for \"describe\".\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n builtin/describe.c                       |  2 ++\n t/perf/p2000-sparse-operations.sh        |  3 +++\n t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++++\n 3 files changed, 35 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8..7ff9b5e4b2 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a..db7887470f 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e..2b46fb2a48 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,36 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'describe tested on all' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\trun_on_all git tag -a v1.0 -m \"Version 1\" &&\n+\ttest_all_match git describe --dirty &&\n+\trun_on_all rm g &&\n+\ttest_all_match git describe --dirty\n+'\n+\n+\n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n+\n+\tensure_not_expanded describe --dirty &&\n+\techo \"test\" >>sparse-index/g &&\n+\tensure_not_expanded describe --dirty &&\n+\techo \"v1.0-dirty\" >actual &&\n+\n+\t# Check describe on dirty work tree\n+\n+\ttest_cmp sparse-index-out actual &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \n-- \n2.40.0\n\nAs for the previous questions, yes I am intereseted in GSOC. I had\nmissed the part regarding the micro projects when I was going through\nthe requirements. Sorry about that. Would I be required to make one now?\n"},{"id":"474515","messageId":"xmqqzg7sg9r3.fsf@gitster.g","threadId":"59483","inReplyTo":"20230331154329.121958-1-nanth.raghul@gmail.com","subject":"Re: [GSOC][PATCH] describe: enable sparse index for describe","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-31T16:34:40Z","receivedAt":"2023-03-31T16:38:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Raghul Nanth A <nanth.raghul@gmail.com> writes:\n\n> Add usage and performance tests for describe\n\nI think the commit is better off without this line.\n\n> git describe compares the index with the working tree when (and only\n> when) it is run with the \"--dirty\" flag. This is done by the\n> ...\n>\n> Signed-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n> ---\n\nHere is where you describe what got changed since the previous\niteration (and following [PATCH v<N>] notational convention would\nhelp people to see which one is meant to be the latest).  These two\nare especially helpful when you send more or less identical patches\nin quick succession like within a few hours.\n\nThanks.\n"},{"id":"474524","messageId":"20230331182038.224892-1-nanth.raghul@gmail.com","threadId":"59483","inReplyTo":"pull.1480.v3.git.git.1680155957146.gitgitgadget@gmail.com","subject":"[GSOC][PATCH v4] describe: enable sparse index for describe","fromName":"Raghul Nanth A","fromEmail":"nanth.raghul@gmail.com","sentAt":"2023-03-31T18:20:38Z","receivedAt":"2023-03-31T18:21:05Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"git describe compares the index with the working tree when (and only\nwhen) it is run with the \"--dirty\" flag. This is done by the\nrun_diff_index() function. The function has been made aware of the\nsparse-index in the series that led to 8d2c3732 (Merge branch\n'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the\nrequires-full-index to false for \"describe\".\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n\n  * Removed describe tests not concerned with sparse index\n  * Added performance metric to commit message\n  * Moved tests to t1092.sh\n  * Explained reason for changes in commit message\n  * Added tests to validate behaviour in sparse and full indices\n\n\n builtin/describe.c                       |  2 ++\n t/perf/p2000-sparse-operations.sh        |  3 +++\n t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++++\n 3 files changed, 35 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8..7ff9b5e4b2 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a..db7887470f 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e..2b46fb2a48 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,36 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'describe tested on all' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\trun_on_all git tag -a v1.0 -m \"Version 1\" &&\n+\ttest_all_match git describe --dirty &&\n+\trun_on_all rm g &&\n+\ttest_all_match git describe --dirty\n+'\n+\n+\n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n+\n+\tensure_not_expanded describe --dirty &&\n+\techo \"test\" >>sparse-index/g &&\n+\tensure_not_expanded describe --dirty &&\n+\techo \"v1.0-dirty\" >actual &&\n+\n+\t# Check describe on dirty work tree\n+\n+\ttest_cmp sparse-index-out actual &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \n-- \n2.40.0\n\n"},{"id":"474675","messageId":"20230403073525.227363-1-nanth.raghul@gmail.com","threadId":"59483","inReplyTo":"pull.1480.v3.git.git.1680155957146.gitgitgadget@gmail.com","subject":"[PATCH v4] describe: enable sparse index for describe","fromName":"Raghul Nanth A","fromEmail":"nanth.raghul@gmail.com","sentAt":"2023-04-03T07:35:25Z","receivedAt":"2023-04-03T07:35:45Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"git describe compares the index with the working tree when (and only\nwhen) it is run with the \"--dirty\" flag. This is done by the\nrun_diff_index() function. The function has been made aware of the\nsparse-index in the series that led to 8d2c3732 (Merge branch\n'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the\nrequires-full-index to false for \"describe\".\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n\n  * Removed describe tests not concerned with sparse index\n  * Added performance metric to commit message\n  * Moved tests to t1092.sh\n  * Explained reason for changes in commit message\n  * Added tests to validate behaviour in sparse and full indices\n\n\n builtin/describe.c                       |  2 ++\n t/perf/p2000-sparse-operations.sh        |  3 +++\n t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++++\n 3 files changed, 35 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8..7ff9b5e4b2 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a..db7887470f 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e..2b46fb2a48 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,36 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'describe tested on all' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\trun_on_all git tag -a v1.0 -m \"Version 1\" &&\n+\ttest_all_match git describe --dirty &&\n+\trun_on_all rm g &&\n+\ttest_all_match git describe --dirty\n+'\n+\n+\n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n+\n+\tensure_not_expanded describe --dirty &&\n+\techo \"test\" >>sparse-index/g &&\n+\tensure_not_expanded describe --dirty &&\n+\techo \"v1.0-dirty\" >actual &&\n+\n+\t# Check describe on dirty work tree\n+\n+\ttest_cmp sparse-index-out actual &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \n-- \n2.40.0\n\n"},{"id":"474688","messageId":"f8d8ed7f-49cd-d65a-521c-e03d2c552c50@github.com","threadId":"59483","inReplyTo":"20230331182038.224892-1-nanth.raghul@gmail.com","subject":"Re: [GSOC][PATCH v4] describe: enable sparse index for describe","fromName":"Victoria Dye","fromEmail":"vdye@github.com","sentAt":"2023-04-03T16:34:10Z","receivedAt":"2023-04-03T16:34:24Z","isPatch":true,"sender":{"key":"vdye@github.com","avatar":"https://avatars.githubusercontent.com/u/3619353?v=4"},"body":"Raghul Nanth A wrote:\n> git describe compares the index with the working tree when (and only\n> when) it is run with the \"--dirty\" flag. This is done by the\n> run_diff_index() function. The function has been made aware of the\n> sparse-index in the series that led to 8d2c3732 (Merge branch\n> 'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the\n> requires-full-index to false for \"describe\".\n> \n\nThis is a good description of the patch and the reasoning behind the\nchanges.\n\n> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\n> index 801919009e..2b46fb2a48 100755\n> --- a/t/t1092-sparse-checkout-compatibility.sh\n> +++ b/t/t1092-sparse-checkout-compatibility.sh\n> @@ -1514,6 +1514,36 @@ test_expect_success 'sparse-index is not expanded: stash' '\n>  \tensure_not_expanded stash pop\n>  '\n>  \n> +test_expect_success 'describe tested on all' '\n> +\tinit_repos &&\n> +\n> +\t# Add tag to be read by describe\n> +\n> +\trun_on_all git tag -a v1.0 -m \"Version 1\" &&\n> +\ttest_all_match git describe --dirty &&\n> +\trun_on_all rm g &&\n> +\ttest_all_match git describe --dirty\n> +'\n> +\n> +\n> +test_expect_success 'sparse-index is not expanded: describe' '\n> +\tinit_repos &&\n> +\n> +\t# Add tag to be read by describe\n> +\n> +\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n> +\n> +\tensure_not_expanded describe --dirty &&\n> +\techo \"test\" >>sparse-index/g &&\n> +\tensure_not_expanded describe --dirty &&\n> +\techo \"v1.0-dirty\" >actual &&\n> +\n> +\t# Check describe on dirty work tree\n> +\n> +\ttest_cmp sparse-index-out actual &&\n\nThis type of output comparison should be part of 'describe tested on all',\nnot the \"ensure not expanded\" test; the former tests the correctness of 'git\ndescribe', whereas the latter focuses on index expansion. When unit testing,\nit helps to keep the scope of each test fairly narrow with a specific focus\nso that they can more easily isolate future regressions.\n\n> +\tensure_not_expanded describe\n> +'\n> +\n>  test_expect_success 'sparse index is not expanded: diff' '\n>  \tinit_repos &&\n>  \n\n"},{"id":"474690","messageId":"9b56e214-7efb-cea9-d3ff-35692c179a7b@github.com","threadId":"59483","inReplyTo":"945ec6f2-8370-0d99-0537-a3724eefde3f@gmail.com","subject":"Re: [PATCH v2] describe: enable sparse index for describe","fromName":"Victoria Dye","fromEmail":"vdye@github.com","sentAt":"2023-04-03T16:37:48Z","receivedAt":"2023-04-03T16:38:13Z","isPatch":true,"sender":{"key":"vdye@github.com","avatar":"https://avatars.githubusercontent.com/u/3619353?v=4"},"body":"Raghul Nanth wrote:\n> Hello. So, yes, I am interested in GSOC. As for the reason for choosing to\n> do sparse-index, I had just missed the part about the micro-projects.\n> Sorry about that. So, do I submit a micro-project patch?\n\nNo, you do not need to submit an additional microproject. The 'git describe'\nintegration covers the intended purpose of a microproject (namely, becoming\nfamiliar with Git contribution best practices).\n\n> \n> And as for the changes mentioned, I will make the changes in the title\n\n"},{"id":"474691","messageId":"20230403164749.246001-1-nanth.raghul@gmail.com","threadId":"59483","inReplyTo":"20230331182038.224892-1-nanth.raghul@gmail.com","subject":"[GSOC][PATCH v5] describe: enable sparse index for describe","fromName":"Raghul Nanth A","fromEmail":"nanth.raghul@gmail.com","sentAt":"2023-04-03T16:47:49Z","receivedAt":"2023-04-03T16:48:14Z","isPatch":true,"sender":{"key":"nanth.raghul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61490162?v=4"},"body":"git describe compares the index with the working tree when (and only\nwhen) it is run with the \"--dirty\" flag. This is done by the\nrun_diff_index() function. The function has been made aware of the\nsparse-index in the series that led to 8d2c3732 (Merge branch\n'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the\nrequires-full-index to false for \"describe\".\n\nPerformance metrics\n\n  Test                                                     HEAD~1            HEAD\n  -------------------------------------------------------------------------------------------------\n  2000.2: git describe --dirty (full-v3)                   0.08(0.09+0.01)   0.08(0.06+0.03) +0.0%\n  2000.3: git describe --dirty (full-v4)                   0.09(0.07+0.03)   0.08(0.05+0.04) -11.1%\n  2000.4: git describe --dirty (sparse-v3)                 0.88(0.82+0.06)   0.02(0.01+0.05) -97.7%\n  2000.5: git describe --dirty (sparse-v4)                 0.68(0.60+0.08)   0.02(0.02+0.04) -97.1%\n  2000.6: echo >>new && git describe --dirty (full-v3)     0.08(0.04+0.05)   0.08(0.05+0.04) +0.0%\n  2000.7: echo >>new && git describe --dirty (full-v4)     0.08(0.07+0.03)   0.08(0.05+0.04) +0.0%\n  2000.8: echo >>new && git describe --dirty (sparse-v3)   0.75(0.69+0.07)   0.02(0.03+0.03) -97.3%\n  2000.9: echo >>new && git describe --dirty (sparse-v4)   0.81(0.73+0.09)   0.02(0.01+0.05) -97.5%\n\nSigned-off-by: Raghul Nanth A <nanth.raghul@gmail.com>\n---\n\n  * Removed describe tests not concerned with sparse index\n  * Added performance metric to commit message\n  * Moved tests to t1092.sh\n  * Explained reason for changes in commit message\n  * Added tests to validate behaviour in sparse and full indices\n\n builtin/describe.c                       |  2 ++\n t/perf/p2000-sparse-operations.sh        |  3 +++\n t/t1092-sparse-checkout-compatibility.sh | 25 ++++++++++++++++++++++++\n 3 files changed, 30 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 5b5930f5c8..7ff9b5e4b2 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tint fd, result;\n \n \t\t\tsetup_work_tree();\n+\t\t\tprepare_repo_settings(the_repository);\n+\t\t\tthe_repository->settings.command_requires_full_index = 0;\n \t\t\trepo_read_index(the_repository);\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh\nindex 3242cfe91a..db7887470f 100755\n--- a/t/perf/p2000-sparse-operations.sh\n+++ b/t/perf/p2000-sparse-operations.sh\n@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '\n \tdone &&\n \n \tgit sparse-checkout init --cone &&\n+\tgit tag -a v1.0 -m \"Final\" &&\n \tgit sparse-checkout set $SPARSE_CONE &&\n \tgit checkout -b wide $OLD_COMMIT &&\n \n@@ -125,5 +126,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 describe --dirty\n+test_perf_on_all 'echo >>new && git describe --dirty'\n \n test_done\ndiff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh\nindex 801919009e..51bebd4fa9 100755\n--- a/t/t1092-sparse-checkout-compatibility.sh\n+++ b/t/t1092-sparse-checkout-compatibility.sh\n@@ -1514,6 +1514,31 @@ test_expect_success 'sparse-index is not expanded: stash' '\n \tensure_not_expanded stash pop\n '\n \n+test_expect_success 'describe tested on all' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\trun_on_all git tag -a v1.0 -m \"Version 1\" &&\n+\ttest_all_match git describe --dirty &&\n+\trun_on_all rm g &&\n+\ttest_all_match git describe --dirty\n+'\n+\n+\n+test_expect_success 'sparse-index is not expanded: describe' '\n+\tinit_repos &&\n+\n+\t# Add tag to be read by describe\n+\n+\tgit -C sparse-index tag -a v1.0 -m \"Version 1\" &&\n+\n+\tensure_not_expanded describe --dirty &&\n+\techo \"test\" >>sparse-index/g &&\n+\tensure_not_expanded describe --dirty &&\n+\tensure_not_expanded describe\n+'\n+\n test_expect_success 'sparse index is not expanded: diff' '\n \tinit_repos &&\n \n-- \n2.40.0\n\n"}]}