{"thread":{"id":"52524","subject":"[PATCH 0/1] sparse-checkout: list directories in cone mode","startedAt":"2019-12-26T20:49:11Z","lastAt":"2019-12-30T17:18:34Z","messageCount":18,"participants":["Derrick Stolee via GitGitGadget","Junio C Hamano","Derrick Stolee","Elijah Newren","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"388952","messageId":"pull.500.git.1577393347.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":null,"subject":"[PATCH 0/1] sparse-checkout: list directories in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-26T20:49:06Z","receivedAt":"2019-12-26T20:49:11Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"When in cone mode, \"git sparse-checkout set\" takes a list of folders and\nconstructs an ordered list of patterns for the sparse-checkout file. The\n\"git sparse-checkout list\" subcommand outputs the contents of the\nsparse-checkout file in a very basic way.\n\nThis patch changes the behavior of \"git sparse-checkout list\" when\ncore.sparseCheckoutCone=true. It will output the folders that were used in\n\"git sparse-checkout set\" to create the patterns, instead of the patterns\nthemselves.\n\nI believe this was requested in the initial review, but I cannot find that\nmessage now.\n\nI was going to include this as part of a longer follow-up series, but I\nthink this may be worth considering for the 2.25.0 release. Hence, it is\nincluded by itself.\n\nThanks, -Stolee\n\nDerrick Stolee (1):\n  sparse-checkout: list folders in cone mode\n\n Documentation/git-sparse-checkout.txt | 11 ++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 11 +++++++++++\n 3 files changed, 42 insertions(+), 1 deletion(-)\n\n\nbase-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/500\n-- \ngitgitgadget\n"},{"id":"388953","messageId":"07be7b8dda679d79ac9b218b2a9b08e47d7762fd.1577393347.git.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.git.1577393347.gitgitgadget@gmail.com","subject":"[PATCH 1/1] sparse-checkout: list folders in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-26T20:49:07Z","receivedAt":"2019-12-26T20:49:13Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <dstolee@microsoft.com>\n\nWhen core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\ncommand taks a list of folders as input, then creates an ordered\nlist of sparse-checkout patterns such that those folders are\nrecursively included and all sibling blobs along the parent folders\nare also included. Listing the patterns is less user-friendly than the\nfolders themselves.\n\nIn cone mode, and as long as the patterns match the expected cone-mode\npattern types, change the output of 'git sparse-checkout list' to only\nshow the folders that created the patterns.\n\nWith this change, the following piped commands would not change the\nworking directory:\n\n\tgit sparse-checkout list | git sparse-checkout set --stdin\n\nThe only time this would not work is if core.sparseCheckoutCone is\ntrue, but the sparse-checkout file contains patterns that do not\nmatch the expected pattern types for cone mode.\n\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/git-sparse-checkout.txt | 11 ++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 11 +++++++++++\n 3 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\nindex 9c3c66cc37..dcca9ee826 100644\n--- a/Documentation/git-sparse-checkout.txt\n+++ b/Documentation/git-sparse-checkout.txt\n@@ -28,7 +28,7 @@ THE FUTURE.\n COMMANDS\n --------\n 'list'::\n-\tProvide a list of the contents in the sparse-checkout file.\n+\tDescribe the patterns in the sparse-checkout file.\n \n 'init'::\n \tEnable the `core.sparseCheckout` setting. If the\n@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match.\n If the patterns do match the expected format, then Git will use faster hash-\n based algorithms to compute inclusion in the sparse-checkout.\n \n+In the cone mode case, the `git sparse-checkout list` subcommand will list the\n+folders that define the recursive patterns. For the example sparse-checkout file\n+above, the output is as follows:\n+\n+--------------------------\n+$ git sparse-checkout list\n+A/B/C\n+--------------------------\n+\n If `core.ignoreCase=true`, then the pattern-matching algorithm will use a\n case-insensitive check. This corrects for case mismatched filenames in the\n 'git sparse-checkout set' command to reflect the expected cone in the working\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex 5d62f7a66d..b3bed891cb 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)\n \n \tmemset(&pl, 0, sizeof(pl));\n \n+\tpl.use_cone_patterns = core_sparse_checkout_cone;\n+\n \tsparse_filename = get_sparse_checkout_filename();\n \tres = add_patterns_from_file_to_list(sparse_filename, \"\", 0, &pl, NULL);\n \tfree(sparse_filename);\n@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)\n \t\treturn 0;\n \t}\n \n+\tif (pl.use_cone_patterns) {\n+\t\tint i;\n+\t\tstruct pattern_entry *pe;\n+\t\tstruct hashmap_iter iter;\n+\t\tstruct string_list sl = STRING_LIST_INIT_DUP;\n+\n+\t\thashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {\n+\t\t\t/* pe->pattern starts with \"/\", skip it */\n+\t\t\tstring_list_insert(&sl, pe->pattern + 1);\n+\t\t}\n+\n+\t\tstring_list_sort(&sl);\n+\n+\t\tfor (i = 0; i < sl.nr; i++)\n+\t\t\tprintf(\"%s\\n\", sl.items[i].string);\n+\n+\t\treturn 0;\n+\t}\n+\n \twrite_patterns_to_file(stdout, &pl);\n \tclear_pattern_list(&pl);\n \ndiff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\nindex 6f7e2d0c9e..37f6d8fa90 100755\n--- a/t/t1091-sparse-checkout-builtin.sh\n+++ b/t/t1091-sparse-checkout-builtin.sh\n@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' '\n \ttest_cmp expect dir\n '\n \n+test_expect_success 'cone mode: list' '\n+\tcat >expect <<-EOF &&\n+\t\tfolder1\n+\t\tfolder2\n+\tEOF\n+\tgit -C repo sparse-checkout set --stdin <expect &&\n+\tgit -C repo sparse-checkout list >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cone mode: set with nested folders' '\n \tgit -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&\n \ttest_line_count = 0 err &&\n-- \ngitgitgadget\n"},{"id":"388955","messageId":"xmqqo8vukcqv.fsf@gitster-ct.c.googlers.com","threadId":"52524","inReplyTo":"07be7b8dda679d79ac9b218b2a9b08e47d7762fd.1577393347.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/1] sparse-checkout: list folders in cone mode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-26T21:17:44Z","receivedAt":"2019-12-26T21:17:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Derrick Stolee via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Derrick Stolee <dstolee@microsoft.com>\n\n> Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode\ns/folder/directory/ everywhere as the rest of Git.\n\n> When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n> command taks a list of folders as input, then creates an ordered\n\n\"takes\"\n\n> list of sparse-checkout patterns such that those folders are\n> recursively included and all sibling blobs along the parent folders\n\nIn this sentence, what does a \"blob\" really mean?  Do you mean a\nfilesystem entity, that is not a folder, that is immediately\ncontained in the \"parent folder\" (in other words, regular files\nand symbolic links)?\n\nHow would this interact with a submodule by the way?\n\n> are also included. Listing the patterns is less user-friendly than the\n> folders themselves.\n>\n> In cone mode, and as long as the patterns match the expected cone-mode\n> pattern types, change the output of 'git sparse-checkout list' to only\n> show the folders that created the patterns.\n> ...\n> +In the cone mode case, the `git sparse-checkout list` subcommand will list the\n> +folders that define the recursive patterns. For the example sparse-checkout file\n> +above, the output is as follows:\n> +\n> +--------------------------\n> +$ git sparse-checkout list\n> +A/B/C\n> +--------------------------\n> +\n\nSounds like a worthwhile usability improvement.\n\n"},{"id":"388990","messageId":"4ecc2696-421a-9b1b-7b2c-335091aa7b08@gmail.com","threadId":"52524","inReplyTo":"xmqqo8vukcqv.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 1/1] sparse-checkout: list folders in cone mode","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-12-27T14:05:08Z","receivedAt":"2019-12-27T14:05:12Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/26/2019 4:17 PM, Junio C Hamano wrote:\n> \"Derrick Stolee via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> \n>> From: Derrick Stolee <dstolee@microsoft.com>\n> \n>> Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode\n> s/folder/directory/ everywhere as the rest of Git.\n> \n>> When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n>> command taks a list of folders as input, then creates an ordered\n> \n> \"takes\"\n\nGood catch.\n\n>> list of sparse-checkout patterns such that those folders are\n>> recursively included and all sibling blobs along the parent folders\n> \n> In this sentence, what does a \"blob\" really mean?  Do you mean a\n> filesystem entity, that is not a folder, that is immediately\n> contained in the \"parent folder\" (in other words, regular files\n> and symbolic links)?\n\nYou're right, I'm using strange wording here. How about \"sibling\nentries\"?\n\n> How would this interact with a submodule by the way?\n\nI just checked with the Git repo by running:\n\n\tgit submodule init\n\tgit submodule update\n\tgit sparse-checkout init --cone\n\nThe working directory then contains all blobs at root AND the\nsha1collisiondetection submodule. Interesting that the sparse-\ncheckout feature ignores submodules. That seems like the best\napproach since the user can already enlist in a subset of the\nsubmodules.\n\n>> are also included. Listing the patterns is less user-friendly than the\n>> folders themselves.\n>>\n>> In cone mode, and as long as the patterns match the expected cone-mode\n>> pattern types, change the output of 'git sparse-checkout list' to only\n>> show the folders that created the patterns.\n>> ...\n>> +In the cone mode case, the `git sparse-checkout list` subcommand will list the\n>> +folders that define the recursive patterns. For the example sparse-checkout file\n>> +above, the output is as follows:\n>> +\n>> +--------------------------\n>> +$ git sparse-checkout list\n>> +A/B/C\n>> +--------------------------\n>> +\n> \n> Sounds like a worthwhile usability improvement.\n \nThanks,\n-Stolee\n"},{"id":"388994","messageId":"CABPp-BHWOtQxhX-QrEYsPiPfKShAXKbe51D=L96JF=g2pZvjmQ@mail.gmail.com","threadId":"52524","inReplyTo":"07be7b8dda679d79ac9b218b2a9b08e47d7762fd.1577393347.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/1] sparse-checkout: list folders in cone mode","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-27T15:52:25Z","receivedAt":"2019-12-27T15:52:34Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, Dec 26, 2019 at 12:49 PM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Derrick Stolee <dstolee@microsoft.com>\n>\n> When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n> command taks a list of folders as input, then creates an ordered\n> list of sparse-checkout patterns such that those folders are\n> recursively included and all sibling blobs along the parent folders\n> are also included. Listing the patterns is less user-friendly than the\n> folders themselves.\n\nI didn't spot anything that Junio hasn't already mentioned, but I'm\njust chiming in to say that this sounds good and thanks so much for\nworking on the sparse-checkout command.  :-)\n"},{"id":"388997","messageId":"pull.500.v2.git.1577472469.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.git.1577393347.gitgitgadget@gmail.com","subject":"[PATCH v2 0/2] sparse-checkout: list directories in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-27T18:47:46Z","receivedAt":"2019-12-27T18:47:54Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"When in cone mode, \"git sparse-checkout set\" takes a list of folders and\nconstructs an ordered list of patterns for the sparse-checkout file. The\n\"git sparse-checkout list\" subcommand outputs the contents of the\nsparse-checkout file in a very basic way.\n\nThis patch changes the behavior of \"git sparse-checkout list\" when\ncore.sparseCheckoutCone=true. It will output the folders that were used in\n\"git sparse-checkout set\" to create the patterns, instead of the patterns\nthemselves.\n\nI believe this was requested in the initial review, but I cannot find that\nmessage now.\n\nI was going to include this as part of a longer follow-up series, but I\nthink this may be worth considering for the 2.25.0 release. Hence, it is\nincluded by itself.\n\nUpdate in V2:\n\n * Fixed typos/word choice in commit message.\n   \n   \n * Added a second commit including clarification on interactions with\n   submodules.\n   \n   \n\nThanks, -Stolee\n\nDerrick Stolee (2):\n  sparse-checkout: list folders in cone mode\n  sparse-checkout: document interactions with submodules\n\n Documentation/git-sparse-checkout.txt | 21 ++++++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 39 +++++++++++++++++++++++++++\n 3 files changed, 80 insertions(+), 1 deletion(-)\n\n\nbase-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/500\n\nRange-diff vs v1:\n\n 1:  07be7b8dda ! 1:  d6f4f40486 sparse-checkout: list folders in cone mode\n     @@ -3,9 +3,9 @@\n          sparse-checkout: list folders in cone mode\n      \n          When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n     -    command taks a list of folders as input, then creates an ordered\n     +    command takes a list of folders as input, then creates an ordered\n          list of sparse-checkout patterns such that those folders are\n     -    recursively included and all sibling blobs along the parent folders\n     +    recursively included and all sibling entries along the parent folders\n          are also included. Listing the patterns is less user-friendly than the\n          folders themselves.\n      \n -:  ---------- > 2:  331bb7d6fb sparse-checkout: document interactions with submodules\n\n-- \ngitgitgadget\n"},{"id":"388998","messageId":"d6f4f404866e30e9de89991bb39f2908facb30ae.1577472469.git.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.v2.git.1577472469.gitgitgadget@gmail.com","subject":"[PATCH v2 1/2] sparse-checkout: list folders in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-27T18:47:47Z","receivedAt":"2019-12-27T18:48:11Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <dstolee@microsoft.com>\n\nWhen core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\ncommand takes a list of folders as input, then creates an ordered\nlist of sparse-checkout patterns such that those folders are\nrecursively included and all sibling entries along the parent folders\nare also included. Listing the patterns is less user-friendly than the\nfolders themselves.\n\nIn cone mode, and as long as the patterns match the expected cone-mode\npattern types, change the output of 'git sparse-checkout list' to only\nshow the folders that created the patterns.\n\nWith this change, the following piped commands would not change the\nworking directory:\n\n\tgit sparse-checkout list | git sparse-checkout set --stdin\n\nThe only time this would not work is if core.sparseCheckoutCone is\ntrue, but the sparse-checkout file contains patterns that do not\nmatch the expected pattern types for cone mode.\n\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/git-sparse-checkout.txt | 11 ++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 11 +++++++++++\n 3 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\nindex 9c3c66cc37..dcca9ee826 100644\n--- a/Documentation/git-sparse-checkout.txt\n+++ b/Documentation/git-sparse-checkout.txt\n@@ -28,7 +28,7 @@ THE FUTURE.\n COMMANDS\n --------\n 'list'::\n-\tProvide a list of the contents in the sparse-checkout file.\n+\tDescribe the patterns in the sparse-checkout file.\n \n 'init'::\n \tEnable the `core.sparseCheckout` setting. If the\n@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match.\n If the patterns do match the expected format, then Git will use faster hash-\n based algorithms to compute inclusion in the sparse-checkout.\n \n+In the cone mode case, the `git sparse-checkout list` subcommand will list the\n+folders that define the recursive patterns. For the example sparse-checkout file\n+above, the output is as follows:\n+\n+--------------------------\n+$ git sparse-checkout list\n+A/B/C\n+--------------------------\n+\n If `core.ignoreCase=true`, then the pattern-matching algorithm will use a\n case-insensitive check. This corrects for case mismatched filenames in the\n 'git sparse-checkout set' command to reflect the expected cone in the working\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex 5d62f7a66d..b3bed891cb 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)\n \n \tmemset(&pl, 0, sizeof(pl));\n \n+\tpl.use_cone_patterns = core_sparse_checkout_cone;\n+\n \tsparse_filename = get_sparse_checkout_filename();\n \tres = add_patterns_from_file_to_list(sparse_filename, \"\", 0, &pl, NULL);\n \tfree(sparse_filename);\n@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)\n \t\treturn 0;\n \t}\n \n+\tif (pl.use_cone_patterns) {\n+\t\tint i;\n+\t\tstruct pattern_entry *pe;\n+\t\tstruct hashmap_iter iter;\n+\t\tstruct string_list sl = STRING_LIST_INIT_DUP;\n+\n+\t\thashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {\n+\t\t\t/* pe->pattern starts with \"/\", skip it */\n+\t\t\tstring_list_insert(&sl, pe->pattern + 1);\n+\t\t}\n+\n+\t\tstring_list_sort(&sl);\n+\n+\t\tfor (i = 0; i < sl.nr; i++)\n+\t\t\tprintf(\"%s\\n\", sl.items[i].string);\n+\n+\t\treturn 0;\n+\t}\n+\n \twrite_patterns_to_file(stdout, &pl);\n \tclear_pattern_list(&pl);\n \ndiff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\nindex 6f7e2d0c9e..37f6d8fa90 100755\n--- a/t/t1091-sparse-checkout-builtin.sh\n+++ b/t/t1091-sparse-checkout-builtin.sh\n@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' '\n \ttest_cmp expect dir\n '\n \n+test_expect_success 'cone mode: list' '\n+\tcat >expect <<-EOF &&\n+\t\tfolder1\n+\t\tfolder2\n+\tEOF\n+\tgit -C repo sparse-checkout set --stdin <expect &&\n+\tgit -C repo sparse-checkout list >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cone mode: set with nested folders' '\n \tgit -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&\n \ttest_line_count = 0 err &&\n-- \ngitgitgadget\n\n"},{"id":"388999","messageId":"331bb7d6fbec6f2f429feb36cf32e0931307ae0b.1577472469.git.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.v2.git.1577472469.gitgitgadget@gmail.com","subject":"[PATCH v2 2/2] sparse-checkout: document interactions with submodules","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-27T18:47:48Z","receivedAt":"2019-12-27T18:48:12Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <dstolee@microsoft.com>\n\nJunio asked what the behavior is between the sparse-checkout feature\nand the submodule feature. The sparse-checkout builtin has not changed\nthe way these features interact, but we may as well document it in\nthe builtin docs.\n\nUsing 'git submodule (init|deinit)' a user can select a subset of\nsubmodules to populate. This behaves very similar to the sparse-checkout\nfeature, but those directories contain their own .git directory\nincluding an object database and ref space. To have the sparse-checkout\nfile also determine if those files should exist would easily cause\nproblems. Therefore, keeping these features independent in this way\nis the best way forward.\n\nAlso create a test that demonstrates this behavior to make sure\nit doesn't change as the sparse-checkout feature evolves.\n\nReported-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/git-sparse-checkout.txt | 10 ++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++\n 2 files changed, 38 insertions(+)\n\ndiff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\nindex dcca9ee826..2b7aaa0310 100644\n--- a/Documentation/git-sparse-checkout.txt\n+++ b/Documentation/git-sparse-checkout.txt\n@@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the\n 'git sparse-checkout set' command to reflect the expected cone in the working\n directory.\n \n+\n+SUBMODULES\n+----------\n+\n+If your repository contains one or more submodules, then those submodules will\n+appear based on which you initialized with the `git submodule` command. If\n+your sparse-checkout patterns exclude an initialized submodule, then that\n+submodule will still appear in your working directory.\n+\n+\n SEE ALSO\n --------\n \ndiff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\nindex 37f6d8fa90..5572beeeca 100755\n--- a/t/t1091-sparse-checkout-builtin.sh\n+++ b/t/t1091-sparse-checkout-builtin.sh\n@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '\n \ttest_cmp expect dir\n '\n \n+test_expect_success 'interaction with submodules' '\n+\tgit clone repo super &&\n+\t(\n+\t\tcd super &&\n+\t\tmkdir modules &&\n+\t\tgit submodule add ../repo modules/child &&\n+\t\tgit add . &&\n+\t\tgit commit -m \"add submodule\" &&\n+\t\tgit sparse-checkout init --cone &&\n+\t\tgit sparse-checkout set folder1\n+\t) &&\n+\tlist_files super >dir &&\n+\tcat >expect <<-EOF &&\n+\t\ta\n+\t\tfolder1\n+\t\tmodules\n+\tEOF\n+\ttest_cmp expect dir &&\n+\tlist_files super/modules/child >dir &&\n+\tcat >expect <<-EOF &&\n+\t\ta\n+\t\tdeep\n+\t\tfolder1\n+\t\tfolder2\n+\tEOF\n+\ttest_cmp expect dir\n+'\n+\n test_done\n-- \ngitgitgadget\n"},{"id":"389001","messageId":"CAPig+cTvFW_84TqKsOPjjBM37cX1OL9uX15APcEYpuKVjvM+dg@mail.gmail.com","threadId":"52524","inReplyTo":"331bb7d6fbec6f2f429feb36cf32e0931307ae0b.1577472469.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-12-27T20:20:09Z","receivedAt":"2019-12-27T20:20:42Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Dec 27, 2019 at 1:48 PM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\n> @@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '\n> +test_expect_success 'interaction with submodules' '\n> +       ...\n> +       cat >expect <<-EOF &&\n> +               a\n> +               folder1\n> +               modules\n> +       EOF\n\nYou would normally use \\-EOF rather than -EOF to make it clear that no\ninterpolation is needed/expected within the here-doc body. However,\nthis script is already full of -EOF when \\-EOF ought to be used, so\nbeing consistent with existing tests may override an objection.\n\nLikewise, please note for future reference that the usual way\nhere-docs are formatted in Git test scripts is to indent the body of\nthe here-doc to the same level as the command which opens it. That is:\n\n    cat >expect <<\\-EOF &&\n    a\n    folder1\n    modules\n    EOF\n\nBut, again, this script is already full of these malformatted\nhere-docs, so maintaining consistency with the existing test in the\nscript is probably okay.\n\n(Of course, a preparatory patch fixing these here-doc issues would be\nwelcome, but might also be outside the scope of this submission. And,\nfixing these very minor issues is quite low-priority, so I wouldn't\nexpect or demand it.)\n"},{"id":"389006","messageId":"CABPp-BGGfwR3r1YZuyeQN1=WqokSBdcHeFWkkZ2OD_S9Enfb0w@mail.gmail.com","threadId":"52524","inReplyTo":"d6f4f404866e30e9de89991bb39f2908facb30ae.1577472469.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 1/2] sparse-checkout: list folders in cone mode","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-27T21:37:44Z","receivedAt":"2019-12-27T21:37:53Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Derrick Stolee <dstolee@microsoft.com>\n>\n> When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n> command takes a list of folders as input, then creates an ordered\ns/folders/directories/\n\n> list of sparse-checkout patterns such that those folders are\ns/folders/directories/\n\n> recursively included and all sibling entries along the parent folders\nagain here.\n\n> are also included. Listing the patterns is less user-friendly than the\n> folders themselves.\nand here.\n\n>\n> In cone mode, and as long as the patterns match the expected cone-mode\n> pattern types, change the output of 'git sparse-checkout list' to only\n> show the folders that created the patterns.\nand here.\n\n>\n> With this change, the following piped commands would not change the\n> working directory:\n>\n>         git sparse-checkout list | git sparse-checkout set --stdin\n>\n> The only time this would not work is if core.sparseCheckoutCone is\n> true, but the sparse-checkout file contains patterns that do not\n> match the expected pattern types for cone mode.\n>\n> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n> ---\n>  Documentation/git-sparse-checkout.txt | 11 ++++++++++-\n>  builtin/sparse-checkout.c             | 21 +++++++++++++++++++++\n>  t/t1091-sparse-checkout-builtin.sh    | 11 +++++++++++\n>  3 files changed, 42 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\n> index 9c3c66cc37..dcca9ee826 100644\n> --- a/Documentation/git-sparse-checkout.txt\n> +++ b/Documentation/git-sparse-checkout.txt\n> @@ -28,7 +28,7 @@ THE FUTURE.\n>  COMMANDS\n>  --------\n>  'list'::\n> -       Provide a list of the contents in the sparse-checkout file.\n> +       Describe the patterns in the sparse-checkout file.\n>\n>  'init'::\n>         Enable the `core.sparseCheckout` setting. If the\n> @@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match.\n>  If the patterns do match the expected format, then Git will use faster hash-\n>  based algorithms to compute inclusion in the sparse-checkout.\n>\n> +In the cone mode case, the `git sparse-checkout list` subcommand will list the\n> +folders that define the recursive patterns. For the example sparse-checkout file\nand here.\n\n> +above, the output is as follows:\n> +\n> +--------------------------\n> +$ git sparse-checkout list\n> +A/B/C\n> +--------------------------\n> +\n>  If `core.ignoreCase=true`, then the pattern-matching algorithm will use a\n>  case-insensitive check. This corrects for case mismatched filenames in the\n>  'git sparse-checkout set' command to reflect the expected cone in the working\n> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\n> index 5d62f7a66d..b3bed891cb 100644\n> --- a/builtin/sparse-checkout.c\n> +++ b/builtin/sparse-checkout.c\n> @@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)\n>\n>         memset(&pl, 0, sizeof(pl));\n>\n> +       pl.use_cone_patterns = core_sparse_checkout_cone;\n> +\n>         sparse_filename = get_sparse_checkout_filename();\n>         res = add_patterns_from_file_to_list(sparse_filename, \"\", 0, &pl, NULL);\n>         free(sparse_filename);\n> @@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)\n>                 return 0;\n>         }\n>\n> +       if (pl.use_cone_patterns) {\n> +               int i;\n> +               struct pattern_entry *pe;\n> +               struct hashmap_iter iter;\n> +               struct string_list sl = STRING_LIST_INIT_DUP;\n> +\n> +               hashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {\n> +                       /* pe->pattern starts with \"/\", skip it */\n> +                       string_list_insert(&sl, pe->pattern + 1);\n> +               }\n> +\n> +               string_list_sort(&sl);\n> +\n> +               for (i = 0; i < sl.nr; i++)\n> +                       printf(\"%s\\n\", sl.items[i].string);\n> +\n> +               return 0;\n> +       }\n> +\n>         write_patterns_to_file(stdout, &pl);\n>         clear_pattern_list(&pl);\n>\n> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\n> index 6f7e2d0c9e..37f6d8fa90 100755\n> --- a/t/t1091-sparse-checkout-builtin.sh\n> +++ b/t/t1091-sparse-checkout-builtin.sh\n> @@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' '\n>         test_cmp expect dir\n>  '\n>\n> +test_expect_success 'cone mode: list' '\n> +       cat >expect <<-EOF &&\n> +               folder1\n> +               folder2\n> +       EOF\n> +       git -C repo sparse-checkout set --stdin <expect &&\n> +       git -C repo sparse-checkout list >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       test_cmp expect actual\n> +'\n> +\n>  test_expect_success 'cone mode: set with nested folders' '\nThere's another one here but that's just the context area, so it'd be\na separate patch in a separate cleanup series...\n\n>         git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&\n>         test_line_count = 0 err &&\n> --\n\nThe rest looks good\n"},{"id":"389008","messageId":"CABPp-BHnTyYJ=RgQhnrRvcwSRd=kGHR=j5uvuVRYZjDNYAdX8Q@mail.gmail.com","threadId":"52524","inReplyTo":"331bb7d6fbec6f2f429feb36cf32e0931307ae0b.1577472469.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-27T21:46:09Z","receivedAt":"2019-12-27T21:46:18Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Derrick Stolee <dstolee@microsoft.com>\n>\n> Junio asked what the behavior is between the sparse-checkout feature\n> and the submodule feature.\n\nDoes this first sentence help future readers?  It is what spurred you\nto write the documentation, but it seems like something that could\njust be left out.\n\n> The sparse-checkout builtin has not changed\n> the way these features interact, but we may as well document it in\n> the builtin docs.\n>\n> Using 'git submodule (init|deinit)' a user can select a subset of\n> submodules to populate. This behaves very similar to the sparse-checkout\n> feature, but those directories contain their own .git directory\n> including an object database and ref space. To have the sparse-checkout\n> file also determine if those files should exist would easily cause\n> problems. Therefore, keeping these features independent in this way\n> is the best way forward.\n>\n> Also create a test that demonstrates this behavior to make sure\n> it doesn't change as the sparse-checkout feature evolves.\n>\n> Reported-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n> ---\n>  Documentation/git-sparse-checkout.txt | 10 ++++++++++\n>  t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++\n>  2 files changed, 38 insertions(+)\n>\n> diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\n> index dcca9ee826..2b7aaa0310 100644\n> --- a/Documentation/git-sparse-checkout.txt\n> +++ b/Documentation/git-sparse-checkout.txt\n> @@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the\n>  'git sparse-checkout set' command to reflect the expected cone in the working\n>  directory.\n>\n> +\n> +SUBMODULES\n> +----------\n> +\n> +If your repository contains one or more submodules, then those submodules will\n> +appear based on which you initialized with the `git submodule` command. If\n> +your sparse-checkout patterns exclude an initialized submodule, then that\n> +submodule will still appear in your working directory.\n> +\n> +\n>  SEE ALSO\n>  --------\n>\n> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\n> index 37f6d8fa90..5572beeeca 100755\n> --- a/t/t1091-sparse-checkout-builtin.sh\n> +++ b/t/t1091-sparse-checkout-builtin.sh\n> @@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '\n>         test_cmp expect dir\n>  '\n>\n> +test_expect_success 'interaction with submodules' '\n> +       git clone repo super &&\n> +       (\n> +               cd super &&\n> +               mkdir modules &&\n> +               git submodule add ../repo modules/child &&\n> +               git add . &&\n> +               git commit -m \"add submodule\" &&\n> +               git sparse-checkout init --cone &&\n> +               git sparse-checkout set folder1\n> +       ) &&\n> +       list_files super >dir &&\n> +       cat >expect <<-EOF &&\n> +               a\n> +               folder1\n> +               modules\n> +       EOF\n> +       test_cmp expect dir &&\n> +       list_files super/modules/child >dir &&\n> +       cat >expect <<-EOF &&\n> +               a\n> +               deep\n> +               folder1\n> +               folder2\n> +       EOF\n> +       test_cmp expect dir\n> +'\n> +\n>  test_done\n> --\n\nI read over the rest, and not being a submodule user I'm not sure what\nI'd expect.  But it certainly seems reasonable to document how these\nfeatures interact and that you haven't made any modifications in the\narea.\n"},{"id":"389009","messageId":"CABPp-BFAcWVrtoYMHghkk4AOEYaUWq0cD3xjtUwMPc2bfvrWSw@mail.gmail.com","threadId":"52524","inReplyTo":"pull.500.git.1577393347.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/1] sparse-checkout: list directories in cone mode","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-27T21:47:49Z","receivedAt":"2019-12-27T21:47:58Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, Dec 26, 2019 at 12:49 PM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> When in cone mode, \"git sparse-checkout set\" takes a list of folders and\n> constructs an ordered list of patterns for the sparse-checkout file. The\n> \"git sparse-checkout list\" subcommand outputs the contents of the\n> sparse-checkout file in a very basic way.\n>\n> This patch changes the behavior of \"git sparse-checkout list\" when\n> core.sparseCheckoutCone=true. It will output the folders that were used in\n> \"git sparse-checkout set\" to create the patterns, instead of the patterns\n> themselves.\n>\n> I believe this was requested in the initial review, but I cannot find that\n> message now.\n\nYeah, I think I mentioned it, but couldn't remember for sure.  Just\ndid a little digging and found\nhttps://lore.kernel.org/git/CABPp-BH13XbNR3MQKE7cHO5e=pMY7kLtGhkX1SQg_o9it=uUug@mail.gmail.com/:\n\n\"Should the list mode in cone mode be modified to just show the\ndirectories the user added?  It seems a little weird to show the\ninternal details of the implementation (all the parent directories and\nnegated entries and whatnot).  That's also not in a form that users\ncan pass along to future `sparse-checkout add` invocations.\"\n\nThough I then went into other tangents, which may have been what\ncaused it to be forgotten or overlooked.\n\n> I was going to include this as part of a longer follow-up series, but I\n> think this may be worth considering for the 2.25.0 release. Hence, it is\n> included by itself.\n\nYeah, I think this is a good and small fixup to a new feature in\n2.25.0, so it'd be nice if it could be included.  Not sure if it's too\nlate given that we're at -rc0, but here's a thumbs up from me if it\nmakes any difference.\n"},{"id":"389013","messageId":"xmqqtv5liek6.fsf@gitster-ct.c.googlers.com","threadId":"52524","inReplyTo":"CABPp-BHnTyYJ=RgQhnrRvcwSRd=kGHR=j5uvuVRYZjDNYAdX8Q@mail.gmail.com","subject":"Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-27T22:33:45Z","receivedAt":"2019-12-27T22:33:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elijah Newren <newren@gmail.com> writes:\n\n> On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n>>\n>> From: Derrick Stolee <dstolee@microsoft.com>\n>>\n>> Junio asked what the behavior is between the sparse-checkout feature\n>> and the submodule feature.\n>\n> Does this first sentence help future readers?  It is what spurred you\n> to write the documentation, but it seems like something that could\n> just be left out.\n\nI tend to agree.  It can safely go below the three-dash lines.\n"},{"id":"389058","messageId":"d934ac0a-d6d7-cf65-5d61-1196abc63ff8@gmail.com","threadId":"52524","inReplyTo":"CAPig+cTvFW_84TqKsOPjjBM37cX1OL9uX15APcEYpuKVjvM+dg@mail.gmail.com","subject":"Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-12-30T13:11:57Z","receivedAt":"2019-12-30T13:12:00Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/27/2019 3:20 PM, Eric Sunshine wrote:\n> On Fri, Dec 27, 2019 at 1:48 PM Derrick Stolee via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n>> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\n>> @@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '\n>> +test_expect_success 'interaction with submodules' '\n>> +       ...\n>> +       cat >expect <<-EOF &&\n>> +               a\n>> +               folder1\n>> +               modules\n>> +       EOF\n> \n> You would normally use \\-EOF rather than -EOF to make it clear that no\n> interpolation is needed/expected within the here-doc body. However,\n> this script is already full of -EOF when \\-EOF ought to be used, so\n> being consistent with existing tests may override an objection.\n> \n> Likewise, please note for future reference that the usual way\n> here-docs are formatted in Git test scripts is to indent the body of\n> the here-doc to the same level as the command which opens it. That is:\n\nThanks for pointing out the difference, except...\n \n>     cat >expect <<\\-EOF &&\n\nThis should be <<-\\EOF\n\n>     a\n>     folder1\n>     modules\n>     EOF\n> \n> But, again, this script is already full of these malformatted\n> here-docs, so maintaining consistency with the existing test in the\n> script is probably okay.\n\nHm. Having these lines have the same tabbing hurts my eyes (it is\nharder to see where the contents end, much like if we didn't tab\ninside a subshell or an if block).\n\nThis is also a place where we are inconsistent, and it's not just\nmy fault for writing the test script in my own style. Here are a\nfew scripts that tab the same way as here:\n\n\tt0008-ignore.sh\n\tt4124-apply-ws-rule.sh\n\tt9400-diff-highlight.sh\n\nThese are definitely the minority. I just mention them so anyone\nwho does a cleanup of this whitespace inconsistency takes the time\nto look for all examples.\n\nFor now, I'll fix the here-doc interpolation issue for this test,\nbut keep the whitespace matching the rest of the test script. I'll\nadd this concern to my next series.\n\nThanks,\n-Stolee\n"},{"id":"389062","messageId":"pull.500.v3.git.1577719993.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.v2.git.1577472469.gitgitgadget@gmail.com","subject":"[PATCH v3 0/2] sparse-checkout: list directories in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-30T15:33:11Z","receivedAt":"2019-12-30T15:33:19Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"When in cone mode, \"git sparse-checkout set\" takes a list of folders and\nconstructs an ordered list of patterns for the sparse-checkout file. The\n\"git sparse-checkout list\" subcommand outputs the contents of the\nsparse-checkout file in a very basic way.\n\nThis patch changes the behavior of \"git sparse-checkout list\" when\ncore.sparseCheckoutCone=true. It will output the folders that were used in\n\"git sparse-checkout set\" to create the patterns, instead of the patterns\nthemselves.\n\nI believe this was requested in the initial review, but I cannot find that\nmessage now.\n\nI was going to include this as part of a longer follow-up series, but I\nthink this may be worth considering for the 2.25.0 release. Hence, it is\nincluded by itself.\n\nUpdate in V2:\n\n * Fixed typos/word choice in commit message.\n   \n   \n * Added a second commit including clarification on interactions with\n   submodules.\n   \n   \n\nThanks, -Stolee\n\nDerrick Stolee (2):\n  sparse-checkout: list directories in cone mode\n  sparse-checkout: document interactions with submodules\n\n Documentation/git-sparse-checkout.txt | 21 ++++++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 39 +++++++++++++++++++++++++++\n 3 files changed, 80 insertions(+), 1 deletion(-)\n\n\nbase-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/500\n\nRange-diff vs v2:\n\n 1:  d6f4f40486 ! 1:  7d4295bd06 sparse-checkout: list folders in cone mode\n     @@ -1,17 +1,17 @@\n      Author: Derrick Stolee <dstolee@microsoft.com>\n      \n     -    sparse-checkout: list folders in cone mode\n     +    sparse-checkout: list directories in cone mode\n      \n          When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n     -    command takes a list of folders as input, then creates an ordered\n     -    list of sparse-checkout patterns such that those folders are\n     -    recursively included and all sibling entries along the parent folders\n     +    command takes a list of directories as input, then creates an ordered\n     +    list of sparse-checkout patterns such that those directories are\n     +    recursively included and all sibling entries along the parent directories\n          are also included. Listing the patterns is less user-friendly than the\n     -    folders themselves.\n     +    directories themselves.\n      \n          In cone mode, and as long as the patterns match the expected cone-mode\n          pattern types, change the output of 'git sparse-checkout list' to only\n     -    show the folders that created the patterns.\n     +    show the directories that created the patterns.\n      \n          With this change, the following piped commands would not change the\n          working directory:\n     @@ -41,8 +41,8 @@\n       based algorithms to compute inclusion in the sparse-checkout.\n       \n      +In the cone mode case, the `git sparse-checkout list` subcommand will list the\n     -+folders that define the recursive patterns. For the example sparse-checkout file\n     -+above, the output is as follows:\n     ++directories that define the recursive patterns. For the example sparse-checkout\n     ++file above, the output is as follows:\n      +\n      +--------------------------\n      +$ git sparse-checkout list\n 2:  331bb7d6fb ! 2:  74bbd0f84d sparse-checkout: document interactions with submodules\n     @@ -2,11 +2,6 @@\n      \n          sparse-checkout: document interactions with submodules\n      \n     -    Junio asked what the behavior is between the sparse-checkout feature\n     -    and the submodule feature. The sparse-checkout builtin has not changed\n     -    the way these features interact, but we may as well document it in\n     -    the builtin docs.\n     -\n          Using 'git submodule (init|deinit)' a user can select a subset of\n          submodules to populate. This behaves very similar to the sparse-checkout\n          feature, but those directories contain their own .git directory\n     @@ -61,14 +56,14 @@\n      +\t\tgit sparse-checkout set folder1\n      +\t) &&\n      +\tlist_files super >dir &&\n     -+\tcat >expect <<-EOF &&\n     ++\tcat >expect <<-\\EOF &&\n      +\t\ta\n      +\t\tfolder1\n      +\t\tmodules\n      +\tEOF\n      +\ttest_cmp expect dir &&\n      +\tlist_files super/modules/child >dir &&\n     -+\tcat >expect <<-EOF &&\n     ++\tcat >expect <<-\\EOF &&\n      +\t\ta\n      +\t\tdeep\n      +\t\tfolder1\n\n-- \ngitgitgadget\n"},{"id":"389063","messageId":"7d4295bd06868a86b7d1b32e8735c11795dbbab2.1577719993.git.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.v3.git.1577719993.gitgitgadget@gmail.com","subject":"[PATCH v3 1/2] sparse-checkout: list directories in cone mode","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-30T15:33:12Z","receivedAt":"2019-12-30T15:33:21Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <dstolee@microsoft.com>\n\nWhen core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\ncommand takes a list of directories as input, then creates an ordered\nlist of sparse-checkout patterns such that those directories are\nrecursively included and all sibling entries along the parent directories\nare also included. Listing the patterns is less user-friendly than the\ndirectories themselves.\n\nIn cone mode, and as long as the patterns match the expected cone-mode\npattern types, change the output of 'git sparse-checkout list' to only\nshow the directories that created the patterns.\n\nWith this change, the following piped commands would not change the\nworking directory:\n\n\tgit sparse-checkout list | git sparse-checkout set --stdin\n\nThe only time this would not work is if core.sparseCheckoutCone is\ntrue, but the sparse-checkout file contains patterns that do not\nmatch the expected pattern types for cone mode.\n\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/git-sparse-checkout.txt | 11 ++++++++++-\n builtin/sparse-checkout.c             | 21 +++++++++++++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 11 +++++++++++\n 3 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\nindex 9c3c66cc37..67be5247b9 100644\n--- a/Documentation/git-sparse-checkout.txt\n+++ b/Documentation/git-sparse-checkout.txt\n@@ -28,7 +28,7 @@ THE FUTURE.\n COMMANDS\n --------\n 'list'::\n-\tProvide a list of the contents in the sparse-checkout file.\n+\tDescribe the patterns in the sparse-checkout file.\n \n 'init'::\n \tEnable the `core.sparseCheckout` setting. If the\n@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match.\n If the patterns do match the expected format, then Git will use faster hash-\n based algorithms to compute inclusion in the sparse-checkout.\n \n+In the cone mode case, the `git sparse-checkout list` subcommand will list the\n+directories that define the recursive patterns. For the example sparse-checkout\n+file above, the output is as follows:\n+\n+--------------------------\n+$ git sparse-checkout list\n+A/B/C\n+--------------------------\n+\n If `core.ignoreCase=true`, then the pattern-matching algorithm will use a\n case-insensitive check. This corrects for case mismatched filenames in the\n 'git sparse-checkout set' command to reflect the expected cone in the working\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex 5d62f7a66d..b3bed891cb 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)\n \n \tmemset(&pl, 0, sizeof(pl));\n \n+\tpl.use_cone_patterns = core_sparse_checkout_cone;\n+\n \tsparse_filename = get_sparse_checkout_filename();\n \tres = add_patterns_from_file_to_list(sparse_filename, \"\", 0, &pl, NULL);\n \tfree(sparse_filename);\n@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)\n \t\treturn 0;\n \t}\n \n+\tif (pl.use_cone_patterns) {\n+\t\tint i;\n+\t\tstruct pattern_entry *pe;\n+\t\tstruct hashmap_iter iter;\n+\t\tstruct string_list sl = STRING_LIST_INIT_DUP;\n+\n+\t\thashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {\n+\t\t\t/* pe->pattern starts with \"/\", skip it */\n+\t\t\tstring_list_insert(&sl, pe->pattern + 1);\n+\t\t}\n+\n+\t\tstring_list_sort(&sl);\n+\n+\t\tfor (i = 0; i < sl.nr; i++)\n+\t\t\tprintf(\"%s\\n\", sl.items[i].string);\n+\n+\t\treturn 0;\n+\t}\n+\n \twrite_patterns_to_file(stdout, &pl);\n \tclear_pattern_list(&pl);\n \ndiff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\nindex 6f7e2d0c9e..37f6d8fa90 100755\n--- a/t/t1091-sparse-checkout-builtin.sh\n+++ b/t/t1091-sparse-checkout-builtin.sh\n@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' '\n \ttest_cmp expect dir\n '\n \n+test_expect_success 'cone mode: list' '\n+\tcat >expect <<-EOF &&\n+\t\tfolder1\n+\t\tfolder2\n+\tEOF\n+\tgit -C repo sparse-checkout set --stdin <expect &&\n+\tgit -C repo sparse-checkout list >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'cone mode: set with nested folders' '\n \tgit -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&\n \ttest_line_count = 0 err &&\n-- \ngitgitgadget\n\n"},{"id":"389064","messageId":"74bbd0f84d5f0c9eb7cdbd6983cf5c82ac3c7d18.1577719993.git.gitgitgadget@gmail.com","threadId":"52524","inReplyTo":"pull.500.v3.git.1577719993.gitgitgadget@gmail.com","subject":"[PATCH v3 2/2] sparse-checkout: document interactions with submodules","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-12-30T15:33:13Z","receivedAt":"2019-12-30T15:33:22Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <dstolee@microsoft.com>\n\nUsing 'git submodule (init|deinit)' a user can select a subset of\nsubmodules to populate. This behaves very similar to the sparse-checkout\nfeature, but those directories contain their own .git directory\nincluding an object database and ref space. To have the sparse-checkout\nfile also determine if those files should exist would easily cause\nproblems. Therefore, keeping these features independent in this way\nis the best way forward.\n\nAlso create a test that demonstrates this behavior to make sure\nit doesn't change as the sparse-checkout feature evolves.\n\nReported-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/git-sparse-checkout.txt | 10 ++++++++++\n t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++\n 2 files changed, 38 insertions(+)\n\ndiff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt\nindex 67be5247b9..3b341cf0fc 100644\n--- a/Documentation/git-sparse-checkout.txt\n+++ b/Documentation/git-sparse-checkout.txt\n@@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the\n 'git sparse-checkout set' command to reflect the expected cone in the working\n directory.\n \n+\n+SUBMODULES\n+----------\n+\n+If your repository contains one or more submodules, then those submodules will\n+appear based on which you initialized with the `git submodule` command. If\n+your sparse-checkout patterns exclude an initialized submodule, then that\n+submodule will still appear in your working directory.\n+\n+\n SEE ALSO\n --------\n \ndiff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh\nindex 37f6d8fa90..ff7f8f7a1f 100755\n--- a/t/t1091-sparse-checkout-builtin.sh\n+++ b/t/t1091-sparse-checkout-builtin.sh\n@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '\n \ttest_cmp expect dir\n '\n \n+test_expect_success 'interaction with submodules' '\n+\tgit clone repo super &&\n+\t(\n+\t\tcd super &&\n+\t\tmkdir modules &&\n+\t\tgit submodule add ../repo modules/child &&\n+\t\tgit add . &&\n+\t\tgit commit -m \"add submodule\" &&\n+\t\tgit sparse-checkout init --cone &&\n+\t\tgit sparse-checkout set folder1\n+\t) &&\n+\tlist_files super >dir &&\n+\tcat >expect <<-\\EOF &&\n+\t\ta\n+\t\tfolder1\n+\t\tmodules\n+\tEOF\n+\ttest_cmp expect dir &&\n+\tlist_files super/modules/child >dir &&\n+\tcat >expect <<-\\EOF &&\n+\t\ta\n+\t\tdeep\n+\t\tfolder1\n+\t\tfolder2\n+\tEOF\n+\ttest_cmp expect dir\n+'\n+\n test_done\n-- \ngitgitgadget\n"},{"id":"389077","messageId":"CABPp-BGxMJjLCq9S54qqxKq3eFfNiRjVNvKgebRXgxzp=CoFpA@mail.gmail.com","threadId":"52524","inReplyTo":"pull.500.v3.git.1577719993.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 0/2] sparse-checkout: list directories in cone mode","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2019-12-30T17:18:22Z","receivedAt":"2019-12-30T17:18:34Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi,\n\nThanks for the fixups.  Just two small comments.\n\nOn Mon, Dec 30, 2019 at 7:33 AM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> When in cone mode, \"git sparse-checkout set\" takes a list of folders and\n> constructs an ordered list of patterns for the sparse-checkout file. The\n> \"git sparse-checkout list\" subcommand outputs the contents of the\n> sparse-checkout file in a very basic way.\n>\n> This patch changes the behavior of \"git sparse-checkout list\" when\n> core.sparseCheckoutCone=true. It will output the folders that were used in\n> \"git sparse-checkout set\" to create the patterns, instead of the patterns\n> themselves.\n>\n> I believe this was requested in the initial review, but I cannot find that\n> message now.\n\nThis sentence isn't still true, is it?\n\n> I was going to include this as part of a longer follow-up series, but I\n> think this may be worth considering for the 2.25.0 release. Hence, it is\n> included by itself.\n>\n> Update in V2:\n>\n>  * Fixed typos/word choice in commit message.\n>\n>\n>  * Added a second commit including clarification on interactions with\n>    submodules.\n>\n>\n>\n> Thanks, -Stolee\n>\n> Derrick Stolee (2):\n>   sparse-checkout: list directories in cone mode\n>   sparse-checkout: document interactions with submodules\n>\n>  Documentation/git-sparse-checkout.txt | 21 ++++++++++++++-\n>  builtin/sparse-checkout.c             | 21 +++++++++++++++\n>  t/t1091-sparse-checkout-builtin.sh    | 39 +++++++++++++++++++++++++++\n>  3 files changed, 80 insertions(+), 1 deletion(-)\n>\n>\n> base-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v3\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v3\n> Pull-Request: https://github.com/gitgitgadget/git/pull/500\n>\n> Range-diff vs v2:\n>\n>  1:  d6f4f40486 ! 1:  7d4295bd06 sparse-checkout: list folders in cone mode\n>      @@ -1,17 +1,17 @@\n>       Author: Derrick Stolee <dstolee@microsoft.com>\n>\n>      -    sparse-checkout: list folders in cone mode\n>      +    sparse-checkout: list directories in cone mode\n>\n>           When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'\n>      -    command takes a list of folders as input, then creates an ordered\n>      -    list of sparse-checkout patterns such that those folders are\n>      -    recursively included and all sibling entries along the parent folders\n>      +    command takes a list of directories as input, then creates an ordered\n>      +    list of sparse-checkout patterns such that those directories are\n>      +    recursively included and all sibling entries along the parent directories\n>           are also included. Listing the patterns is less user-friendly than the\n>      -    folders themselves.\n>      +    directories themselves.\n>\n>           In cone mode, and as long as the patterns match the expected cone-mode\n>           pattern types, change the output of 'git sparse-checkout list' to only\n>      -    show the folders that created the patterns.\n>      +    show the directories that created the patterns.\n>\n>           With this change, the following piped commands would not change the\n>           working directory:\n>      @@ -41,8 +41,8 @@\n>        based algorithms to compute inclusion in the sparse-checkout.\n>\n>       +In the cone mode case, the `git sparse-checkout list` subcommand will list the\n>      -+folders that define the recursive patterns. For the example sparse-checkout file\n>      -+above, the output is as follows:\n>      ++directories that define the recursive patterns. For the example sparse-checkout\n>      ++file above, the output is as follows:\n>       +\n>       +--------------------------\n>       +$ git sparse-checkout list\n>  2:  331bb7d6fb ! 2:  74bbd0f84d sparse-checkout: document interactions with submodules\n>      @@ -2,11 +2,6 @@\n>\n>           sparse-checkout: document interactions with submodules\n>\n>      -    Junio asked what the behavior is between the sparse-checkout feature\n>      -    and the submodule feature. The sparse-checkout builtin has not changed\n>      -    the way these features interact, but we may as well document it in\n>      -    the builtin docs.\n>      -\n\nI actually liked the second sentence of this paragraph and thought it\nprovided useful information for future readers; I only thought the\nfirst sentence should be removed.\n\n>           Using 'git submodule (init|deinit)' a user can select a subset of\n>           submodules to populate. This behaves very similar to the sparse-checkout\n>           feature, but those directories contain their own .git directory\n>      @@ -61,14 +56,14 @@\n>       +         git sparse-checkout set folder1\n>       + ) &&\n>       + list_files super >dir &&\n>      -+ cat >expect <<-EOF &&\n>      ++ cat >expect <<-\\EOF &&\n>       +         a\n>       +         folder1\n>       +         modules\n>       + EOF\n>       + test_cmp expect dir &&\n>       + list_files super/modules/child >dir &&\n>      -+ cat >expect <<-EOF &&\n>      ++ cat >expect <<-\\EOF &&\n>       +         a\n>       +         deep\n>       +         folder1\n>\n> --\n> gitgitgadget\n"}]}