* [PATCH] grep: ignore --recurse-submodules if --no-index is given
@ 2020-01-26 0:58 Philippe Blain via GitGitGadget
2020-01-26 9:39 ` Johannes Schindelin
2020-01-30 13:37 ` [PATCH v2] " Philippe Blain via GitGitGadget
0 siblings, 2 replies; 4+ messages in thread
From: Philippe Blain via GitGitGadget @ 2020-01-26 0:58 UTC (permalink / raw)
To: git; +Cc: Brandon Williams, Philippe Blain, Philippe Blain
From: Philippe Blain <levraiphilippeblain@gmail.com>
Since grep learned to recurse into submodules in 0281e487fd
(grep: optionally recurse into submodules, 2016-12-16),
using --recurse-submodules along with --no-index makes Git
die().
This is unfortunate because if submodule.recurse is set in a user's
~/.gitconfig, invoking `git grep --no-index` either inside or outside
a Git repository results in
fatal: option not supported with --recurse-submodules
Let's allow using these options together, so that setting submodule.recurse
globally does not prevent using `git grep --no-index`.
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.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
grep: ignore --recurse-submodules if --no-index is given
Since grep learned to recurse into submodules in 0281e487fd (grep:
optionally recurse into submodules, 2016-12-16), using
--recurse-submodules along with --no-index makes Git die().
This is unfortunate because if submodule.recurse is set in a user's
~/.gitconfig, invoking git grep --no-index either inside or outside a
Git repository results in
fatal: option not supported with --recurse-submodules
Let's allow using these options together, so that setting
submodule.recurse globally does not prevent using git grep --no-index.
Using --recurse-submodules should not have any effect if --no-indexis
used inside a repository, as Git will recurse into the checked out
submodule directories just like into regular directories.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-540%2Fphil-blain%2Fgrep-no-index-ignore-recurse-submodule-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-540/phil-blain/grep-no-index-ignore-recurse-submodule-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/540
Documentation/git-grep.txt | 3 ++-
builtin/grep.c | 4 ++--
t/t7814-grep-recurse-submodules.sh | 11 ++++++++++-
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index c89fb569e3..ffc3a6efdc 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -96,7 +96,8 @@ OPTIONS
Recursively search in each submodule that has been initialized and
checked out in the repository. When used in combination with the
<tree> option the prefix of all submodule output will be the name of
- the parent project's <tree> object.
+ the parent project's <tree> object. This option has no effect
+ if `--no-index` is given.
-a::
--text::
diff --git a/builtin/grep.c b/builtin/grep.c
index 50ce8d9461..d5f089dd41 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1115,8 +1115,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"));
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
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] grep: ignore --recurse-submodules if --no-index is given
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
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2020-01-26 9:39 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget
Cc: git, Brandon Williams, Philippe Blain, Philippe Blain
Hi Philippe,
On Sun, 26 Jan 2020, Philippe Blain via GitGitGadget wrote:
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> Since grep learned to recurse into submodules in 0281e487fd
> (grep: optionally recurse into submodules, 2016-12-16),
> using --recurse-submodules along with --no-index makes Git
> die().
>
> This is unfortunate because if submodule.recurse is set in a user's
> ~/.gitconfig, invoking `git grep --no-index` either inside or outside
> a Git repository results in
>
> fatal: option not supported with --recurse-submodules
>
> Let's allow using these options together, so that setting submodule.recurse
> globally does not prevent using `git grep --no-index`.
>
> 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.
>
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
My initial reaction to this patch was: "but why would you try to combine
`--recurse-submodules` with `--no-index`?". The `submodule.recurse`
reference made me think again, though.
And then it hit me: by `--no-index`, what we _really_ mean to say is:
ignore that this _might_ be tracked in Git. And that obviously means that
there cannot be any submodules to recurse into, as far as `git diff
--no-index` is concerned.
So I think your patch makes a ton of sense.
Thanks,
Dscho
> ---
> grep: ignore --recurse-submodules if --no-index is given
>
> Since grep learned to recurse into submodules in 0281e487fd (grep:
> optionally recurse into submodules, 2016-12-16), using
> --recurse-submodules along with --no-index makes Git die().
>
> This is unfortunate because if submodule.recurse is set in a user's
> ~/.gitconfig, invoking git grep --no-index either inside or outside a
> Git repository results in
>
> fatal: option not supported with --recurse-submodules
>
> Let's allow using these options together, so that setting
> submodule.recurse globally does not prevent using git grep --no-index.
>
> Using --recurse-submodules should not have any effect if --no-indexis
> used inside a repository, as Git will recurse into the checked out
> submodule directories just like into regular directories.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-540%2Fphil-blain%2Fgrep-no-index-ignore-recurse-submodule-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-540/phil-blain/grep-no-index-ignore-recurse-submodule-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/540
>
> Documentation/git-grep.txt | 3 ++-
> builtin/grep.c | 4 ++--
> t/t7814-grep-recurse-submodules.sh | 11 ++++++++++-
> 3 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
> index c89fb569e3..ffc3a6efdc 100644
> --- a/Documentation/git-grep.txt
> +++ b/Documentation/git-grep.txt
> @@ -96,7 +96,8 @@ OPTIONS
> Recursively search in each submodule that has been initialized and
> checked out in the repository. When used in combination with the
> <tree> option the prefix of all submodule output will be the name of
> - the parent project's <tree> object.
> + the parent project's <tree> object. This option has no effect
> + if `--no-index` is given.
>
> -a::
> --text::
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 50ce8d9461..d5f089dd41 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -1115,8 +1115,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"));
>
> 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
> --
> gitgitgadget
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] grep: ignore --recurse-submodules if --no-index is given
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 ` Philippe Blain via GitGitGadget
2020-01-30 18:14 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Blain via GitGitGadget @ 2020-01-30 13:37 UTC (permalink / raw)
To: git
Cc: Brandon Williams, SZEDER Gábor, Junio C Hamano,
Matheus Tavares Bernardino, Philippe Blain, Philippe Blain
From: Philippe Blain <levraiphilippeblain@gmail.com>
Since grep learned to recurse into submodules in 0281e487fd
(grep: optionally recurse into submodules, 2016-12-16),
using --recurse-submodules along with --no-index makes Git
die().
This is unfortunate because if submodule.recurse is set in a user's
~/.gitconfig, invoking `git grep --no-index` either inside or outside
a Git repository results in
fatal: option not supported with --recurse-submodules
Let's allow using these options together, so that setting submodule.recurse
globally does not prevent using `git grep --no-index`.
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.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
grep: ignore --recurse-submodules if --no-index is given
Changes since v1:
* set recurse_submodules to 0 early in cmd_grep if !use_index. This
makes more sense, and eliminates an incompatibility with topic
mt/threaded-grep-in-object-store.
v1: Since grep learned to recurse into submodules in 0281e487fd (grep:
optionally recurse into submodules, 2016-12-16), using
--recurse-submodules along with --no-index makes Git die().
This is unfortunate because if submodule.recurse is set in a user's
~/.gitconfig, invoking git grep --no-index either inside or outside a
Git repository results in
fatal: option not supported with --recurse-submodules
Let's allow using these options together, so that setting
submodule.recurse globally does not prevent using git grep --no-index.
Using --recurse-submodules should not have any effect if --no-indexis
used inside a repository, as Git will recurse into the checked out
submodule directories just like into regular directories.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-540%2Fphil-blain%2Fgrep-no-index-ignore-recurse-submodule-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-540/phil-blain/grep-no-index-ignore-recurse-submodule-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/540
Range-diff vs v1:
1: 6634266b01 ! 1: 6fc8bf788a grep: ignore --recurse-submodules if --no-index is given
@@ -20,6 +20,7 @@
is used inside a repository, as Git will recurse into the checked out
submodule directories just like into regular directories.
+ Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
@@ -39,6 +40,16 @@
diff --git a/builtin/grep.c b/builtin/grep.c
--- a/builtin/grep.c
+++ b/builtin/grep.c
+@@
+ /* 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;
+
+ /*
+ * skip a -- separator; we know it cannot be
@@
}
}
Documentation/git-grep.txt | 3 ++-
builtin/grep.c | 7 +++++--
t/t7814-grep-recurse-submodules.sh | 11 ++++++++++-
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index c89fb569e3..ffc3a6efdc 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -96,7 +96,8 @@ OPTIONS
Recursively search in each submodule that has been initialized and
checked out in the repository. When used in combination with the
<tree> option the prefix of all submodule output will be the name of
- the parent project's <tree> object.
+ the parent project's <tree> object. This option has no effect
+ if `--no-index` is given.
-a::
--text::
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;
/*
* 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"));
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
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] grep: ignore --recurse-submodules if --no-index is given
2020-01-30 13:37 ` [PATCH v2] " Philippe Blain via GitGitGadget
@ 2020-01-30 18:14 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2020-01-30 18:14 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget
Cc: git, Brandon Williams, SZEDER Gábor,
Matheus Tavares Bernardino, Philippe Blain
"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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-01-30 18:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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).