aboutsummaryrefslogtreecommitdiffstats
path: root/grep.c
diff options
context:
space:
mode:
authorCarlos López <00xc@protonmail.com>2022-06-22 19:47:32 +0000
committerJunio C Hamano <gitster@pobox.com>2022-06-22 13:23:29 -0700
commit68437ede53dccd1dea9e44e831a59de274d389de (patch)
tree4522d5e4501a87bd71ed5d0d0a3e7e1dd76b3cb7 /grep.c
parentf770e9f396d48b567ef7b37d273e91ad570a3522 (diff)
downloadgit-68437ede53dccd1dea9e44e831a59de274d389de.tar.gz
grep: add --max-count command line option
This patch adds a command line option analogous to that of GNU grep(1)'s -m / --max-count, which users might already be used to. This makes it possible to limit the amount of matches shown in the output while keeping the functionality of other options such as -C (show code context) or -p (show containing function), which would be difficult to do with a shell pipeline (e.g. head(1)). Signed-off-by: Carlos López 00xc@protonmail.com Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/grep.c b/grep.c
index 82eb7da102..52a894c989 100644
--- a/grep.c
+++ b/grep.c
@@ -1615,7 +1615,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
return 0;
goto next_line;
}
- if (hit) {
+ if (hit && (opt->max_count < 0 || count < opt->max_count)) {
count++;
if (opt->status_only)
return 1;