summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2011-08-01 19:20:53 +0200
committerJunio C Hamano <gitster@pobox.com>2011-08-01 16:09:15 -0700
commitba8ea7496f2b95c49fccb72ed6b332afbd865e7b (patch)
treec52a2d2007a2e209813df918dede0b05bbd08be8 /builtin/grep.c
parentb35acb53458d0f99ba2400b902980b35e5acc2d3 (diff)
downloadgit-ba8ea7496f2b95c49fccb72ed6b332afbd865e7b.tar.gz
grep: add option to show whole function as context
Add a new option, -W, to show the whole surrounding function of a match. It uses the same regular expressions as -p and diff to find the beginning of sections. Currently it will not display comments in front of a function, but those that are following one. Despite this shortcoming it is already useful, e.g. to simply see a more complete applicable context or to extract whole functions. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index cccf8da6d2..1fae66262f 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -838,6 +838,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
context_callback),
OPT_BOOLEAN('p', "show-function", &opt.funcname,
"show a line with the function name before matches"),
+ OPT_BOOLEAN('W', NULL, &opt.funcbody,
+ "show the surrounding function"),
OPT_GROUP(""),
OPT_CALLBACK('f', NULL, &opt, "file",
"read patterns from file", file_callback),
@@ -980,7 +982,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
use_threads = 0;
if (use_threads) {
- if (opt.pre_context || opt.post_context || opt.file_break)
+ if (opt.pre_context || opt.post_context || opt.file_break ||
+ opt.funcbody)
skip_first_line = 1;
start_threads(&opt);
}