From: Taylor Blau <me@ttaylorr.com>
To: Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, me@ttaylorr.com,
calbabreaker@gmail.com, Derrick Stolee <derrickstolee@github.com>,
Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH 3/3] sparse-checkout: refuse to add to bad patterns
Date: Mon, 20 Sep 2021 14:59:28 -0400 [thread overview]
Message-ID: <YUjaEGtts6R6b/wK@nand.local> (raw)
In-Reply-To: <d513b28b75189d066f9c66de44a1a578cbc38139.1632160658.git.gitgitgadget@gmail.com>
On Mon, Sep 20, 2021 at 05:57:38PM +0000, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <dstolee@microsoft.com>
>
> When in cone mode sparse-checkout, it is unclear how 'git
> sparse-checkout add <dir1> ...' should behave if the existing
> sparse-checkout file does not match the cone mode patterns. Change the
> behavior to fail with an error message about the existing patterns.
>
> Also, all cone mode patterns start with a '/' character, so add that
> restriction. This is necessary for our example test 'cone mode: warn on
> bad pattern', but also requires modifying the example sparse-checkout
> file we use to test the warnings related to recognizing cone mode
> patterns.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
> builtin/sparse-checkout.c | 3 +++
> dir.c | 2 +-
> t/t1091-sparse-checkout-builtin.sh | 11 +++++++----
> 3 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index fe76c3eedda..2492ae828a9 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -513,6 +513,9 @@ static void add_patterns_cone_mode(int argc, const char **argv,
> die(_("unable to load existing sparse-checkout patterns"));
> free(sparse_filename);
>
> + if (!existing.use_cone_patterns)
> + die(_("existing sparse-checkout patterns do not use cone mode"));
> +
Makes sense.
> hashmap_for_each_entry(&existing.recursive_hashmap, &iter, pe, ent) {
> if (!hashmap_contains_parent(&pl->recursive_hashmap,
> pe->pattern, &buffer) ||
> diff --git a/dir.c b/dir.c
> index 03c4d212672..93136442103 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -727,7 +727,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
> }
>
> if (given->patternlen < 2 ||
> - *given->pattern == '*' ||
> + *given->pattern != '/' ||
Makes sense that we require cone-mode patterns to start with '/', which
necessarily means we want to drop the other arm `*given->pattern == '*'`.
> strstr(given->pattern, "**")) {
> /* Not a cone pattern. */
> warning(_("unrecognized pattern: '%s'"), given->pattern);
> diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
> index af0acd32bd9..780c6a1aaae 100755
> --- a/t/t1091-sparse-checkout-builtin.sh
> +++ b/t/t1091-sparse-checkout-builtin.sh
> @@ -108,14 +108,17 @@ 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 &&
> +
> + test_must_fail git -C bad-patterns sparse-checkout add dir 2>err &&
> + grep "existing sparse-checkout patterns do not use cone mode" err &&
>
> git -C bad-patterns sparse-checkout init --cone &&
> cat >expect <<-\EOF &&
> /*
> !/*/
> EOF
> - test_cmp expect bad-patterns/.git/info/sparse-checkout
> + test_cmp expect bad-patterns/.git/info/sparse-checkout &&
> + git -C bad-patterns sparse-checkout add dir
Good thinking to make sure that we can add `dir` after clearing. But
let's check the contents of the sparse-checkout file to make sure that
it was added in cone mode.
> '
>
> test_expect_success 'interaction with clone --no-checkout (unborn index)' '
> @@ -182,9 +185,9 @@ test_expect_success 'set sparse-checkout using --stdin' '
> test_expect_success 'add to sparse-checkout' '
> cat repo/.git/info/sparse-checkout >expect &&
> cat >add <<-\EOF &&
> - pattern1
> + /pattern1
> /folder1/
> - pattern2
> + /pattern2
> EOF
> cat add >>expect &&
> git -C repo sparse-checkout add --stdin <add &&
Hmm. Does this new restriction apply to patterns given over the
command-line? (It looks like we handle the two slightly differently, so
I wonder if we are expecting users to write "git sparse-checkout add
/foo" instead of "... add foo" as a consequence).
Thanks,
Taylor
next prev parent reply other threads:[~2021-09-21 2:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-20 17:57 [PATCH 0/3] Sparse checkout: fix mixed-mode pattern issues Derrick Stolee via GitGitGadget
2021-09-20 17:57 ` [PATCH 1/3] sparse-checkout: fix OOM error with mixed patterns Derrick Stolee via GitGitGadget
2021-09-20 18:24 ` Taylor Blau
2021-09-21 13:06 ` Derrick Stolee
2021-09-21 16:35 ` Taylor Blau
2021-09-20 17:57 ` [PATCH 2/3] sparse-checkout: clear patterns when switching modes Derrick Stolee via GitGitGadget
2021-09-20 18:52 ` Taylor Blau
2021-09-20 18:54 ` Taylor Blau
2021-09-20 17:57 ` [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Derrick Stolee via GitGitGadget
2021-09-20 18:59 ` Taylor Blau [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-12-07 20:02 [PATCH 0/3] sparse-checkout: fix segfault on malformed patterns Derrick Stolee via GitGitGadget
2021-12-07 20:02 ` [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Derrick Stolee via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YUjaEGtts6R6b/wK@nand.local \
--to=me@ttaylorr.com \
--cc=calbabreaker@gmail.com \
--cc=derrickstolee@github.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).