git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] sparse-checkout: list directories in cone mode
@ 2019-12-26 20:49 Derrick Stolee via GitGitGadget
  2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-26 20:49 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano

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
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/1] sparse-checkout: list folders in cone mode
  2019-12-26 20:49 [PATCH 0/1] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
@ 2019-12-26 20:49 ` Derrick Stolee via GitGitGadget
  2019-12-26 21:17   ` Junio C Hamano
  2019-12-27 15:52   ` Elijah Newren
  2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
  2019-12-27 21:47 ` [PATCH 0/1] " Elijah Newren
  2 siblings, 2 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-26 20:49 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano,
	Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

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.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 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(-)

diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 9c3c66cc37..dcca9ee826 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -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
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 5d62f7a66d..b3bed891cb 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -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);
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 6f7e2d0c9e..37f6d8fa90 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -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 &&
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
  2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
@ 2019-12-26 21:17   ` Junio C Hamano
  2019-12-27 14:05     ` Derrick Stolee
  2019-12-27 15:52   ` Elijah Newren
  1 sibling, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2019-12-26 21:17 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: git, szeder.dev, newren, jon, Derrick Stolee

"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Derrick Stolee <dstolee@microsoft.com>

> Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
s/folder/directory/ everywhere as the rest of Git.

> When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set'
> command taks a list of folders as input, then creates an ordered

"takes"

> 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?

> 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.
> ...
> +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.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
  2019-12-26 21:17   ` Junio C Hamano
@ 2019-12-27 14:05     ` Derrick Stolee
  0 siblings, 0 replies; 18+ messages in thread
From: Derrick Stolee @ 2019-12-27 14:05 UTC (permalink / raw)
  To: Junio C Hamano, Derrick Stolee via GitGitGadget
  Cc: git, szeder.dev, newren, jon, Derrick Stolee

On 12/26/2019 4:17 PM, Junio C Hamano wrote:
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Derrick Stolee <dstolee@microsoft.com>
> 
>> Subject: Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
> s/folder/directory/ everywhere as the rest of Git.
> 
>> 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.

>> 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"?

> 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.

>> 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.
>> ...
>> +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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/1] sparse-checkout: list folders in cone mode
  2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
  2019-12-26 21:17   ` Junio C Hamano
@ 2019-12-27 15:52   ` Elijah Newren
  1 sibling, 0 replies; 18+ messages in thread
From: Elijah Newren @ 2019-12-27 15:52 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git Mailing List, SZEDER Gábor, jon, Derrick Stolee,
	Junio C Hamano

On Thu, Dec 26, 2019 at 12:49 PM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Derrick Stolee <dstolee@microsoft.com>
>
> 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.  :-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 0/2] sparse-checkout: list directories in cone mode
  2019-12-26 20:49 [PATCH 0/1] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
@ 2019-12-27 18:47 ` Derrick Stolee via GitGitGadget
  2019-12-27 18:47   ` [PATCH v2 1/2] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
                     ` (2 more replies)
  2019-12-27 21:47 ` [PATCH 0/1] " Elijah Newren
  2 siblings, 3 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-27 18:47 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano

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.

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

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/2] sparse-checkout: list folders in cone mode
  2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
@ 2019-12-27 18:47   ` Derrick Stolee via GitGitGadget
  2019-12-27 21:37     ` Elijah Newren
  2019-12-27 18:47   ` [PATCH v2 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
  2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2 siblings, 1 reply; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-27 18:47 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano,
	Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

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.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 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(-)

diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 9c3c66cc37..dcca9ee826 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -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
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 5d62f7a66d..b3bed891cb 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -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);
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 6f7e2d0c9e..37f6d8fa90 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -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 &&
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/2] sparse-checkout: document interactions with submodules
  2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
  2019-12-27 18:47   ` [PATCH v2 1/2] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
@ 2019-12-27 18:47   ` Derrick Stolee via GitGitGadget
  2019-12-27 20:20     ` Eric Sunshine
  2019-12-27 21:46     ` Elijah Newren
  2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2 siblings, 2 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-27 18:47 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano,
	Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

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.

Reported-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 Documentation/git-sparse-checkout.txt | 10 ++++++++++
 t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index dcca9ee826..2b7aaa0310 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -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
 --------
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 37f6d8fa90..5572beeeca 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -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
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
  2019-12-27 18:47   ` [PATCH v2 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
@ 2019-12-27 20:20     ` Eric Sunshine
  2019-12-30 13:11       ` Derrick Stolee
  2019-12-27 21:46     ` Elijah Newren
  1 sibling, 1 reply; 18+ messages in thread
From: Eric Sunshine @ 2019-12-27 20:20 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git List, SZEDER Gábor, Elijah Newren, Jon Simons,
	Derrick Stolee, Junio C Hamano

On Fri, Dec 27, 2019 at 1:48 PM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> @@ -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
    EOF

But, 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.)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 1/2] sparse-checkout: list folders in cone mode
  2019-12-27 18:47   ` [PATCH v2 1/2] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
@ 2019-12-27 21:37     ` Elijah Newren
  0 siblings, 0 replies; 18+ messages in thread
From: Elijah Newren @ 2019-12-27 21:37 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git Mailing List, SZEDER Gábor, jon, Derrick Stolee,
	Junio C Hamano

On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Derrick Stolee <dstolee@microsoft.com>
>
> 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/

> list of sparse-checkout patterns such that those folders are
s/folders/directories/

> recursively included and all sibling entries along the parent folders
again here.

> are also included. Listing the patterns is less user-friendly than the
> folders themselves.
and here.

>
> 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.

>
> 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.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  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(-)
>
> diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
> index 9c3c66cc37..dcca9ee826 100644
> --- a/Documentation/git-sparse-checkout.txt
> +++ b/Documentation/git-sparse-checkout.txt
> @@ -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
and here.

> +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
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index 5d62f7a66d..b3bed891cb 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -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);
>
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index 6f7e2d0c9e..37f6d8fa90 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -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' '
There's another one here but that's just the context area, so it'd be
a separate patch in a separate cleanup series...

>         git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
>         test_line_count = 0 err &&
> --

The rest looks good

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
  2019-12-27 18:47   ` [PATCH v2 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
  2019-12-27 20:20     ` Eric Sunshine
@ 2019-12-27 21:46     ` Elijah Newren
  2019-12-27 22:33       ` Junio C Hamano
  1 sibling, 1 reply; 18+ messages in thread
From: Elijah Newren @ 2019-12-27 21:46 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git Mailing List, SZEDER Gábor, jon, Derrick Stolee,
	Junio C Hamano

On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Derrick Stolee <dstolee@microsoft.com>
>
> 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.

> 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 <gitster@pobox.com>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  Documentation/git-sparse-checkout.txt | 10 ++++++++++
>  t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+)
>
> diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
> index dcca9ee826..2b7aaa0310 100644
> --- a/Documentation/git-sparse-checkout.txt
> +++ b/Documentation/git-sparse-checkout.txt
> @@ -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
>  --------
>
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index 37f6d8fa90..5572beeeca 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -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
> --

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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/1] sparse-checkout: list directories in cone mode
  2019-12-26 20:49 [PATCH 0/1] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
  2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
@ 2019-12-27 21:47 ` Elijah Newren
  2 siblings, 0 replies; 18+ messages in thread
From: Elijah Newren @ 2019-12-27 21:47 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git Mailing List, SZEDER Gábor, jon, Derrick Stolee,
	Junio C Hamano

On Thu, Dec 26, 2019 at 12:49 PM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> 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.

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.

> 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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
  2019-12-27 21:46     ` Elijah Newren
@ 2019-12-27 22:33       ` Junio C Hamano
  0 siblings, 0 replies; 18+ messages in thread
From: Junio C Hamano @ 2019-12-27 22:33 UTC (permalink / raw)
  To: Elijah Newren
  Cc: Derrick Stolee via GitGitGadget, Git Mailing List,
	SZEDER Gábor, jon, Derrick Stolee

Elijah Newren <newren@gmail.com> writes:

> On Fri, Dec 27, 2019 at 10:47 AM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> 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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] sparse-checkout: document interactions with submodules
  2019-12-27 20:20     ` Eric Sunshine
@ 2019-12-30 13:11       ` Derrick Stolee
  0 siblings, 0 replies; 18+ messages in thread
From: Derrick Stolee @ 2019-12-30 13:11 UTC (permalink / raw)
  To: Eric Sunshine, Derrick Stolee via GitGitGadget
  Cc: Git List, SZEDER Gábor, Elijah Newren, Jon Simons,
	Derrick Stolee, Junio C Hamano

On 12/27/2019 3:20 PM, Eric Sunshine wrote:
> On Fri, Dec 27, 2019 at 1:48 PM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
>> @@ -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:

Thanks for pointing out the difference, except...
 
>     cat >expect <<\-EOF &&

This should be <<-\EOF

>     a
>     folder1
>     modules
>     EOF
> 
> But, 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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/2] sparse-checkout: list directories in cone mode
  2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
  2019-12-27 18:47   ` [PATCH v2 1/2] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
  2019-12-27 18:47   ` [PATCH v2 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
@ 2019-12-30 15:33   ` Derrick Stolee via GitGitGadget
  2019-12-30 15:33     ` [PATCH v3 1/2] " Derrick Stolee via GitGitGadget
                       ` (2 more replies)
  2 siblings, 3 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-30 15:33 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano

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.

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 <dstolee@microsoft.com>
      
     -    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
      +		folder1

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/2] sparse-checkout: list directories in cone mode
  2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
@ 2019-12-30 15:33     ` Derrick Stolee via GitGitGadget
  2019-12-30 15:33     ` [PATCH v3 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
  2019-12-30 17:18     ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Elijah Newren
  2 siblings, 0 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-30 15:33 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano,
	Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

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.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 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(-)

diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 9c3c66cc37..67be5247b9 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -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
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 5d62f7a66d..b3bed891cb 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -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);
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 6f7e2d0c9e..37f6d8fa90 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -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 &&
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 2/2] sparse-checkout: document interactions with submodules
  2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2019-12-30 15:33     ` [PATCH v3 1/2] " Derrick Stolee via GitGitGadget
@ 2019-12-30 15:33     ` Derrick Stolee via GitGitGadget
  2019-12-30 17:18     ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Elijah Newren
  2 siblings, 0 replies; 18+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2019-12-30 15:33 UTC (permalink / raw)
  To: git; +Cc: szeder.dev, newren, jon, Derrick Stolee, Junio C Hamano,
	Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

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 <gitster@pobox.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 Documentation/git-sparse-checkout.txt | 10 ++++++++++
 t/t1091-sparse-checkout-builtin.sh    | 28 +++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 67be5247b9..3b341cf0fc 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -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
 --------
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index 37f6d8fa90..ff7f8f7a1f 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -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
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/2] sparse-checkout: list directories in cone mode
  2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
  2019-12-30 15:33     ` [PATCH v3 1/2] " Derrick Stolee via GitGitGadget
  2019-12-30 15:33     ` [PATCH v3 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
@ 2019-12-30 17:18     ` Elijah Newren
  2 siblings, 0 replies; 18+ messages in thread
From: Elijah Newren @ 2019-12-30 17:18 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget
  Cc: Git Mailing List, SZEDER Gábor, jon, Derrick Stolee,
	Junio C Hamano

Hi,

Thanks for the fixups.  Just two small comments.

On Mon, Dec 30, 2019 at 7:33 AM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> 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.

This sentence isn't still true, is it?

> 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 <dstolee@microsoft.com>
>
>      -    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.
>      -

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.

>           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
>       +         folder1
>
> --
> gitgitgadget

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2019-12-30 17:18 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-26 20:49 [PATCH 0/1] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
2019-12-26 20:49 ` [PATCH 1/1] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
2019-12-26 21:17   ` Junio C Hamano
2019-12-27 14:05     ` Derrick Stolee
2019-12-27 15:52   ` Elijah Newren
2019-12-27 18:47 ` [PATCH v2 0/2] sparse-checkout: list directories " Derrick Stolee via GitGitGadget
2019-12-27 18:47   ` [PATCH v2 1/2] sparse-checkout: list folders " Derrick Stolee via GitGitGadget
2019-12-27 21:37     ` Elijah Newren
2019-12-27 18:47   ` [PATCH v2 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
2019-12-27 20:20     ` Eric Sunshine
2019-12-30 13:11       ` Derrick Stolee
2019-12-27 21:46     ` Elijah Newren
2019-12-27 22:33       ` Junio C Hamano
2019-12-30 15:33   ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Derrick Stolee via GitGitGadget
2019-12-30 15:33     ` [PATCH v3 1/2] " Derrick Stolee via GitGitGadget
2019-12-30 15:33     ` [PATCH v3 2/2] sparse-checkout: document interactions with submodules Derrick Stolee via GitGitGadget
2019-12-30 17:18     ` [PATCH v3 0/2] sparse-checkout: list directories in cone mode Elijah Newren
2019-12-27 21:47 ` [PATCH 0/1] " Elijah Newren

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).