Re: [PATCH 4/8] sparse-checkout: cone mode does not recognize "**"
- From
Jeff King <peff@peff.net>
- Date
- Jan 14, 2020, 21:16 UTC
- Message-ID
- <20200114211653.GB3949560@coredump.intra.peff.net>
- In-Reply-To
- <dfa7e204449c8958d35cc01261d2dc8099d7ce0c.1579029963.git.gitgitgadget@gmail.com>
On Tue, Jan 14, 2020 at 07:25:58PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 18 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com> > > When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' > command creates a restricted set of possible patterns that are used > by a custom algorithm to quickly match those patterns. > > If a user manually edits the sparse-checkout file, then they could > create patterns that do not match these expectations. The cone-mode > matching algorithm can return incorrect results. The solution is to > detect these incorrect patterns, warn that we do not recognize them, > and revert to the standard algorithm. > > Check each pattern for the "**" substring, and revert to the old > logic if seen. While technically a "/<dir>/**" pattern matches > the meaning of "/<dir>/", it is not one that would be written by > the sparse-checkout builtin in cone mode. Attempting to accept that > pattern change complicates the logic and instead we punt and do > not accept any instance of "**".
That all makes sense.
Show 14 quoted lines
> diff --git a/dir.c b/dir.c
> index 22d08e61c2..f8e350dda2 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -651,6 +651,13 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
> return;
> }
>
> + if (strstr(given->pattern, "**")) {
> + /* Not a cone pattern. */
> + pl->use_cone_patterns = 0;
> + warning(_("unrecognized pattern: '%s'"), given->pattern);
> + goto clear_hashmaps;
> + }The clear_hashmaps label already unsets pl->use_cone_patterns, so the first line is redundant (the same is true of existing goto jumps, as well, though).
I wondered whether this warning could be triggered accidentally by somebody who just happened to add such a pattern. But we'd exit immediately from add_pattern_to_hashsets() immediately unless the user has set core.sparseCheckoutCone. And if that's set, then warning is definitely the right thing to do.
-Peff