#include "tree-walk.h"
#include "builtin.h"
#include "parse-options.h"
+#include "userdiff.h"
#include "grep.h"
#ifndef NO_EXTERNAL_GREP
{
struct grep_opt *opt = cb;
+ switch (userdiff_config(var, value)) {
+ case 0: break;
+ case -1: return -1;
+ default: return 0;
+ }
+
if (!strcmp(var, "color.grep")) {
opt->color = git_config_colorbool(var, value, -1);
return 0;
argc -= 2;
}
+ if (opt->pre_context || opt->post_context) {
+ /*
+ * 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);
+ else
+ opt->show_hunk_mark = 1;
+ }
+
status = exec_grep(argc, argv);
if (kept_0) {
patterns = fopen(arg, "r");
if (!patterns)
- die("'%s': %s", arg, strerror(errno));
+ die_errno("cannot open '%s'", arg);
while (strbuf_getline(&sb, patterns, '\n') == 0) {
/* ignore empty line like grep does */
if (sb.len == 0)
"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),
* unrecognized non option is the beginning of the refs list
* that continues up to the -- (if exists), and then paths.
*/
- argc = parse_options(argc, argv, options, grep_usage,
+ argc = parse_options(argc, argv, prefix, options, grep_usage,
PARSE_OPT_KEEP_DASHDASH |
PARSE_OPT_STOP_AT_NON_OPTION |
PARSE_OPT_NO_INTERNAL_HELP);
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.");