summaryrefslogtreecommitdiff
path: root/builtin-grep.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2009-07-02 00:06:34 +0200
committerJunio C Hamano <gitster@pobox.com>2009-07-01 19:16:49 -0700
commit2944e4e6145bdfcb1a8730d7da671786d72c86ed (patch)
treea0a293f3b48ec4a732eb4f1743f8cf6b15b041d1 /builtin-grep.c
parent49de3216983cc921ea66ade18a8521d4d74bbf3f (diff)
downloadgit-2944e4e6145bdfcb1a8730d7da671786d72c86ed.tar.gz
grep: add option -p/--show-function
The new option -p instructs git grep to print the previous function definition as a context line, similar to diff -p. Such context lines are marked with an equal sign instead of a dash. This option complements the existing context options -A, -B, -C. Function definitions are detected using the same heuristic that diff uses. User defined regular expressions are not supported, yet. 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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index 48998af911..037452ec79 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -278,13 +278,13 @@ static int flush_grep(struct grep_opt *opt,
argc -= 2;
}
- if (opt->pre_context || opt->post_context) {
+ if (opt->pre_context || opt->post_context || opt->funcname) {
/*
* grep handles hunk marks between files, but we need to
* do that ourselves between multiple calls.
*/
if (opt->show_hunk_mark)
- write_or_die(1, "--\n", 3);
+ write_or_die(1, opt->funcname ? "==\n" : "--\n", 3);
else
opt->show_hunk_mark = 1;
}
@@ -721,6 +721,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
"show <n> 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_GROUP(""),
OPT_CALLBACK('f', NULL, &opt, "file",
"read patterns from file", file_callback),
@@ -789,7 +791,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
argc--;
}
- if (opt.color && !opt.color_external)
+ if ((opt.color && !opt.color_external) || opt.funcname)
external_grep_allowed = 0;
if (!opt.pattern_list)
die("no pattern given.");