From: Victoria Dye <vdye@github.com>
To: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>, git@vger.kernel.org
Cc: derrickstolee@github.com
Subject: Re: [PATCH v2 3/4] rm: expand the index only when necessary
Date: Tue, 9 Aug 2022 17:24:30 -0700 [thread overview]
Message-ID: <2c0cb658-cd5a-420a-d313-6839149b9b40@github.com> (raw)
In-Reply-To: <20220807041335.1790658-4-shaoxuan.yuan02@gmail.com>
Shaoxuan Yuan wrote:
> Remove the `ensure_full_index()` method so `git-rm` does not always
> expand the index when the expansion is unnecessary, i.e. when
> <pathspec> does not have any possibilities to match anything outside
> of sparse-checkout definition.
>
> Expand the index when the <pathspec> needs an expanded index, i.e. the
> <pathspec> contains wildcard that may need a full-index or the
> <pathspec> is simply outside of sparse-checkout definition.
>
> Notice that the test 'rm pathspec expands index when necessary' in
> t1092 *is* testing this code change behavior, though it will be marked
> as 'test_expect_success' only in the next patch, where we officially
> mark `command_requires_full_index = 0`, so the index does not expand
> unless we tell it to do so.
>
> Notice that because we also want `ensure_full_index` to record the
> stdout and stderr from Git command, a corresponding modification
> is also included in this patch. The reason we want the "sparse-index-out"
> and "sparse-index-err", is that we need to make sure there is no error
> from Git command itself, so we can rely on the `test_region` result
> and determine if the index is expanded or not.
I think this patch might make more sense _after_ patch 4. Without the
changes in patch 4, modifying how a sparse index is handled here doesn't
immediately change any functionality. Then, patch 4 effectively makes its
own changes (enable the sparse index) + "turns on" the changes from this
series, all at once.
I usually recommend trying to make the effects of a patch testable in that
patch (as long as it doesn't make a series more complicated/confusing). In
this case, it looks like you could swap the order of the commits and only
need to adjust the 'test_expect_success'/'test_expect_failure' settings on
the tests, making it a good candidate for this kind of reordering.
All that said, I don't think changing this is worth a re-roll on its own -
it's moreso intended as "things to consider for future series". :)
>
> Helped-by: Victoria Dye <vdye@github.com>
> Helped-by: Derrick Stolee <derrickstolee@github.com>
> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
> ---
> builtin/rm.c | 5 +++--
> t/t1092-sparse-checkout-compatibility.sh | 27 ++++++++++++++++++++++--
> 2 files changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/rm.c b/builtin/rm.c
> index 84a935a16e..58ed924f0d 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -296,8 +296,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>
> seen = xcalloc(pathspec.nr, 1);
>
> - /* TODO: audit for interaction with sparse-index. */
> - ensure_full_index(&the_index);
> + if (pathspec_needs_expanded_index(&the_index, &pathspec))
> + ensure_full_index(&the_index);
> +
> for (i = 0; i < active_nr; i++) {
> const struct cache_entry *ce = active_cache[i];
>
> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
> index c9300b77dd..94464cf911 100755
> --- a/t/t1092-sparse-checkout-compatibility.sh
> +++ b/t/t1092-sparse-checkout-compatibility.sh
> @@ -1340,10 +1340,14 @@ ensure_not_expanded () {
> shift &&
> test_must_fail env \
> GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
> - git -C sparse-index "$@" || return 1
> + git -C sparse-index "$@" \
> + >sparse-index-out \
> + 2>sparse-index-error || return 1
> else
> GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
> - git -C sparse-index "$@" || return 1
> + git -C sparse-index "$@" \
> + >sparse-index-out \
> + 2>sparse-index-error || return 1
> fi &&
> test_region ! index ensure_full_index trace2.txt
> }
> @@ -1910,4 +1914,23 @@ test_expect_failure 'rm pathspec outside sparse definition' '
> test_sparse_match git status --porcelain=v2
> '
>
> +test_expect_failure 'rm pathspec expands index when necessary' '
> + init_repos &&
> +
> + # in-cone pathspec (do not expand)
> + ensure_not_expanded rm "deep/deep*" &&
> + test_must_be_empty sparse-index-err &&
> +
> + # out-of-cone pathspec (expand)
> + ! ensure_not_expanded rm --sparse "folder1/a*" &&
> + test_must_be_empty sparse-index-err &&
> +
> + # pathspec that should expand index
> + ! ensure_not_expanded rm "*/a" &&
> + test_must_be_empty sparse-index-err &&
> +
> + ! ensure_not_expanded rm "**a" &&
> + test_must_be_empty sparse-index-err
> +'
> +
> test_done
next prev parent reply other threads:[~2022-08-10 0:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 4:51 [PATCH v1 0/4] rm: integrate with sparse-index Shaoxuan Yuan
2022-08-03 4:51 ` [PATCH v1 1/4] t1092: add tests for `git-rm` Shaoxuan Yuan
2022-08-03 14:32 ` Derrick Stolee
2022-08-03 4:51 ` [PATCH v1 2/4] pathspec.h: move pathspec_needs_expanded_index() from reset.c to here Shaoxuan Yuan
2022-08-03 14:35 ` Derrick Stolee
2022-08-05 7:53 ` Shaoxuan Yuan
2022-08-03 4:51 ` [PATCH v1 3/4] rm: expand the index only when necessary Shaoxuan Yuan
2022-08-03 14:40 ` Derrick Stolee
2022-08-05 8:07 ` Shaoxuan Yuan
2022-08-03 4:51 ` [PATCH v1 4/4] rm: integrate with sparse-index Shaoxuan Yuan
2022-08-04 14:48 ` Derrick Stolee
2022-08-06 3:18 ` Shaoxuan Yuan
2022-08-07 4:13 ` [PATCH v2 0/4] " Shaoxuan Yuan
2022-08-07 4:13 ` [PATCH v2 1/4] t1092: add tests for `git-rm` Shaoxuan Yuan
2022-08-10 12:47 ` Derrick Stolee
2022-08-07 4:13 ` [PATCH v2 2/4] pathspec.h: move pathspec_needs_expanded_index() from reset.c to here Shaoxuan Yuan
2022-08-07 4:13 ` [PATCH v2 3/4] rm: expand the index only when necessary Shaoxuan Yuan
2022-08-10 0:24 ` Victoria Dye [this message]
2022-08-07 4:13 ` [PATCH v2 4/4] rm: integrate with sparse-index Shaoxuan Yuan
2022-08-08 17:24 ` [PATCH v2 0/4] " Junio C Hamano
2022-08-08 17:51 ` Victoria Dye
2022-08-08 19:01 ` Junio C Hamano
2022-08-10 0:27 ` Victoria Dye
2022-08-10 0:31 ` Shaoxuan Yuan
2022-08-12 18:36 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c0cb658-cd5a-420a-d313-6839149b9b40@github.com \
--to=vdye@github.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=shaoxuan.yuan02@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.