From: Junio C Hamano <gitster@pobox.com>
To: "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Brandon Williams" <bmwill@google.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Matheus Tavares Bernardino" <matheus.bernardino@usp.br>,
"Philippe Blain" <levraiphilippeblain@gmail.com>
Subject: Re: [PATCH v2] grep: ignore --recurse-submodules if --no-index is given
Date: Thu, 30 Jan 2020 10:14:39 -0800 [thread overview]
Message-ID: <xmqq36bwerqo.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <pull.540.v2.git.1580391448318.gitgitgadget@gmail.com> (Philippe Blain via GitGitGadget's message of "Thu, 30 Jan 2020 13:37:28 +0000")
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> Using `--recurse-submodules` should not have any effect if `--no-index`
> is used inside a repository, as Git will recurse into the checked out
> submodule directories just like into regular directories.
> ...
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 50ce8d9461..ae2d5bbafc 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -958,6 +958,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
> /* die the same way as if we did it at the beginning */
> setup_git_directory();
> }
> + /* Ignore --recurse-submodules if --no-index is given or implied */
> + if (!use_index)
> + recurse_submodules = 0;
This is done quite early in the execution flow. That makes any and
all existing checks that says "if recurse-submodules is set and we
are in no-index mode, do this" unneeded.
>
> /*
> * skip a -- separator; we know it cannot be
> @@ -1115,8 +1118,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
> }
> }
>
> - if (recurse_submodules && (!use_index || untracked))
> - die(_("option not supported with --recurse-submodules"));
> + if (recurse_submodules && untracked)
> + die(_("--untracked not supported with --recurse-submodules"));
And this is an example of a change to remove a check for such a
redundant condition. If recurse_submodules is true (which is the
only time the RHS of &&- is evaluated), we know use_index cannot be
false, so the final outcome solely depends on the value of untracked.
Looks good. And my quick reading of the current builtin/grep.c code
suggests that this is the only such combination that can be simplified.
Thanks.
> if (!show_in_pager && !opt.status_only)
> setup_pager();
> diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
> index 946f91fa57..828cb3ba58 100755
> --- a/t/t7814-grep-recurse-submodules.sh
> +++ b/t/t7814-grep-recurse-submodules.sh
> @@ -345,7 +345,16 @@ test_incompatible_with_recurse_submodules ()
> }
>
> test_incompatible_with_recurse_submodules --untracked
> -test_incompatible_with_recurse_submodules --no-index
> +
> +test_expect_success 'grep --recurse-submodules --no-index ignores --recurse-submodules' '
> + git grep --recurse-submodules --no-index -e "^(.|.)[\d]" >actual &&
> + cat >expect <<-\EOF &&
> + a:(1|2)d(3|4)
> + submodule/a:(1|2)d(3|4)
> + submodule/sub/a:(1|2)d(3|4)
> + EOF
> + test_cmp expect actual
> +'
>
> test_expect_success 'grep --recurse-submodules should pass the pattern type along' '
> # Fixed
>
> base-commit: bc7a3d4dc04dd719e7c8c35ebd7a6e6651c5c5b6
prev parent reply other threads:[~2020-01-30 18:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-26 0:58 [PATCH] grep: ignore --recurse-submodules if --no-index is given Philippe Blain via GitGitGadget
2020-01-26 9:39 ` Johannes Schindelin
2020-01-30 13:37 ` [PATCH v2] " Philippe Blain via GitGitGadget
2020-01-30 18:14 ` Junio C Hamano [this message]
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=xmqq36bwerqo.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=levraiphilippeblain@gmail.com \
--cc=matheus.bernardino@usp.br \
--cc=szeder.dev@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 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 NNTP newsgroup(s).