From ba8ea7496f2b95c49fccb72ed6b332afbd865e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 1 Aug 2011 19:20:53 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/grep.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin') 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); } -- cgit v1.2.1 From 317f63c21c8eac46813eacf487485445f2f79a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 1 Aug 2011 19:22:52 +0200 Subject: grep: long context options Take long option names for -A (--after-context), -B (--before-context) and -C (--context) from GNU grep and add a similar long option name for -W (--function-context). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/grep.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/grep.c b/builtin/grep.c index 1fae66262f..1851797540 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -827,18 +827,18 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_BOOLEAN(0, "heading", &opt.heading, "show filename only once above matches from same file"), OPT_GROUP(""), - OPT_CALLBACK('C', NULL, &opt, "n", + OPT_CALLBACK('C', "context", &opt, "n", "show context lines before and after matches", context_callback), - OPT_INTEGER('B', NULL, &opt.pre_context, + OPT_INTEGER('B', "before-context", &opt.pre_context, "show context lines before matches"), - OPT_INTEGER('A', NULL, &opt.post_context, + OPT_INTEGER('A', "after-context", &opt.post_context, "show context lines after matches"), OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM", context_callback), OPT_BOOLEAN('p', "show-function", &opt.funcname, "show a line with the function name before matches"), - OPT_BOOLEAN('W', NULL, &opt.funcbody, + OPT_BOOLEAN('W', "function-context", &opt.funcbody, "show the surrounding function"), OPT_GROUP(""), OPT_CALLBACK('f', NULL, &opt, "file", -- cgit v1.2.1