sparse-checkout: list directories in cone mode
cover sparse-checkout: list directories in cone mode
When in cone mode, "git sparse-checkout set" takes a list of folders and constructs an ordered list of patterns for the sparse-checkout file. The "git sparse-checkout list" subcommand outputs the contents of the sparse-checkout file in a very basic way.
This patch changes the behavior of "git sparse-checkout list" when core.sparseCheckoutCone=true. It will output the folders that were used in "git sparse-checkout set" to create the patterns, instead of the patterns themselves.
I believe this was requested in the initial review, but I cannot find that message now.
I was going to include this as part of a longer follow-up series, but I think this may be worth considering for the 2.25.0 release. Hence, it is included by itself.
Thanks, -Stolee
Derrick Stolee (1):
sparse-checkout: list folders in cone mode
Documentation/git-sparse-checkout.txt | 11 ++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
base-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/500
Signature · 1 line
gitgitgadget
PATCH 1/1 sparse-checkout: list folders in cone mode
From: Derrick Stolee <[email protected]>
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command taks a list of folders as input, then creates an ordered list of sparse-checkout patterns such that those folders are recursively included and all sibling blobs along the parent folders are also included. Listing the patterns is less user-friendly than the folders themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the folders that created the patterns.
With this change, the following piped commands would not change the working directory:
git sparse-checkout list | git sparse-checkout set --stdin
The only time this would not work is if core.sparseCheckoutCone is true, but the sparse-checkout file contains patterns that do not match the expected pattern types for cone mode.
--- Documentation/git-sparse-checkout.txt | 11 ++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
Documentation/git-sparse-checkout.txt +10 -1
@@ -28,7 +28,7 @@ THE FUTURE. COMMANDS -------- 'list':: - Provide a list of the contents in the sparse-checkout file. + Describe the patterns in the sparse-checkout file. 'init':: Enable the `core.sparseCheckout` setting. If the
@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match. If the patterns do match the expected format, then Git will use faster hash- based algorithms to compute inclusion in the sparse-checkout. +In the cone mode case, the `git sparse-checkout list` subcommand will list the +folders that define the recursive patterns. For the example sparse-checkout file +above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- + If `core.ignoreCase=true`, then the pattern-matching algorithm will use a case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working
builtin/sparse-checkout.c +21 -0
@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)memset (&pl,0 ,sizeof (pl)); + pl.use_cone_patterns = core_sparse_checkout_cone; + sparse_filename =get_sparse_checkout_filename (); res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , &pl,NULL );free (sparse_filename);
@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)return 0 ; } +if (pl.use_cone_patterns) { +int i; +struct pattern_entry *pe; +struct hashmap_iter iter; +struct string_list sl =STRING_LIST_INIT_DUP ; + +hashmap_for_each_entry (&pl.recursive_hashmap, &iter, pe, ent) { +/* pe->pattern starts with "/", skip it */ +string_list_insert (&sl, pe->pattern +1 ); + } + +string_list_sort (&sl); + +for (i =0 ; i < sl.nr; i++) +printf ("%s\n" , sl.items[i].string); + +return 0 ; + } +write_patterns_to_file (stdout, &pl);clear_pattern_list (&pl);
t/t1091-sparse-checkout-builtin.sh +11 -0
@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir ' +test_expect_success 'cone mode: list' ' + cat >expect <<-EOF && + folder1 + folder2 + EOF + git -C repo sparse-checkout set --stdin <expect && + git -C repo sparse-checkout list >actual 2>err && + test_must_be_empty err && + test_cmp expect actual +' + test_expect_success 'cone mode: set with nested folders' ' git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err &&
Signature · 1 line
gitgitgadget
Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
Quoted 3 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
s/folder/directory/ everywhere as the rest of Git.
Quoted 2 lines
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command taks a list of folders as input, then creates an ordered
"takes"
Quoted 2 lines
list of sparse-checkout patterns such that those folders are recursively included and all sibling blobs along the parent folders
In this sentence, what does a "blob" really mean? Do you mean a filesystem entity, that is not a folder, that is immediately contained in the "parent folder" (in other words, regular files and symbolic links)?
How would this interact with a submodule by the way?
Quoted 7 lines
are also included. Listing the patterns is less user-friendly than the folders themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the folders that created the patterns.
...
Documentation/git-sparse-checkout.txt expecting patterns of these types. Git will warn if the patterns do not match. · line 161
Quoted 9 lines
Documentation/git-sparse-checkout.txt +9
-0+In the cone mode case, the `git sparse-checkout list` subcommand will list the +folders that define the recursive patterns. For the example sparse-checkout file +above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- +
Sounds like a worthwhile usability improvement.
Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
s/folder/directory/ everywhere as the rest of Git.
Quoted 2 lines
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command taks a list of folders as input, then creates an ordered
"takes"
Good catch.
Quoted 7 lines
Quoted 2 lines
list of sparse-checkout patterns such that those folders are recursively included and all sibling blobs along the parent folders
In this sentence, what does a "blob" really mean? Do you mean a filesystem entity, that is not a folder, that is immediately contained in the "parent folder" (in other words, regular files and symbolic links)?
You're right, I'm using strange wording here. How about "sibling entries"?
Quoted 1 line
How would this interact with a submodule by the way?
I just checked with the Git repo by running:
git submodule init
git submodule update
git sparse-checkout init --cone
The working directory then contains all blobs at root AND the sha1collisiondetection submodule. Interesting that the sparse- checkout feature ignores submodules. That seems like the best approach since the user can already enlist in a subset of the submodules.
Quoted 18 lines
Quoted 7 lines
are also included. Listing the patterns is less user-friendly than the folders themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the folders that created the patterns.
...Documentation/git-sparse-checkout.txt expecting patterns of these types. Git will warn if the patterns do not match. · line 161
Quoted 9 lines
Documentation/git-sparse-checkout.txt +9
-0+In the cone mode case, the `git sparse-checkout list` subcommand will list the +folders that define the recursive patterns. For the example sparse-checkout file +above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- +Sounds like a worthwhile usability improvement.
Thanks,
-Stolee
Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
In reply to Derrick Stolee via GitGitGadgetQuoted 9 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command taks a list of folders as input, then creates an ordered list of sparse-checkout patterns such that those folders are recursively included and all sibling blobs along the parent folders are also included. Listing the patterns is less user-friendly than the folders themselves.
I didn't spot anything that Junio hasn't already mentioned, but I'm just chiming in to say that this sounds good and thanks so much for working on the sparse-checkout command. :-)
v2 cover sparse-checkout: list directories in cone mode
In reply to Derrick Stolee via GitGitGadgetWhen in cone mode, "git sparse-checkout set" takes a list of folders and constructs an ordered list of patterns for the sparse-checkout file. The "git sparse-checkout list" subcommand outputs the contents of the sparse-checkout file in a very basic way.
This patch changes the behavior of "git sparse-checkout list" when core.sparseCheckoutCone=true. It will output the folders that were used in "git sparse-checkout set" to create the patterns, instead of the patterns themselves.
I believe this was requested in the initial review, but I cannot find that message now.
I was going to include this as part of a longer follow-up series, but I think this may be worth considering for the 2.25.0 release. Hence, it is included by itself.
Update in V2:
* Fixed typos/word choice in commit message.
* Added a second commit including clarification on interactions with submodules.
Thanks, -Stolee
Derrick Stolee (2):
sparse-checkout: list folders in cone mode
sparse-checkout: document interactions with submodules
Documentation/git-sparse-checkout.txt | 21 ++++++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 39 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)
base-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/500
Range-diff vs v1:
1: 07be7b8dda ! 1: d6f4f40486 sparse-checkout: list folders in cone mode
@@ -3,9 +3,9 @@
sparse-checkout: list folders in cone mode
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'
- command taks a list of folders as input, then creates an ordered
+ command takes a list of folders as input, then creates an ordered
list of sparse-checkout patterns such that those folders are
- recursively included and all sibling blobs along the parent folders
+ recursively included and all sibling entries along the parent folders
are also included. Listing the patterns is less user-friendly than the folders themselves.
-: ---------- > 2: 331bb7d6fb sparse-checkout: document interactions with submodules
Signature · 1 line
gitgitgadget
PATCH v2 1/2 sparse-checkout: list folders in cone mode
From: Derrick Stolee <[email protected]>
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command takes a list of folders as input, then creates an ordered list of sparse-checkout patterns such that those folders are recursively included and all sibling entries along the parent folders are also included. Listing the patterns is less user-friendly than the folders themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the folders that created the patterns.
With this change, the following piped commands would not change the working directory:
git sparse-checkout list | git sparse-checkout set --stdin
The only time this would not work is if core.sparseCheckoutCone is true, but the sparse-checkout file contains patterns that do not match the expected pattern types for cone mode.
--- Documentation/git-sparse-checkout.txt | 11 ++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
Documentation/git-sparse-checkout.txt +10 -1
@@ -28,7 +28,7 @@ THE FUTURE. COMMANDS -------- 'list':: - Provide a list of the contents in the sparse-checkout file. + Describe the patterns in the sparse-checkout file. 'init':: Enable the `core.sparseCheckout` setting. If the
@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match. If the patterns do match the expected format, then Git will use faster hash- based algorithms to compute inclusion in the sparse-checkout. +In the cone mode case, the `git sparse-checkout list` subcommand will list the +folders that define the recursive patterns. For the example sparse-checkout file +above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- + If `core.ignoreCase=true`, then the pattern-matching algorithm will use a case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working
builtin/sparse-checkout.c +21 -0
@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)memset (&pl,0 ,sizeof (pl)); + pl.use_cone_patterns = core_sparse_checkout_cone; + sparse_filename =get_sparse_checkout_filename (); res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , &pl,NULL );free (sparse_filename);
@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)return 0 ; } +if (pl.use_cone_patterns) { +int i; +struct pattern_entry *pe; +struct hashmap_iter iter; +struct string_list sl =STRING_LIST_INIT_DUP ; + +hashmap_for_each_entry (&pl.recursive_hashmap, &iter, pe, ent) { +/* pe->pattern starts with "/", skip it */ +string_list_insert (&sl, pe->pattern +1 ); + } + +string_list_sort (&sl); + +for (i =0 ; i < sl.nr; i++) +printf ("%s\n" , sl.items[i].string); + +return 0 ; + } +write_patterns_to_file (stdout, &pl);clear_pattern_list (&pl);
t/t1091-sparse-checkout-builtin.sh +11 -0
@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir ' +test_expect_success 'cone mode: list' ' + cat >expect <<-EOF && + folder1 + folder2 + EOF + git -C repo sparse-checkout set --stdin <expect && + git -C repo sparse-checkout list >actual 2>err && + test_must_be_empty err && + test_cmp expect actual +' + test_expect_success 'cone mode: set with nested folders' ' git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err &&
Signature · 1 line
gitgitgadget
Re: [PATCH v2 1/2] sparse-checkout: list folders in cone mode
Quoted 5 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command takes a list of folders as input, then creates an ordered
s/folders/directories/
Quoted 1 line
list of sparse-checkout patterns such that those folders are
s/folders/directories/
Quoted 1 line
recursively included and all sibling entries along the parent folders
again here.
Quoted 2 lines
are also included. Listing the patterns is less user-friendly than the folders themselves.
and here.
Quoted 4 lines
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the folders that created the patterns.
and here.
Quoted 31 lines
With this change, the following piped commands would not change the working directory:
git sparse-checkout list | git sparse-checkout set --stdinThe only time this would not work is if core.sparseCheckoutCone is true, but the sparse-checkout file contains patterns that do not match the expected pattern types for cone mode.
Signed-off-by Derrick Stolee <[email protected]>--- Documentation/git-sparse-checkout.txt | 11 ++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)Documentation/git-sparse-checkout.txt +1
-1@@ -28,7 +28,7 @@ THE FUTURE. COMMANDS -------- 'list':: - Provide a list of the contents in the sparse-checkout file. + Describe the patterns in the sparse-checkout file. 'init':: Enable the `core.sparseCheckout` setting. If the
Documentation/git-sparse-checkout.txt expecting patterns of these types. Git will warn if the patterns do not match. · line 154
Quoted 5 lines
Documentation/git-sparse-checkout.txt +2
-0@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match. If the patterns do match the expected format, then Git will use faster hash- based algorithms to compute inclusion in the sparse-checkout. +In the cone mode case, the `git sparse-checkout list` subcommand will list the +folders that define the recursive patterns. For the example sparse-checkout file
and here.
Quoted 59 lines
Documentation/git-sparse-checkout.txt +7
-0+above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- + If `core.ignoreCase=true`, then the pattern-matching algorithm will use a case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the workingbuiltin/sparse-checkout.c +21
-0@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)memset (&pl,0 ,sizeof (pl)); + pl.use_cone_patterns = core_sparse_checkout_cone; + sparse_filename =get_sparse_checkout_filename (); res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , &pl,NULL );free (sparse_filename);@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)return 0 ; } +if (pl.use_cone_patterns) { +int i; +struct pattern_entry *pe; +struct hashmap_iter iter; +struct string_list sl =STRING_LIST_INIT_DUP ; + +hashmap_for_each_entry (&pl.recursive_hashmap, &iter, pe, ent) { +/* pe->pattern starts with "/", skip it */ +string_list_insert (&sl, pe->pattern +1 ); + } + +string_list_sort (&sl); + +for (i =0 ; i < sl.nr; i++) +printf ("%s\n" , sl.items[i].string); + +return 0 ; + } +write_patterns_to_file (stdout, &pl);clear_pattern_list (&pl);t/t1091-sparse-checkout-builtin.sh +2
-0@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir ' +test_expect_success 'cone mode: list' ' + cat >expect <<-EOF &&
t/t1091-sparse-checkout-builtin.sh test_expect_success 'cone mode: init and set' ' · line 260
Quoted 10 lines
t/t1091-sparse-checkout-builtin.sh +9
-0+ folder1 + folder2 + EOF + git -C repo sparse-checkout set --stdin <expect && + git -C repo sparse-checkout list >actual 2>err && + test_must_be_empty err && + test_cmp expect actual +' + test_expect_success 'cone mode: set with nested folders' '
There's another one here but that's just the context area, so it'd be a separate patch in a separate cleanup series...
t/t1091-sparse-checkout-builtin.sh test_expect_success 'cone mode: init and set' '
Quoted 3 lines
t/t1091-sparse-checkout-builtin.sh +0
-1git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err && --
The rest looks good
PATCH v2 2/2 sparse-checkout: document interactions with submodules
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
Junio asked what the behavior is between the sparse-checkout feature and the submodule feature. The sparse-checkout builtin has not changed the way these features interact, but we may as well document it in the builtin docs.
Using 'git submodule (init|deinit)' a user can select a subset of submodules to populate. This behaves very similar to the sparse-checkout feature, but those directories contain their own .git directory including an object database and ref space. To have the sparse-checkout file also determine if those files should exist would easily cause problems. Therefore, keeping these features independent in this way is the best way forward.
Also create a test that demonstrates this behavior to make sure it doesn't change as the sparse-checkout feature evolves.
--- Documentation/git-sparse-checkout.txt | 10 ++++++++++ t/t1091-sparse-checkout-builtin.sh | 28 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
Documentation/git-sparse-checkout.txt +10 -0
@@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working directory. + +SUBMODULES +---------- + +If your repository contains one or more submodules, then those submodules will +appear based on which you initialized with the `git submodule` command. If +your sparse-checkout patterns exclude an initialized submodule, then that +submodule will still appear in your working directory. + + SEE ALSO --------
t/t1091-sparse-checkout-builtin.sh +28 -0
@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' test_cmp expect dir ' +test_expect_success 'interaction with submodules' ' + git clone repo super && + ( + cd super && + mkdir modules && + git submodule add ../repo modules/child && + git add . && + git commit -m "add submodule" && + git sparse-checkout init --cone && + git sparse-checkout set folder1 + ) && + list_files super >dir && + cat >expect <<-EOF && + a + folder1 + modules + EOF + test_cmp expect dir && + list_files super/modules/child >dir && + cat >expect <<-EOF && + a + deep + folder1 + folder2 + EOF + test_cmp expect dir +' + test_done
Signature · 1 line
gitgitgadget
Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
t/t1091-sparse-checkout-builtin.sh test_expect_success 'cone mode: set with core.ignoreCase=true' ' · line 346
Quoted 9 lines · Derrick Stolee via GitGitGadget
t/t1091-sparse-checkout-builtin.sh +7
-0@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' +test_expect_success 'interaction with submodules' ' + ... + cat >expect <<-EOF && + a + folder1 + modules + EOF
You would normally use \-EOF rather than -EOF to make it clear that no interpolation is needed/expected within the here-doc body. However, this script is already full of -EOF when \-EOF ought to be used, so being consistent with existing tests may override an objection.
Likewise, please note for future reference that the usual way here-docs are formatted in Git test scripts is to indent the body of the here-doc to the same level as the command which opens it. That is:
cat >expect <<\-EOF &&
a
folder1
modules
EOFBut, again, this script is already full of these malformatted here-docs, so maintaining consistency with the existing test in the script is probably okay.
(Of course, a preparatory patch fixing these here-doc issues would be welcome, but might also be outside the scope of this submission. And, fixing these very minor issues is quite low-priority, so I wouldn't expect or demand it.)
Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
Quoted 17 lines · Eric Sunshine
t/t1091-sparse-checkout-builtin.sh test_expect_success 'cone mode: set with core.ignoreCase=true' ' · line 346
Quoted 9 lines · Derrick Stolee via GitGitGadget
t/t1091-sparse-checkout-builtin.sh +7
-0@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' +test_expect_success 'interaction with submodules' ' + ... + cat >expect <<-EOF && + a + folder1 + modules + EOFYou would normally use \-EOF rather than
-EOFto make it clear that no interpolation is needed/expected within the here-doc body. However, this script is already full of-EOFwhen \-EOF ought to be used, so being consistent with existing tests may override an objection.
Quoted 3 lines
Likewise, please note for future reference that the usual way here-docs are formatted in Git test scripts is to indent the body of the here-doc to the same level as the command which opens it. That is:
Thanks for pointing out the difference, except...
Quoted 1 line
cat >expect <<\-EOF &&
This should be <<-\EOF
Quoted 8 lines
a
folder1
modules
EOFBut, again, this script is already full of these malformatted here-docs, so maintaining consistency with the existing test in the script is probably okay.
Hm. Having these lines have the same tabbing hurts my eyes (it is harder to see where the contents end, much like if we didn't tab inside a subshell or an if block).
This is also a place where we are inconsistent, and it's not just my fault for writing the test script in my own style. Here are a few scripts that tab the same way as here:
t0008-ignore.sh t4124-apply-ws-rule.sh t9400-diff-highlight.sh
These are definitely the minority. I just mention them so anyone who does a cleanup of this whitespace inconsistency takes the time to look for all examples.
For now, I'll fix the here-doc interpolation issue for this test, but keep the whitespace matching the rest of the test script. I'll add this concern to my next series.
Thanks,
-Stolee
Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
In reply to Derrick Stolee via GitGitGadgetQuoted 5 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Junio asked what the behavior is between the sparse-checkout feature and the submodule feature.
Does this first sentence help future readers? It is what spurred you to write the documentation, but it seems like something that could just be left out.
Quoted 71 lines
The sparse-checkout builtin has not changed
the way these features interact, but we may as well document it in the builtin docs.Using 'git submodule (init|deinit)' a user can select a subset of submodules to populate. This behaves very similar to the sparse-checkout feature, but those directories contain their own .git directory including an object database and ref space. To have the sparse-checkout file also determine if those files should exist would easily cause problems. Therefore, keeping these features independent in this way is the best way forward.
Also create a test that demonstrates this behavior to make sure it doesn't change as the sparse-checkout feature evolves.
Reported-by Junio C Hamano <[email protected]>Signed-off-by Derrick Stolee <[email protected]>--- Documentation/git-sparse-checkout.txt | 10 ++++++++++ t/t1091-sparse-checkout-builtin.sh | 28 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)Documentation/git-sparse-checkout.txt +10
-0@@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working directory. + +SUBMODULES +---------- + +If your repository contains one or more submodules, then those submodules will +appear based on which you initialized with the `git submodule` command. If +your sparse-checkout patterns exclude an initialized submodule, then that +submodule will still appear in your working directory. + + SEE ALSO --------t/t1091-sparse-checkout-builtin.sh +20
-0@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' test_cmp expect dir ' +test_expect_success 'interaction with submodules' ' + git clone repo super && + ( + cd super && + mkdir modules && + git submodule add ../repo modules/child && + git add . && + git commit -m "add submodule" && + git sparse-checkout init --cone && + git sparse-checkout set folder1 + ) && + list_files super >dir && + cat >expect <<-EOF && + a + folder1 + modules + EOF + test_cmp expect dir && + list_files super/modules/child >dir && + cat >expect <<-EOF &&
t/t1091-sparse-checkout-builtin.sh test_expect_success 'cone mode: set with core.ignoreCase=true' '
Quoted 10 lines
t/t1091-sparse-checkout-builtin.sh +8
-1+ a + deep + folder1 + folder2 + EOF + test_cmp expect dir +' + test_done --
I read over the rest, and not being a submodule user I'm not sure what I'd expect. But it certainly seems reasonable to document how these features interact and that you haven't made any modifications in the area.
Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
Quoted 11 lines · Elijah Newren
Quoted 5 lines · Derrick Stolee via GitGitGadget
From: Derrick Stolee <[email protected]>
Junio asked what the behavior is between the sparse-checkout feature and the submodule feature.
Does this first sentence help future readers? It is what spurred you to write the documentation, but it seems like something that could just be left out.
I tend to agree. It can safely go below the three-dash lines.
v3 cover sparse-checkout: list directories in cone mode
In reply to Derrick Stolee via GitGitGadgetWhen in cone mode, "git sparse-checkout set" takes a list of folders and constructs an ordered list of patterns for the sparse-checkout file. The "git sparse-checkout list" subcommand outputs the contents of the sparse-checkout file in a very basic way.
This patch changes the behavior of "git sparse-checkout list" when core.sparseCheckoutCone=true. It will output the folders that were used in "git sparse-checkout set" to create the patterns, instead of the patterns themselves.
I believe this was requested in the initial review, but I cannot find that message now.
I was going to include this as part of a longer follow-up series, but I think this may be worth considering for the 2.25.0 release. Hence, it is included by itself.
Update in V2:
* Fixed typos/word choice in commit message.
* Added a second commit including clarification on interactions with submodules.
Thanks, -Stolee
Derrick Stolee (2):
sparse-checkout: list directories in cone mode
sparse-checkout: document interactions with submodules
Documentation/git-sparse-checkout.txt | 21 ++++++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 39 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)
base-commit: 761e3d26bbe44c51f83c4f1ad198461f57029ebd
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/500
Range-diff vs v2:
1: d6f4f40486 ! 1: 7d4295bd06 sparse-checkout: list folders in cone mode
@@ -1,17 +1,17 @@
Author: Derrick Stolee <[email protected]>
- sparse-checkout: list folders in cone mode
+ sparse-checkout: list directories in cone mode
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'
- command takes a list of folders as input, then creates an ordered
- list of sparse-checkout patterns such that those folders are
- recursively included and all sibling entries along the parent folders
+ command takes a list of directories as input, then creates an ordered
+ list of sparse-checkout patterns such that those directories are
+ recursively included and all sibling entries along the parent directories
are also included. Listing the patterns is less user-friendly than the
- folders themselves.
+ directories themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only
- show the folders that created the patterns.
+ show the directories that created the patterns.
With this change, the following piped commands would not change the working directory:
@@ -41,8 +41,8 @@
based algorithms to compute inclusion in the sparse-checkout.
+In the cone mode case, the git sparse-checkout list subcommand will list the
-+folders that define the recursive patterns. For the example sparse-checkout file -+above, the output is as follows:
++directories that define the recursive patterns. For the example sparse-checkout ++file above, the output is as follows:
+
+--------------------------
+$ git sparse-checkout list
2: 331bb7d6fb ! 2: 74bbd0f84d sparse-checkout: document interactions with submodules
@@ -2,11 +2,6 @@
sparse-checkout: document interactions with submodules
- Junio asked what the behavior is between the sparse-checkout feature
- and the submodule feature. The sparse-checkout builtin has not changed
- the way these features interact, but we may as well document it in
- the builtin docs.
-
Using 'git submodule (init|deinit)' a user can select a subset of
submodules to populate. This behaves very similar to the sparse-checkout
feature, but those directories contain their own .git directory
@@ -61,14 +56,14 @@
+ git sparse-checkout set folder1
+ ) &&
+ list_files super >dir &&
-+ cat >expect <<-EOF &&
++ cat >expect <<-\EOF &&
+ a
+ folder1
+ modules
+ EOF
+ test_cmp expect dir &&
+ list_files super/modules/child >dir &&
-+ cat >expect <<-EOF &&
++ cat >expect <<-\EOF &&
+ a
+ deep
+ folder1Signature · 1 line
gitgitgadget
PATCH v3 1/2 sparse-checkout: list directories in cone mode
From: Derrick Stolee <[email protected]>
When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command takes a list of directories as input, then creates an ordered list of sparse-checkout patterns such that those directories are recursively included and all sibling entries along the parent directories are also included. Listing the patterns is less user-friendly than the directories themselves.
In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only show the directories that created the patterns.
With this change, the following piped commands would not change the working directory:
git sparse-checkout list | git sparse-checkout set --stdin
The only time this would not work is if core.sparseCheckoutCone is true, but the sparse-checkout file contains patterns that do not match the expected pattern types for cone mode.
--- Documentation/git-sparse-checkout.txt | 11 ++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
Documentation/git-sparse-checkout.txt +10 -1
@@ -28,7 +28,7 @@ THE FUTURE. COMMANDS -------- 'list':: - Provide a list of the contents in the sparse-checkout file. + Describe the patterns in the sparse-checkout file. 'init':: Enable the `core.sparseCheckout` setting. If the
@@ -150,6 +150,15 @@ expecting patterns of these types. Git will warn if the patterns do not match. If the patterns do match the expected format, then Git will use faster hash- based algorithms to compute inclusion in the sparse-checkout. +In the cone mode case, the `git sparse-checkout list` subcommand will list the +directories that define the recursive patterns. For the example sparse-checkout +file above, the output is as follows: + +-------------------------- +$ git sparse-checkout list +A/B/C +-------------------------- + If `core.ignoreCase=true`, then the pattern-matching algorithm will use a case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working
builtin/sparse-checkout.c +21 -0
@@ -53,6 +53,8 @@ static int sparse_checkout_list(int argc, const char **argv)memset (&pl,0 ,sizeof (pl)); + pl.use_cone_patterns = core_sparse_checkout_cone; + sparse_filename =get_sparse_checkout_filename (); res =add_patterns_from_file_to_list (sparse_filename,"" ,0 , &pl,NULL );free (sparse_filename);
@@ -62,6 +64,25 @@ static int sparse_checkout_list(int argc, const char **argv)return 0 ; } +if (pl.use_cone_patterns) { +int i; +struct pattern_entry *pe; +struct hashmap_iter iter; +struct string_list sl =STRING_LIST_INIT_DUP ; + +hashmap_for_each_entry (&pl.recursive_hashmap, &iter, pe, ent) { +/* pe->pattern starts with "/", skip it */ +string_list_insert (&sl, pe->pattern +1 ); + } + +string_list_sort (&sl); + +for (i =0 ; i < sl.nr; i++) +printf ("%s\n" , sl.items[i].string); + +return 0 ; + } +write_patterns_to_file (stdout, &pl);clear_pattern_list (&pl);
t/t1091-sparse-checkout-builtin.sh +11 -0
@@ -246,6 +246,17 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir ' +test_expect_success 'cone mode: list' ' + cat >expect <<-EOF && + folder1 + folder2 + EOF + git -C repo sparse-checkout set --stdin <expect && + git -C repo sparse-checkout list >actual 2>err && + test_must_be_empty err && + test_cmp expect actual +' + test_expect_success 'cone mode: set with nested folders' ' git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err &&
Signature · 1 line
gitgitgadget
PATCH v3 2/2 sparse-checkout: document interactions with submodules
In reply to Derrick Stolee via GitGitGadgetFrom: Derrick Stolee <[email protected]>
Using 'git submodule (init|deinit)' a user can select a subset of submodules to populate. This behaves very similar to the sparse-checkout feature, but those directories contain their own .git directory including an object database and ref space. To have the sparse-checkout file also determine if those files should exist would easily cause problems. Therefore, keeping these features independent in this way is the best way forward.
Also create a test that demonstrates this behavior to make sure it doesn't change as the sparse-checkout feature evolves.
--- Documentation/git-sparse-checkout.txt | 10 ++++++++++ t/t1091-sparse-checkout-builtin.sh | 28 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
Documentation/git-sparse-checkout.txt +10 -0
@@ -164,6 +164,16 @@ case-insensitive check. This corrects for case mismatched filenames in the 'git sparse-checkout set' command to reflect the expected cone in the working directory. + +SUBMODULES +---------- + +If your repository contains one or more submodules, then those submodules will +appear based on which you initialized with the `git submodule` command. If +your sparse-checkout patterns exclude an initialized submodule, then that +submodule will still appear in your working directory. + + SEE ALSO --------
t/t1091-sparse-checkout-builtin.sh +28 -0
@@ -340,4 +340,32 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' test_cmp expect dir ' +test_expect_success 'interaction with submodules' ' + git clone repo super && + ( + cd super && + mkdir modules && + git submodule add ../repo modules/child && + git add . && + git commit -m "add submodule" && + git sparse-checkout init --cone && + git sparse-checkout set folder1 + ) && + list_files super >dir && + cat >expect <<-\EOF && + a + folder1 + modules + EOF + test_cmp expect dir && + list_files super/modules/child >dir && + cat >expect <<-\EOF && + a + deep + folder1 + folder2 + EOF + test_cmp expect dir +' + test_done
Signature · 1 line
gitgitgadget
Hi,
Thanks for the fixups. Just two small comments.
Quoted 6 lines · Derrick Stolee via GitGitGadget
When in cone mode, "git sparse-checkout set" takes a list of folders and constructs an ordered list of patterns for the sparse-checkout file. The "git sparse-checkout list" subcommand outputs the contents of the sparse-checkout file in a very basic way.
Quoted 7 lines
This patch changes the behavior of "git sparse-checkout list" when core.sparseCheckoutCone=true. It will output the folders that were used in "git sparse-checkout set" to create the patterns, instead of the patterns themselves.
I believe this was requested in the initial review, but I cannot find that message now.
This sentence isn't still true, is it?
Quoted 72 lines
I was going to include this as part of a longer follow-up series, but I think this may be worth considering for the 2.25.0 release. Hence, it is included by itself.
Update in V2:
* Fixed typos/word choice in commit message.
* Added a second commit including clarification on interactions with submodules.
Thanks, -Stolee
Derrick Stolee (2):
sparse-checkout: list directories in cone mode
sparse-checkout: document interactions with submodulesDocumentation/git-sparse-checkout.txt | 21 ++++++++++++++- builtin/sparse-checkout.c | 21 +++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 39 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)base-commit:
761e3d26bbe44c51f83c4f1ad198461f57029ebd
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-500%2Fderrickstolee%2Fsparse-checkout-list-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-500/derrickstolee/sparse-checkout-list-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/500Range-diff vs v2:
1:
d6f4f40486! 1:7d4295bd06sparse-checkout: list folders in cone mode
@@ -1,17 +1,17 @@
Author: Derrick Stolee <[email protected]>- sparse-checkout: list folders in cone mode
+ sparse-checkout: list directories in cone modeWhen core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'
- command takes a list of folders as input, then creates an ordered
- list of sparse-checkout patterns such that those folders are
- recursively included and all sibling entries along the parent folders
+ command takes a list of directories as input, then creates an ordered
+ list of sparse-checkout patterns such that those directories are
+ recursively included and all sibling entries along the parent directories
are also included. Listing the patterns is less user-friendly than the
- folders themselves.
+ directories themselves.In cone mode, and as long as the patterns match the expected cone-mode pattern types, change the output of 'git sparse-checkout list' to only
- show the folders that created the patterns.
+ show the directories that created the patterns.With this change, the following piped commands would not change the working directory:
@@ -41,8 +41,8 @@
based algorithms to compute inclusion in the sparse-checkout.+In the cone mode case, the
git sparse-checkout listsubcommand will list the
-+folders that define the recursive patterns. For the example sparse-checkout file -+above, the output is as follows:
++directories that define the recursive patterns. For the example sparse-checkout ++file above, the output is as follows:
+
+--------------------------
+$ git sparse-checkout list
2:331bb7d6fb! 2:74bbd0f84dsparse-checkout: document interactions with submodules
@@ -2,11 +2,6 @@
Quoted 7 lines
sparse-checkout: document interactions with submodules
- Junio asked what the behavior is between the sparse-checkout feature
- and the submodule feature. The sparse-checkout builtin has not changed
- the way these features interact, but we may as well document it in
- the builtin docs.
-
I actually liked the second sentence of this paragraph and thought it provided useful information for future readers; I only thought the first sentence should be removed.
Quoted 23 lines
Using 'git submodule (init|deinit)' a user can select a subset of submodules to populate. This behaves very similar to the sparse-checkout feature, but those directories contain their own .git directory
@@ -61,14 +56,14 @@
+ git sparse-checkout set folder1
+ ) &&
+list_filessuper >dir &&
-+ cat >expect <<-EOF&&
++ cat >expect <<-\EOF &&
+ a
+ folder1
+ modules
+ EOF
+test_cmpexpect dir &&
+list_filessuper/modules/child >dir &&
-+ cat >expect <<-EOF&&
++ cat >expect <<-\EOF &&
+ a
+ deep
+ folder1--
gitgitgadget
Quoted 6 lines · Derrick Stolee via GitGitGadget
When in cone mode, "git sparse-checkout set" takes a list of folders and constructs an ordered list of patterns for the sparse-checkout file. The "git sparse-checkout list" subcommand outputs the contents of the sparse-checkout file in a very basic way.
Quoted 7 lines
This patch changes the behavior of "git sparse-checkout list" when core.sparseCheckoutCone=true. It will output the folders that were used in "git sparse-checkout set" to create the patterns, instead of the patterns themselves.
I believe this was requested in the initial review, but I cannot find that message now.
Yeah, I think I mentioned it, but couldn't remember for sure. Just did a little digging and found
https://lore.kernel.org/git/CABPp-BH13XbNR3MQKE7cHO5e=pMY7kLtGhkX1SQg_o9it=uUug@mail.gmail.com/:
"Should the list mode in cone mode be modified to just show the directories the user added? It seems a little weird to show the internal details of the implementation (all the parent directories and negated entries and whatnot). That's also not in a form that users can pass along to future sparse-checkout add invocations."
Though I then went into other tangents, which may have been what caused it to be forgotten or overlooked.
Quoted 3 lines
I was going to include this as part of a longer follow-up series, but I think this may be worth considering for the 2.25.0 release. Hence, it is included by itself.
Yeah, I think this is a good and small fixup to a new feature in 2.25.0, so it'd be nice if it could be included. Not sure if it's too late given that we're at -rc0, but here's a thumbs up from me if it makes any difference.