Skip to content

Commit

Permalink
grep: optionally recurse into submodules
Browse files Browse the repository at this point in the history
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 <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bmwill authored and gitster committed Dec 22, 2016
1 parent 4538eef commit 0281e48
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Documentation/git-grep.txt
Expand Up @@ -26,6 +26,7 @@ SYNOPSIS
[--threads <num>]
[-f <file>] [-e] <pattern>
[--and|--or|--not|(|)|-e <pattern>...]
[--recurse-submodules]
[ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
[--] [<pathspec>...]

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

--recurse-submodules::
Recursively search in each submodule that has been initialized and
checked out in the repository.

-a::
--text::
Process binary files as if they were text.
Expand Down

0 comments on commit 0281e48

Please sign in to comment.