Skip to content

Commit 0281e48

Browse files
bmwillgitster
authored andcommitted
grep: optionally recurse into submodules
Allow grep to recognize submodules and recursively search for patterns in each submodule. This is done by forking off a process to recursively call grep on each submodule. The top level --super-prefix option is used to pass a path to the submodule which can in turn be used to prepend to output or in pathspec matching logic. Recursion only occurs for submodules which have been initialized and checked out by the parent project. If a submodule hasn't been initialized and checked out it is simply skipped. In order to support the existing multi-threading infrastructure in grep, output from each child process is captured in a strbuf so that it can be later printed to the console in an ordered fashion. To limit the number of theads that are created, each child process has half the number of threads as its parents (minimum of 1), otherwise we potentailly have a fork-bomb. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4538eef commit 0281e48

File tree

4 files changed

+386
-20
lines changed

4 files changed

+386
-20
lines changed

Documentation/git-grep.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SYNOPSIS
2626
[--threads <num>]
2727
[-f <file>] [-e] <pattern>
2828
[--and|--or|--not|(|)|-e <pattern>...]
29+
[--recurse-submodules]
2930
[ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
3031
[--] [<pathspec>...]
3132

@@ -88,6 +89,10 @@ OPTIONS
8889
mechanism. Only useful when searching files in the current directory
8990
with `--no-index`.
9091

92+
--recurse-submodules::
93+
Recursively search in each submodule that has been initialized and
94+
checked out in the repository.
95+
9196
-a::
9297
--text::
9398
Process binary files as if they were text.

0 commit comments

Comments
 (0)