Merge branch 'rs/grep-p'
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Jul 2009 07:59:58 +0000 (00:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jul 2009 07:59:58 +0000 (00:59 -0700)
* rs/grep-p:
grep: simplify -p output
grep -p: support user defined regular expressions
grep: add option -p/--show-function
grep: handle pre context lines on demand
grep: print context hunk marks between files
grep: move context hunk mark handling into show_line()
userdiff: add xdiff_clear_find_func()

1  2 
builtin-grep.c
diff.c
diff --combined builtin-grep.c
index e5583686a2daeb05def8358044f49f03ba3acbef,ff8e51b43ee7ebf635d72de023dca898c0db9440..f477659100fdc63bff5938b4c96f28eaefc07460
@@@ -11,6 -11,7 +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 +31,12 @@@ static int grep_config(const char *var
  {
        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 +285,17 @@@ static int flush_grep(struct grep_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 +612,7 @@@ static int file_callback(const struct o
  
        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 +728,8 @@@ int cmd_grep(int argc, const char **arg
                        "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),
                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.");
diff --combined diff.c
index 0a020ffab4dcfbd88fbee31bb3c84e336a67b17c,892921cdc71e75b7dfecf9bc3fcc04147576c1a3..cd35e0c2d7e29012e24cc8f5f49d9d351420b56e
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -1603,6 -1603,7 +1603,7 @@@ static void builtin_diff(const char *na
                        free(mf1.ptr);
                if (textconv_two)
                        free(mf2.ptr);
+               xdiff_clear_find_func(&xecfg);
        }
  
   free_ab_and_return:
@@@ -1975,14 -1976,14 +1976,14 @@@ static void prep_temp_blob(const char *
        fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,
                        strlen(base) + 1);
        if (fd < 0)
 -              die("unable to create temp-file: %s", strerror(errno));
 +              die_errno("unable to create temp-file");
        if (convert_to_working_tree(path,
                        (const char *)blob, (size_t)size, &buf)) {
                blob = buf.buf;
                size = buf.len;
        }
        if (write_in_full(fd, blob, size) != size)
 -              die("unable to write temp-file");
 +              die_errno("unable to write temp-file");
        close(fd);
        temp->name = temp->tmp_path;
        strcpy(temp->hex, sha1_to_hex(sha1));
@@@ -2021,12 -2022,12 +2022,12 @@@ static struct diff_tempfile *prepare_te
                if (lstat(name, &st) < 0) {
                        if (errno == ENOENT)
                                goto not_a_valid_file;
 -                      die("stat(%s): %s", name, strerror(errno));
 +                      die_errno("stat(%s)", name);
                }
                if (S_ISLNK(st.st_mode)) {
                        struct strbuf sb = STRBUF_INIT;
                        if (strbuf_readlink(&sb, name, st.st_size) < 0)
 -                              die("readlink(%s)", name);
 +                              die_errno("readlink(%s)", name);
                        prep_temp_blob(name, temp, sb.buf, sb.len,
                                       (one->sha1_valid ?
                                        one->sha1 : null_sha1),
@@@ -2219,7 -2220,7 +2220,7 @@@ static void diff_fill_sha1_info(struct 
                                return;
                        }
                        if (lstat(one->path, &st) < 0)
 -                              die("stat %s", one->path);
 +                              die_errno("stat '%s'", one->path);
                        if (index_path(one->sha1, one->path, &st, 0))
                                die("cannot hash %s", one->path);
                }