summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index bcb07ea..e6bcdf8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -961,6 +961,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_BOOL_F(0, "ext-grep", &external_grep_allowed__ignored,
N_("allow calling of grep(1) (ignored by this build)"),
PARSE_OPT_NOCOMPLETE),
+ OPT_INTEGER('m', "max-count", &opt.max_count,
+ N_("maximum number of results per file")),
OPT_END()
};
grep_prefix = prefix;
@@ -1101,6 +1103,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (recurse_submodules && untracked)
die(_("--untracked not supported with --recurse-submodules"));
+ /*
+ * Optimize out the case where the amount of matches is limited to zero.
+ * We do this to keep results consistent with GNU grep(1).
+ */
+ if (opt.max_count == 0)
+ return 1;
+
if (show_in_pager) {
if (num_threads > 1)
warning(_("invalid option combination, ignoring --threads"));