git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] sparse-checkout: clear patterns when switching modes

From
Taylor Blau <me@ttaylorr.com>
Date
Sep 20, 2021, 18:52 UTC
Message-ID
<YUjYZNqvvxVRctJQ@nand.local>
In-Reply-To
<450b90dad57c42e37a4edc52dac88caf98021fc6.1632160658.git.gitgitgadget@gmail.com>
On Mon, Sep 20, 2021 at 05:57:37PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 33 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com>
>
> Previously, when a user runs 'git sparse-checkout init --cone', the
> existing patterns would remain, even if the patterns were not in cone
> mode. This causes confusion as to how the patterns should work when
> later 'git sparse-checkout add' commands append to the pattern list.
>
> In fact, the way these patterns were modified was not even a strict
> appending of patterns, but mutating and reordering patterns because of
> how the paths were interpreted and rewritten.
>
> As a first step, we shall start overwriting the pattern set completely
> when switching to cone mode, unless the existing patterns already match
> cone mode patterns. The 'use_cone_patterns' member is set to false if
> the patterns fail to parse using cone mode restrictions.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  builtin/sparse-checkout.c          | 13 +++++++++++--
>  t/t1091-sparse-checkout-builtin.sh |  9 ++++++++-
>  2 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index b45fd97a98b..fe76c3eedda 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -348,8 +348,17 @@ static int sparse_checkout_init(int argc, const char **argv)
>
>  	/* If we already have a sparse-checkout file, use it. */
>  	if (res >= 0) {
> -		free(sparse_filename);
> -		return update_working_directory(NULL);
> +		if (pl.use_cone_patterns || !init_opts.cone_mode) {

I traced through this code beginning with sparse_checkout_init() and right before the check on pl.use_cone_patterns, and I couldn't find anywhere that this variable is set to a non-zero value. Could you let me know if I'm missing something, or is the left-hand side of this or redundant?

I guess what this check wants to be saying is "if the existing sparse-checkout was in cone mode or we are transitioning to cone mode, then quit now".

Show 10 quoted lines
> +			free(sparse_filename);
> +			return update_working_directory(NULL);
> +		}
> +
> +		/*
> +		 * At this point, note that if res >= 0 but pl.use_cone_patterns
> +		 * is false, then we want to override the patterns with the
> +		 * initial set of cone mode patterns.
> +		 */
> +		clear_pattern_list(&pl);

...or otherwise, we are transitioning into cone mode from a non-cone mode state?

If so, this may be somewhat surprising to users who have their patterns cleared after re-initializing. I guess the command is called "init", but it may be friendlier to have a `--reinitialize` option or similar which indicates the user's preference to obliterate existing patterns if necessary.

See my message at [1] for some more details about a possible suggestion there.

Show 20 quoted lines
>  	}
>
>  	if (get_oid("HEAD", &oid)) {
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index a429d2cc671..af0acd32bd9 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -108,7 +108,14 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' '
>  	git -C bad-patterns sparse-checkout init &&
>  	git -C bad-patterns sparse-checkout add dir &&
>  	git -C bad-patterns config core.sparseCheckoutCone true &&
> -	git -C bad-patterns sparse-checkout add dir
> +	git -C bad-patterns sparse-checkout add dir &&
> +
> +	git -C bad-patterns sparse-checkout init --cone &&
> +	cat >expect <<-\EOF &&
> +	/*
> +	!/*/
> +	EOF
> +	test_cmp expect bad-patterns/.git/info/sparse-checkout

Makes sense that we have to look at the contents of $GIT_DIR/info/sparse-checkout directly here to see the explicit '/*' and '!/*/' patterns.

Thanks, Taylor

[1]: https://lore.kernel.org/git/YUi55%2F3L9nizTVyA@nand.local/
Previous: Derrick Stolee via GitGitGadgetNext: Taylor Blau
Message 7 of 10 in “Sparse checkout: fix mixed-mode pattern issues”
  1. 0/3 Sparse checkout: fix mixed-mode pattern issuesDerrick Stolee via GitGitGadget, Sep 20, 2021
  2. 1/3 sparse-checkout: fix OOM error with mixed patternsDerrick Stolee via GitGitGadget, Sep 20, 2021
  3. Taylor BlauSep 20, 2021
  4. Derrick StoleeSep 21, 2021
  5. Taylor BlauSep 21, 2021
  6. 2/3 sparse-checkout: clear patterns when switching modesDerrick Stolee via GitGitGadget, Sep 20, 2021
  7. Taylor BlauSep 20, 2021
  8. Taylor BlauSep 20, 2021
  9. 3/3 sparse-checkout: refuse to add to bad patternsDerrick Stolee via GitGitGadget, Sep 20, 2021
  10. Taylor BlauSep 20, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.