git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 6/8] builtin/grep.c: respect 'submodule.recurse' option

From
Stefan Beller <sbeller@google.com>
Date
May 26, 2017, 19:10 UTC
Message-ID
<20170526191017.19155-7-sbeller@google.com>
In-Reply-To
<20170526191017.19155-1-sbeller@google.com>

In builtin/grep.c we parse the config before evaluating the command line options. This makes the task of teaching grep to respect the new config option 'submodule.recurse' very easy by just parsing that option.

As an alternative I had implemented a similar structure to treat
submodules as the fetch/push command have, including
* aligning the meaning of the 'recurse_submodules' to possible submodule
  values RECURSE_SUBMODULES_* as defined in submodule.h.
* having a callback to parse the value and
* reacting to the RECURSE_SUBMODULES_DEFAULT state that was the initial
  state.

However all this is not needed for a true boolean value, so let's keep it simple. However this adds another place where "submodule.recurse" is parsed.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/grep.c                     |  3 +++
 t/t7814-grep-recurse-submodules.sh | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
diff --git a/builtin/grep.c b/builtin/grep.c
index b1095362fb..454e263820 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -302,6 +302,9 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
 #endif
 	}
 
+	if (!strcmp(var, "submodule.recurse"))
+		recurse_submodules = git_config_bool(var, value);
+
 	return st;
 }
 
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 3a58197f47..7184113b9b 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -33,6 +33,24 @@ test_expect_success 'grep correctly finds patterns in a submodule' '
 	test_cmp expect actual
 '
 
+test_expect_success 'grep finds patterns in a submodule via config' '
+	test_config submodule.recurse true &&
+	# expect from previous test
+	git grep -e "(3|4)" >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'grep --no-recurse-submodules overrides config' '
+	test_config submodule.recurse true &&
+	cat >expect <<-\EOF &&
+	a:(1|2)d(3|4)
+	b/b:(3|4)
+	EOF
+
+	git grep -e "(3|4)" --no-recurse-submodules >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'grep and basic pathspecs' '
 	cat >expect <<-\EOF &&
 	submodule/a:(1|2)d(3|4)
-- 
2.13.0.17.g582985b1e4
Previous: Stefan BellerNext: Stefan Beller
Message 7 of 15 in “[PATCHv2 0/8] A reroll of sb/submodule-blanket-recursive”
  1. Stefan BellerMay 26, 2017
  2. 1/8 submodule recursing: do not write a config variable twiceStefan Beller, May 26, 2017
  3. 4/8 submodule loading: separate code path for .gitmodules and config overlayStefan Beller, May 26, 2017
  4. 8/8 builtin/fetch.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  5. 5/8 Introduce 'submodule.recurse' option for worktree manipulatorsStefan Beller, May 26, 2017
  6. 3/8 reset/checkout/read-tree: unify config callback for submodule recursionStefan Beller, May 26, 2017
  7. 6/8 builtin/grep.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  8. 2/8 submodule test invocation: only pass additional argumentsStefan Beller, May 26, 2017
  9. 7/8 builtin/push.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  10. Junio C HamanoMay 30, 2017
  11. 0/4 A reroll of sb/submodule-blanket-recursiveStefan Beller, Jun 1, 2017
  12. 1/4 Introduce 'submodule.recurse' option for worktree manipulatorsStefan Beller, Jun 1, 2017
  13. 3/4 builtin/push.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017
  14. 2/4 builtin/grep.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017
  15. 4/4 builtin/fetch.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.