X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-grep.c;h=f477659100fdc63bff5938b4c96f28eaefc07460;hb=e532e7b08f3de1a590db909c2c93532c2a39e9ae;hp=73fc922c4995369c0ca86c01200e2a0ea39161ab;hpb=7d40f89137b456820d51ebc1cbb3ffbb966e7fec;p=git.git diff --git a/builtin-grep.c b/builtin-grep.c index 73fc922c4..f47765910 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -11,6 +11,7 @@ #include "tree-walk.h" #include "builtin.h" #include "parse-options.h" +#include "userdiff.h" #include "grep.h" #ifndef NO_EXTERNAL_GREP @@ -30,6 +31,12 @@ static int grep_config(const char *var, const char *value, void *cb) { 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; @@ -278,6 +285,17 @@ static int flush_grep(struct grep_opt *opt, 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) { @@ -594,7 +612,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset) 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) @@ -710,6 +728,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) "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_GROUP(""), OPT_CALLBACK('f', NULL, &opt, "file", "read patterns from file", file_callback), @@ -778,7 +798,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.");