Merge branch 'rs/diff-no-minimal'
authorJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:46 +0000 (11:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:46 +0000 (11:20 -0700)
* rs/diff-no-minimal:
  git diff too slow for a file

1  2 
builtin/blame.c
builtin/merge-file.c
builtin/merge-tree.c
builtin/rerere.c
combine-diff.c
diff.c
merge-file.c

diff --combined builtin/blame.c
index 4dd4c3f494042c91e2fa481314d2d8d6d61d9c43,8deeee12b613dbd26c64cc1005151d67d0af7a4c..8506286dd271d4e92369d81ec2cce9240a559d64
@@@ -39,7 -39,7 +39,7 @@@ static int show_root
  static int reverse;
  static int blank_boundary;
  static int incremental;
- static int xdl_opts = XDF_NEED_MINIMAL;
+ static int xdl_opts;
  
  static enum date_mode blame_date_mode = DATE_ISO8601;
  static size_t blame_date_width;
@@@ -1589,7 -1589,7 +1589,7 @@@ static void emit_porcelain(struct score
        strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
        printf("%s%c%d %d %d\n",
               hex,
 -             ent->guilty ? ' ' : '*', // purely for debugging
 +             ent->guilty ? ' ' : '*', /* purely for debugging */
               ent->s_lno + 1,
               ent->lno + 1,
               ent->num_lines);
diff --combined builtin/merge-file.c
index 610849a6533c6fd2d3d2e8d3f8d233757174aabd,e5e860fa78e32355bc3b61999178dd64d00de75b..b8e9e5ba01658bbdd6e9d712b00da902b6f33fbe
@@@ -25,37 -25,32 +25,37 @@@ int cmd_merge_file(int argc, const cha
        const char *names[3] = { NULL, NULL, NULL };
        mmfile_t mmfs[3];
        mmbuffer_t result = {NULL, 0};
-       xmparam_t xmp = {{XDF_NEED_MINIMAL}};
+       xmparam_t xmp = {{0}};
        int ret = 0, i = 0, to_stdout = 0;
 -      int level = XDL_MERGE_ZEALOUS_ALNUM;
 -      int style = 0, quiet = 0;
 -      int favor = 0;
 +      int quiet = 0;
        int nongit;
 -
        struct option options[] = {
                OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
 -              OPT_SET_INT(0, "diff3", &style, "use a diff3 based merge", XDL_MERGE_DIFF3),
 -              OPT_SET_INT(0, "ours", &favor, "for conflicts, use our version",
 +              OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
 +              OPT_SET_INT(0, "ours", &xmp.favor, "for conflicts, use our version",
                            XDL_MERGE_FAVOR_OURS),
 -              OPT_SET_INT(0, "theirs", &favor, "for conflicts, use their version",
 +              OPT_SET_INT(0, "theirs", &xmp.favor, "for conflicts, use their version",
                            XDL_MERGE_FAVOR_THEIRS),
 +              OPT_SET_INT(0, "union", &xmp.favor, "for conflicts, use a union version",
 +                          XDL_MERGE_FAVOR_UNION),
 +              OPT_INTEGER(0, "marker-size", &xmp.marker_size,
 +                          "for conflicts, use this marker size"),
                OPT__QUIET(&quiet),
                OPT_CALLBACK('L', NULL, names, "name",
                             "set labels for file1/orig_file/file2", &label_cb),
                OPT_END(),
        };
  
 +      xmp.level = XDL_MERGE_ZEALOUS_ALNUM;
 +      xmp.style = 0;
 +      xmp.favor = 0;
 +
        prefix = setup_git_directory_gently(&nongit);
        if (!nongit) {
                /* Read the configuration file */
                git_config(git_xmerge_config, NULL);
                if (0 <= git_xmerge_style)
 -                      style = git_xmerge_style;
 +                      xmp.style = git_xmerge_style;
        }
  
        argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
                                        argv[i]);
        }
  
 -      ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
 -                      &xmp, XDL_MERGE_FLAGS(level, style, favor), &result);
 +      xmp.ancestor = names[1];
 +      xmp.file1 = names[0];
 +      xmp.file2 = names[2];
 +      ret = xdl_merge(mmfs + 1, mmfs + 0, mmfs + 2, &xmp, &result);
  
        for (i = 0; i < 3; i++)
                free(mmfs[i].ptr);
diff --combined builtin/merge-tree.c
index a4a4f2ce4c3f147062070c2acc08eaf9f4d40be8,fc00d794d641c146023a78d7d8e4143f0fdac302..fc00d794d641c146023a78d7d8e4143f0fdac302
@@@ -106,7 -106,7 +106,7 @@@ static void show_diff(struct merge_lis
        xdemitconf_t xecfg;
        xdemitcb_t ecb;
  
-       xpp.flags = XDF_NEED_MINIMAL;
+       xpp.flags = 0;
        memset(&xecfg, 0, sizeof(xecfg));
        xecfg.ctxlen = 3;
        ecb.outf = show_outf;
diff --combined builtin/rerere.c
index 34f9acee910406c7ba0bf9eed76267a0cf8f46c2,0048f9ef7fee24e5e058ef226f3b0fc93703fcf1..0048f9ef7fee24e5e058ef226f3b0fc93703fcf1
@@@ -89,7 -89,7 +89,7 @@@ static int diff_two(const char *file1, 
        printf("--- a/%s\n+++ b/%s\n", label1, label2);
        fflush(stdout);
        memset(&xpp, 0, sizeof(xpp));
-       xpp.flags = XDF_NEED_MINIMAL;
+       xpp.flags = 0;
        memset(&xecfg, 0, sizeof(xecfg));
        xecfg.ctxlen = 3;
        ecb.outf = outf;
diff --combined combine-diff.c
index 7557136c820a10570e72f6870ecc7a45c4c7ce36,13a812896116c81ab6423b0b9d4f1b9e52496e9f..655fa89d8a7ffe3c3823080f5af3e5e385e95440
@@@ -211,6 -211,7 +211,6 @@@ static void combine_diff(const unsigne
        xpparam_t xpp;
        xdemitconf_t xecfg;
        mmfile_t parent_file;
 -      xdemitcb_t ecb;
        struct combine_diff_state state;
        unsigned long sz;
  
        parent_file.ptr = grab_blob(parent, mode, &sz);
        parent_file.size = sz;
        memset(&xpp, 0, sizeof(xpp));
-       xpp.flags = XDF_NEED_MINIMAL;
+       xpp.flags = 0;
        memset(&xecfg, 0, sizeof(xecfg));
        memset(&state, 0, sizeof(state));
        state.nmask = nmask;
        state.n = n;
  
        xdi_diff_outf(&parent_file, result_file, consume_line, &state,
 -                    &xpp, &xecfg, &ecb);
 +                    &xpp, &xecfg);
        free(parent_file.ptr);
  
        /* Assign line numbers for this parent.
diff --combined diff.c
index 494f5601e97e7395e647296bc7f8090331a47c43,0924274dd3c21e6cf247a974cf0e492d907d8736..302b205572fdf962361522fdd051806400cd094d
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -44,8 -44,7 +44,8 @@@ static char diff_colors[][COLOR_MAXLEN
  };
  
  static void diff_filespec_load_driver(struct diff_filespec *one);
 -static char *run_textconv(const char *, struct diff_filespec *, size_t *);
 +static size_t fill_textconv(struct userdiff_driver *driver,
 +                          struct diff_filespec *df, char **outbuf);
  
  static int parse_diff_color_slot(const char *var, int ofs)
  {
@@@ -467,8 -466,8 +467,8 @@@ static void emit_rewrite_diff(const cha
                              const char *name_b,
                              struct diff_filespec *one,
                              struct diff_filespec *two,
 -                            const char *textconv_one,
 -                            const char *textconv_two,
 +                            struct userdiff_driver *textconv_one,
 +                            struct userdiff_driver *textconv_two,
                              struct diff_options *o)
  {
        int lc_a, lc_b;
        const char *reset = diff_get_color(color_diff, DIFF_RESET);
        static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
        const char *a_prefix, *b_prefix;
 -      const char *data_one, *data_two;
 +      char *data_one, *data_two;
        size_t size_one, size_two;
        struct emit_callback ecbdata;
  
        quote_two_c_style(&a_name, a_prefix, name_a, 0);
        quote_two_c_style(&b_name, b_prefix, name_b, 0);
  
 -      diff_populate_filespec(one, 0);
 -      diff_populate_filespec(two, 0);
 -      if (textconv_one) {
 -              data_one = run_textconv(textconv_one, one, &size_one);
 -              if (!data_one)
 -                      die("unable to read files to diff");
 -      }
 -      else {
 -              data_one = one->data;
 -              size_one = one->size;
 -      }
 -      if (textconv_two) {
 -              data_two = run_textconv(textconv_two, two, &size_two);
 -              if (!data_two)
 -                      die("unable to read files to diff");
 -      }
 -      else {
 -              data_two = two->data;
 -              size_two = two->size;
 -      }
 +      size_one = fill_textconv(textconv_one, one, &data_one);
 +      size_two = fill_textconv(textconv_two, two, &data_two);
  
        memset(&ecbdata, 0, sizeof(ecbdata));
        ecbdata.color_diff = color_diff;
                emit_rewrite_lines(&ecbdata, '-', data_one, size_one);
        if (lc_b)
                emit_rewrite_lines(&ecbdata, '+', data_two, size_two);
 +      if (textconv_one)
 +              free((char *)data_one);
 +      if (textconv_two)
 +              free((char *)data_two);
  }
  
  struct diff_words_buffer {
@@@ -560,68 -573,16 +560,68 @@@ static void diff_words_append(char *lin
        buffer->text.ptr[buffer->text.size] = '\0';
  }
  
 +struct diff_words_style_elem
 +{
 +      const char *prefix;
 +      const char *suffix;
 +      const char *color; /* NULL; filled in by the setup code if
 +                          * color is enabled */
 +};
 +
 +struct diff_words_style
 +{
 +      enum diff_words_type type;
 +      struct diff_words_style_elem new, old, ctx;
 +      const char *newline;
 +};
 +
 +struct diff_words_style diff_words_styles[] = {
 +      { DIFF_WORDS_PORCELAIN, {"+", "\n"}, {"-", "\n"}, {" ", "\n"}, "~\n" },
 +      { DIFF_WORDS_PLAIN, {"{+", "+}"}, {"[-", "-]"}, {"", ""}, "\n" },
 +      { DIFF_WORDS_COLOR, {"", ""}, {"", ""}, {"", ""}, "\n" }
 +};
 +
  struct diff_words_data {
        struct diff_words_buffer minus, plus;
        const char *current_plus;
        FILE *file;
        regex_t *word_regex;
 +      enum diff_words_type type;
 +      struct diff_words_style *style;
  };
  
 +static int fn_out_diff_words_write_helper(FILE *fp,
 +                                        struct diff_words_style_elem *st_el,
 +                                        const char *newline,
 +                                        size_t count, const char *buf)
 +{
 +      while (count) {
 +              char *p = memchr(buf, '\n', count);
 +              if (p != buf) {
 +                      if (st_el->color && fputs(st_el->color, fp) < 0)
 +                              return -1;
 +                      if (fputs(st_el->prefix, fp) < 0 ||
 +                          fwrite(buf, p ? p - buf : count, 1, fp) != 1 ||
 +                          fputs(st_el->suffix, fp) < 0)
 +                              return -1;
 +                      if (st_el->color && *st_el->color
 +                          && fputs(GIT_COLOR_RESET, fp) < 0)
 +                              return -1;
 +              }
 +              if (!p)
 +                      return 0;
 +              if (fputs(newline, fp) < 0)
 +                      return -1;
 +              count -= p + 1 - buf;
 +              buf = p + 1;
 +      }
 +      return 0;
 +}
 +
  static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
  {
        struct diff_words_data *diff_words = priv;
 +      struct diff_words_style *style = diff_words->style;
        int minus_first, minus_len, plus_first, plus_len;
        const char *minus_begin, *minus_end, *plus_begin, *plus_end;
  
                plus_begin = plus_end = diff_words->plus.orig[plus_first].end;
  
        if (diff_words->current_plus != plus_begin)
 -              fwrite(diff_words->current_plus,
 -                              plus_begin - diff_words->current_plus, 1,
 -                              diff_words->file);
 +              fn_out_diff_words_write_helper(diff_words->file,
 +                              &style->ctx, style->newline,
 +                              plus_begin - diff_words->current_plus,
 +                              diff_words->current_plus);
        if (minus_begin != minus_end)
 -              color_fwrite_lines(diff_words->file,
 -                              diff_get_color(1, DIFF_FILE_OLD),
 +              fn_out_diff_words_write_helper(diff_words->file,
 +                              &style->old, style->newline,
                                minus_end - minus_begin, minus_begin);
        if (plus_begin != plus_end)
 -              color_fwrite_lines(diff_words->file,
 -                              diff_get_color(1, DIFF_FILE_NEW),
 +              fn_out_diff_words_write_helper(diff_words->file,
 +                              &style->new, style->newline,
                                plus_end - plus_begin, plus_begin);
  
        diff_words->current_plus = plus_end;
@@@ -736,13 -696,13 +736,13 @@@ static void diff_words_show(struct diff
  {
        xpparam_t xpp;
        xdemitconf_t xecfg;
 -      xdemitcb_t ecb;
        mmfile_t minus, plus;
 +      struct diff_words_style *style = diff_words->style;
  
        /* special case: only removal */
        if (!diff_words->plus.text.size) {
 -              color_fwrite_lines(diff_words->file,
 -                      diff_get_color(1, DIFF_FILE_OLD),
 +              fn_out_diff_words_write_helper(diff_words->file,
 +                      &style->old, style->newline,
                        diff_words->minus.text.size, diff_words->minus.text.ptr);
                diff_words->minus.text.size = 0;
                return;
        memset(&xecfg, 0, sizeof(xecfg));
        diff_words_fill(&diff_words->minus, &minus, diff_words->word_regex);
        diff_words_fill(&diff_words->plus, &plus, diff_words->word_regex);
-       xpp.flags = XDF_NEED_MINIMAL;
+       xpp.flags = 0;
        /* as only the hunk header will be parsed, we need a 0-context */
        xecfg.ctxlen = 0;
        xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
 -                    &xpp, &xecfg, &ecb);
 +                    &xpp, &xecfg);
        free(minus.ptr);
        free(plus.ptr);
        if (diff_words->current_plus != diff_words->plus.text.ptr +
                        diff_words->plus.text.size)
 -              fwrite(diff_words->current_plus,
 +              fn_out_diff_words_write_helper(diff_words->file,
 +                      &style->ctx, style->newline,
                        diff_words->plus.text.ptr + diff_words->plus.text.size
 -                      - diff_words->current_plus, 1,
 -                      diff_words->file);
 +                      - diff_words->current_plus, diff_words->current_plus);
        diff_words->minus.text.size = diff_words->plus.text.size = 0;
  }
  
@@@ -878,9 -838,6 +878,9 @@@ static void fn_out_consume(void *priv, 
  
        if (len < 1) {
                emit_line(ecbdata->file, reset, reset, line, len);
 +              if (ecbdata->diff_words
 +                  && ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN)
 +                      fputs("~\n", ecbdata->file);
                return;
        }
  
                        return;
                }
                diff_words_flush(ecbdata);
 -              line++;
 -              len--;
 -              emit_line(ecbdata->file, plain, reset, line, len);
 +              if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {
 +                      emit_line(ecbdata->file, plain, reset, line, len);
 +                      fputs("~\n", ecbdata->file);
 +              } else {
 +                      /* don't print the prefix character */
 +                      emit_line(ecbdata->file, plain, reset, line+1, len-1);
 +              }
                return;
        }
  
@@@ -1629,26 -1582,14 +1629,26 @@@ void diff_set_mnemonic_prefix(struct di
                options->b_prefix = b;
  }
  
 -static const char *get_textconv(struct diff_filespec *one)
 +static struct userdiff_driver *get_textconv(struct diff_filespec *one)
  {
        if (!DIFF_FILE_VALID(one))
                return NULL;
        if (!S_ISREG(one->mode))
                return NULL;
        diff_filespec_load_driver(one);
 -      return one->driver->textconv;
 +      if (!one->driver->textconv)
 +              return NULL;
 +
 +      if (one->driver->textconv_want_cache && !one->driver->textconv_cache) {
 +              struct notes_cache *c = xmalloc(sizeof(*c));
 +              struct strbuf name = STRBUF_INIT;
 +
 +              strbuf_addf(&name, "textconv/%s", one->driver->name);
 +              notes_cache_init(c, name.buf, one->driver->textconv);
 +              one->driver->textconv_cache = c;
 +      }
 +
 +      return one->driver;
  }
  
  static void builtin_diff(const char *name_a,
        const char *set = diff_get_color_opt(o, DIFF_METAINFO);
        const char *reset = diff_get_color_opt(o, DIFF_RESET);
        const char *a_prefix, *b_prefix;
 -      const char *textconv_one = NULL, *textconv_two = NULL;
 +      struct userdiff_driver *textconv_one = NULL;
 +      struct userdiff_driver *textconv_two = NULL;
        struct strbuf header = STRBUF_INIT;
  
        if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
                }
        }
  
 -      if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
 -              die("unable to read files to diff");
 -
        if (!DIFF_OPT_TST(o, TEXT) &&
 -          ( (diff_filespec_is_binary(one) && !textconv_one) ||
 -            (diff_filespec_is_binary(two) && !textconv_two) )) {
 +          ( (!textconv_one && diff_filespec_is_binary(one)) ||
 +            (!textconv_two && diff_filespec_is_binary(two)) )) {
 +              if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
 +                      die("unable to read files to diff");
                /* Quite common confusing case */
                if (mf1.size == mf2.size &&
                    !memcmp(mf1.ptr, mf2.ptr, mf1.size))
                const char *diffopts = getenv("GIT_DIFF_OPTS");
                xpparam_t xpp;
                xdemitconf_t xecfg;
 -              xdemitcb_t ecb;
                struct emit_callback ecbdata;
                const struct userdiff_funcname *pe;
  
                        strbuf_reset(&header);
                }
  
 -              if (textconv_one) {
 -                      size_t size;
 -                      mf1.ptr = run_textconv(textconv_one, one, &size);
 -                      if (!mf1.ptr)
 -                              die("unable to read files to diff");
 -                      mf1.size = size;
 -              }
 -              if (textconv_two) {
 -                      size_t size;
 -                      mf2.ptr = run_textconv(textconv_two, two, &size);
 -                      if (!mf2.ptr)
 -                              die("unable to read files to diff");
 -                      mf2.size = size;
 -              }
 +              mf1.size = fill_textconv(textconv_one, one, &mf1.ptr);
 +              mf2.size = fill_textconv(textconv_two, two, &mf2.ptr);
  
                pe = diff_funcname_pattern(one);
                if (!pe)
                        check_blank_at_eof(&mf1, &mf2, &ecbdata);
                ecbdata.file = o->file;
                ecbdata.header = header.len ? &header : NULL;
-               xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
+               xpp.flags = o->xdl_opts;
                xecfg.ctxlen = o->context;
                xecfg.interhunkctxlen = o->interhunkcontext;
                xecfg.flags = XDL_EMIT_FUNCNAMES;
                        xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
                else if (!prefixcmp(diffopts, "-u"))
                        xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
 -              if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) {
 +              if (o->word_diff) {
 +                      int i;
 +
                        ecbdata.diff_words =
                                xcalloc(1, sizeof(struct diff_words_data));
                        ecbdata.diff_words->file = o->file;
 +                      ecbdata.diff_words->type = o->word_diff;
                        if (!o->word_regex)
                                o->word_regex = userdiff_word_regex(one);
                        if (!o->word_regex)
                                        die ("Invalid regular expression: %s",
                                                        o->word_regex);
                        }
 +                      for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) {
 +                              if (o->word_diff == diff_words_styles[i].type) {
 +                                      ecbdata.diff_words->style =
 +                                              &diff_words_styles[i];
 +                                      break;
 +                              }
 +                      }
 +                      if (DIFF_OPT_TST(o, COLOR_DIFF)) {
 +                              struct diff_words_style *st = ecbdata.diff_words->style;
 +                              st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
 +                              st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
 +                              st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN);
 +                      }
                }
                xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
 -                            &xpp, &xecfg, &ecb);
 -              if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
 +                            &xpp, &xecfg);
 +              if (o->word_diff)
                        free_diff_words_data(&ecbdata);
                if (textconv_one)
                        free(mf1.ptr);
@@@ -1891,12 -1829,13 +1891,12 @@@ static void builtin_diffstat(const cha
                /* Crazy xdl interfaces.. */
                xpparam_t xpp;
                xdemitconf_t xecfg;
 -              xdemitcb_t ecb;
  
                memset(&xpp, 0, sizeof(xpp));
                memset(&xecfg, 0, sizeof(xecfg));
-               xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
+               xpp.flags = o->xdl_opts;
                xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
 -                            &xpp, &xecfg, &ecb);
 +                            &xpp, &xecfg);
        }
  
   free_and_return:
@@@ -1938,13 -1877,14 +1938,13 @@@ static void builtin_checkdiff(const cha
                /* Crazy xdl interfaces.. */
                xpparam_t xpp;
                xdemitconf_t xecfg;
 -              xdemitcb_t ecb;
  
                memset(&xpp, 0, sizeof(xpp));
                memset(&xecfg, 0, sizeof(xecfg));
                xecfg.ctxlen = 1; /* at least one context line */
-               xpp.flags = XDF_NEED_MINIMAL;
+               xpp.flags = 0;
                xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
 -                            &xpp, &xecfg, &ecb);
 +                            &xpp, &xecfg);
  
                if (data.ws_rule & WS_BLANK_AT_EOF) {
                        struct emit_callback ecbdata;
@@@ -2093,7 -2033,7 +2093,7 @@@ static int diff_populate_gitlink(struc
        char *data = xmalloc(100), *dirty = "";
  
        /* Are we looking at the work tree? */
 -      if (!s->sha1_valid && s->dirty_submodule)
 +      if (s->dirty_submodule)
                dirty = "-dirty";
  
        len = snprintf(data, 100,
@@@ -2600,7 -2540,6 +2600,7 @@@ static void run_checkdiff(struct diff_f
  void diff_setup(struct diff_options *options)
  {
        memset(options, 0, sizeof(*options));
 +      memset(&diff_queued_diff, 0, sizeof(diff_queued_diff));
  
        options->file = stdout;
  
@@@ -2690,12 -2629,6 +2690,12 @@@ int diff_setup_done(struct diff_option
         */
        if (options->pickaxe)
                DIFF_OPT_SET(options, RECURSIVE);
 +      /*
 +       * When patches are generated, submodules diffed against the work tree
 +       * must be checked for dirtiness too so it can be shown in the output
 +       */
 +      if (options->output_format & DIFF_FORMAT_PATCH)
 +              DIFF_OPT_SET(options, DIRTY_SUBMODULES);
  
        if (options->detect_rename && options->rename_limit < 0)
                options->rename_limit = diff_rename_limit_default;
@@@ -2779,7 -2712,7 +2779,7 @@@ int diff_opt_parse(struct diff_options 
        const char *arg = av[0];
  
        /* Output format options */
 -      if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
 +      if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch"))
                options->output_format |= DIFF_FORMAT_PATCH;
        else if (opt_arg(arg, 'U', "unified", &options->context))
                options->output_format |= DIFF_FORMAT_PATCH;
                DIFF_OPT_SET(options, FOLLOW_RENAMES);
        else if (!strcmp(arg, "--color"))
                DIFF_OPT_SET(options, COLOR_DIFF);
 +      else if (!prefixcmp(arg, "--color=")) {
 +              int value = git_config_colorbool(NULL, arg+8, -1);
 +              if (value == 0)
 +                      DIFF_OPT_CLR(options, COLOR_DIFF);
 +              else if (value > 0)
 +                      DIFF_OPT_SET(options, COLOR_DIFF);
 +              else
 +                      return error("option `color' expects \"always\", \"auto\", or \"never\"");
 +      }
        else if (!strcmp(arg, "--no-color"))
                DIFF_OPT_CLR(options, COLOR_DIFF);
        else if (!strcmp(arg, "--color-words")) {
                DIFF_OPT_SET(options, COLOR_DIFF);
 -              DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
 +              options->word_diff = DIFF_WORDS_COLOR;
        }
        else if (!prefixcmp(arg, "--color-words=")) {
                DIFF_OPT_SET(options, COLOR_DIFF);
 -              DIFF_OPT_SET(options, COLOR_DIFF_WORDS);
 +              options->word_diff = DIFF_WORDS_COLOR;
                options->word_regex = arg + 14;
        }
 +      else if (!strcmp(arg, "--word-diff")) {
 +              if (options->word_diff == DIFF_WORDS_NONE)
 +                      options->word_diff = DIFF_WORDS_PLAIN;
 +      }
 +      else if (!prefixcmp(arg, "--word-diff=")) {
 +              const char *type = arg + 12;
 +              if (!strcmp(type, "plain"))
 +                      options->word_diff = DIFF_WORDS_PLAIN;
 +              else if (!strcmp(type, "color")) {
 +                      DIFF_OPT_SET(options, COLOR_DIFF);
 +                      options->word_diff = DIFF_WORDS_COLOR;
 +              }
 +              else if (!strcmp(type, "porcelain"))
 +                      options->word_diff = DIFF_WORDS_PORCELAIN;
 +              else if (!strcmp(type, "none"))
 +                      options->word_diff = DIFF_WORDS_NONE;
 +              else
 +                      die("bad --word-diff argument: %s", type);
 +      }
 +      else if (!prefixcmp(arg, "--word-diff-regex=")) {
 +              if (options->word_diff == DIFF_WORDS_NONE)
 +                      options->word_diff = DIFF_WORDS_PLAIN;
 +              options->word_regex = arg + 18;
 +      }
        else if (!strcmp(arg, "--exit-code"))
                DIFF_OPT_SET(options, EXIT_WITH_STATUS);
        else if (!strcmp(arg, "--quiet"))
@@@ -3178,8 -3078,7 +3178,8 @@@ int diff_unmodified_pair(struct diff_fi
         * dealing with a change.
         */
        if (one->sha1_valid && two->sha1_valid &&
 -          !hashcmp(one->sha1, two->sha1))
 +          !hashcmp(one->sha1, two->sha1) &&
 +          !one->dirty_submodule && !two->dirty_submodule)
                return 1; /* no change */
        if (!one->sha1_valid && !two->sha1_valid)
                return 1; /* both look at the same file on the filesystem. */
@@@ -3314,8 -3213,6 +3314,8 @@@ static void diff_resolve_rename_copy(vo
                }
                else if (hashcmp(p->one->sha1, p->two->sha1) ||
                         p->one->mode != p->two->mode ||
 +                       p->one->dirty_submodule ||
 +                       p->two->dirty_submodule ||
                         is_null_sha1(p->one->sha1))
                        p->status = DIFF_STATUS_MODIFIED;
                else {
@@@ -3464,6 -3361,7 +3464,6 @@@ static int diff_get_patch_id(struct dif
        for (i = 0; i < q->nr; i++) {
                xpparam_t xpp;
                xdemitconf_t xecfg;
 -              xdemitcb_t ecb;
                mmfile_t mf1, mf2;
                struct diff_filepair *p = q->queue[i];
                int len1, len2;
                                        len2, p->two->path);
                git_SHA1_Update(&ctx, buffer, len1);
  
-               xpp.flags = XDF_NEED_MINIMAL;
+               xpp.flags = 0;
                xecfg.ctxlen = 3;
                xecfg.flags = XDL_EMIT_FUNCNAMES;
                xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
 -                            &xpp, &xecfg, &ecb);
 +                            &xpp, &xecfg);
        }
  
        git_SHA1_Final(sha1, &ctx);
@@@ -3542,7 -3440,8 +3542,7 @@@ int diff_flush_patch_id(struct diff_opt
                diff_free_filepair(q->queue[i]);
  
        free(q->queue);
 -      q->queue = NULL;
 -      q->nr = q->alloc = 0;
 +      DIFF_QUEUE_CLEAR(q);
  
        return result;
  }
@@@ -3670,7 -3569,8 +3670,7 @@@ void diff_flush(struct diff_options *op
                diff_free_filepair(q->queue[i]);
  free_queue:
        free(q->queue);
 -      q->queue = NULL;
 -      q->nr = q->alloc = 0;
 +      DIFF_QUEUE_CLEAR(q);
        if (options->close_file)
                fclose(options->file);
  
@@@ -3692,7 -3592,8 +3692,7 @@@ static void diffcore_apply_filter(cons
        int i;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
 -      outq.queue = NULL;
 -      outq.nr = outq.alloc = 0;
 +      DIFF_QUEUE_CLEAR(&outq);
  
        if (!filter)
                return;
@@@ -3760,7 -3661,8 +3760,7 @@@ static void diffcore_skip_stat_unmatch(
        int i;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
 -      outq.queue = NULL;
 -      outq.nr = outq.alloc = 0;
 +      DIFF_QUEUE_CLEAR(&outq);
  
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
@@@ -3821,12 -3723,6 +3821,12 @@@ void diffcore_fix_diff_index(struct dif
  
  void diffcore_std(struct diff_options *options)
  {
 +      /* We never run this function more than one time, because the
 +       * rename/copy detection logic can only run once.
 +       */
 +      if (diff_queued_diff.run)
 +              return;
 +
        if (options->skip_stat_unmatch)
                diffcore_skip_stat_unmatch(options);
        if (options->break_opt != -1)
                DIFF_OPT_SET(options, HAS_CHANGES);
        else
                DIFF_OPT_CLR(options, HAS_CHANGES);
 +
 +      diff_queued_diff.run = 1;
  }
  
  int diff_result_code(struct diff_options *opt, int status)
@@@ -4001,47 -3895,3 +4001,47 @@@ static char *run_textconv(const char *p
  
        return strbuf_detach(&buf, outsize);
  }
 +
 +static size_t fill_textconv(struct userdiff_driver *driver,
 +                          struct diff_filespec *df,
 +                          char **outbuf)
 +{
 +      size_t size;
 +
 +      if (!driver || !driver->textconv) {
 +              if (!DIFF_FILE_VALID(df)) {
 +                      *outbuf = "";
 +                      return 0;
 +              }
 +              if (diff_populate_filespec(df, 0))
 +                      die("unable to read files to diff");
 +              *outbuf = df->data;
 +              return df->size;
 +      }
 +
 +      if (driver->textconv_cache) {
 +              *outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
 +                                        &size);
 +              if (*outbuf)
 +                      return size;
 +      }
 +
 +      *outbuf = run_textconv(driver->textconv, df, &size);
 +      if (!*outbuf)
 +              die("unable to read files to diff");
 +
 +      if (driver->textconv_cache) {
 +              /* ignore errors, as we might be in a readonly repository */
 +              notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
 +                              size);
 +              /*
 +               * we could save up changes and flush them all at the end,
 +               * but we would need an extra call after all diffing is done.
 +               * Since generating a cache entry is the slow path anyway,
 +               * this extra overhead probably isn't a big deal.
 +               */
 +              notes_cache_write(driver->textconv_cache);
 +      }
 +
 +      return size;
 +}
diff --combined merge-file.c
index c336c93c01c0bad76d6189065f0e6630d0b7f5af,cafc274e2d0438c346ecc6d8df4290b740470756..db4d0d50d32d8852d1cb5173125e4173c3badb49
@@@ -30,13 -30,7 +30,13 @@@ static void *three_way_filemerge(const 
        int merge_status;
        mmbuffer_t res;
  
 -      merge_status = ll_merge(&res, path, base,
 +      /*
 +       * This function is only used by cmd_merge_tree, which
 +       * does not respect the merge.conflictstyle option.
 +       * There is no need to worry about a label for the
 +       * common ancestor.
 +       */
 +      merge_status = ll_merge(&res, path, base, NULL,
                                our, ".our", their, ".their", 0);
        if (merge_status < 0)
                return NULL;
@@@ -66,7 -60,7 +66,7 @@@ static int generate_common_file(mmfile_
        xdemitcb_t ecb;
  
        memset(&xpp, 0, sizeof(xpp));
-       xpp.flags = XDF_NEED_MINIMAL;
+       xpp.flags = 0;
        memset(&xecfg, 0, sizeof(xecfg));
        xecfg.ctxlen = 3;
        xecfg.flags = XDL_EMIT_COMMON;