Merge branch 'by/diff-graph'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jun 2010 18:16:57 +0000 (11:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jun 2010 18:16:57 +0000 (11:16 -0700)
* by/diff-graph:
  Make --color-words work well with --graph
  graph.c: register a callback for graph output
  Emit a whole line in one go
  diff.c: Output the text graph padding before each diff line
  Output the graph columns at the end of the commit message
  Add a prefix output callback to diff output

Conflicts:
diff.c

1  2 
diff.c

diff --cc diff.c
index b53b6ec8e2ced8c94c0353dddf07ca5c1dd79978,974b6a997a8ee506a0fec05e513374085c85aec6..c6b5fb376ac5ca165cb5441d2b17a6be5432f0f6
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -1707,25 -1885,25 +1890,25 @@@ static void builtin_diff(const char *na
        b_two = quote_two(b_prefix, name_b + (*name_b == '/'));
        lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
        lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
-       strbuf_addf(&header, "%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+       strbuf_addf(&header, "%s%sdiff --git %s %s%s\n", line_prefix, set, a_one, b_two, reset);
        if (lbl[0][0] == '/') {
                /* /dev/null */
-               strbuf_addf(&header, "%snew file mode %06o%s\n", set, two->mode, reset);
+               strbuf_addf(&header, "%s%snew file mode %06o%s\n", line_prefix, set, two->mode, reset);
 -              if (xfrm_msg && xfrm_msg[0])
 -                      strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset);
 +              if (xfrm_msg)
 +                      strbuf_addstr(&header, xfrm_msg);
        }
        else if (lbl[1][0] == '/') {
-               strbuf_addf(&header, "%sdeleted file mode %06o%s\n", set, one->mode, reset);
+               strbuf_addf(&header, "%s%sdeleted file mode %06o%s\n", line_prefix, set, one->mode, reset);
 -              if (xfrm_msg && xfrm_msg[0])
 -                      strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset);
 +              if (xfrm_msg)
 +                      strbuf_addstr(&header, xfrm_msg);
        }
        else {
                if (one->mode != two->mode) {
-                       strbuf_addf(&header, "%sold mode %06o%s\n", set, one->mode, reset);
-                       strbuf_addf(&header, "%snew mode %06o%s\n", set, two->mode, reset);
+                       strbuf_addf(&header, "%s%sold mode %06o%s\n", line_prefix, set, one->mode, reset);
+                       strbuf_addf(&header, "%s%snew mode %06o%s\n", line_prefix, set, two->mode, reset);
                }
 -              if (xfrm_msg && xfrm_msg[0])
 -                      strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset);
 +              if (xfrm_msg)
 +                      strbuf_addstr(&header, xfrm_msg);
  
                /*
                 * we do not run diff between different kind
                ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
                if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
                        check_blank_at_eof(&mf1, &mf2, &ecbdata);
-               ecbdata.file = o->file;
+               ecbdata.opt = o;
                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;
@@@ -2384,36 -2562,38 +2567,47 @@@ static void fill_metainfo(struct strbu
                          struct diff_filespec *one,
                          struct diff_filespec *two,
                          struct diff_options *o,
 -                        struct diff_filepair *p)
 +                        struct diff_filepair *p,
 +                        int use_color)
  {
 +      const char *set = diff_get_color(use_color, DIFF_METAINFO);
 +      const char *reset = diff_get_color(use_color, DIFF_RESET);
+       struct strbuf *msgbuf;
+       char *line_prefix = "";
+       if (o->output_prefix) {
+               msgbuf = o->output_prefix(o, o->output_prefix_data);
+               line_prefix = msgbuf->buf;
+       }
  
        strbuf_init(msg, PATH_MAX * 2 + 300);
        switch (p->status) {
        case DIFF_STATUS_COPIED:
-               strbuf_addf(msg, "%ssimilarity index %d%%",
-                           set, similarity_index(p));
-               strbuf_addf(msg, "%s\n%scopy from ", reset, set);
 -              strbuf_addf(msg, "%ssimilarity index %d%%", line_prefix, similarity_index(p));
 -              strbuf_addf(msg, "\n%scopy from ", line_prefix);
++              strbuf_addf(msg, "%s%ssimilarity index %d%%",
++                          line_prefix, set, similarity_index(p));
++              strbuf_addf(msg, "%s\n%s%scopy from ",
++                          reset,  line_prefix, set);
                quote_c_style(name, msg, NULL, 0);
-               strbuf_addf(msg, "%s\n%scopy to ", reset, set);
 -              strbuf_addf(msg, "\n%scopy to ", line_prefix);
++              strbuf_addf(msg, "%s\n%s%scopy to ", reset, line_prefix, set);
                quote_c_style(other, msg, NULL, 0);
 -              strbuf_addch(msg, '\n');
 +              strbuf_addf(msg, "%s\n", reset);
                break;
        case DIFF_STATUS_RENAMED:
-               strbuf_addf(msg, "%ssimilarity index %d%%",
-                           set, similarity_index(p));
-               strbuf_addf(msg, "%s\n%srename from ", reset, set);
 -              strbuf_addf(msg, "%ssimilarity index %d%%", line_prefix, similarity_index(p));
 -              strbuf_addf(msg, "\n%srename from ", line_prefix);
++              strbuf_addf(msg, "%s%ssimilarity index %d%%",
++                          line_prefix, set, similarity_index(p));
++              strbuf_addf(msg, "%s\n%s%srename from ",
++                          reset, line_prefix, set);
                quote_c_style(name, msg, NULL, 0);
-               strbuf_addf(msg, "%s\n%srename to ", reset, set);
 -              strbuf_addf(msg, "\n%srename to ", line_prefix);
++              strbuf_addf(msg, "%s\n%s%srename to ",
++                          reset, line_prefix, set);
                quote_c_style(other, msg, NULL, 0);
 -              strbuf_addch(msg, '\n');
 +              strbuf_addf(msg, "%s\n", reset);
                break;
        case DIFF_STATUS_MODIFIED:
                if (p->score) {
-                       strbuf_addf(msg, "%sdissimilarity index %d%%%s\n",
 -                      strbuf_addf(msg, "%sdissimilarity index %d%%\n",
 -                                  line_prefix, similarity_index(p));
++                      strbuf_addf(msg, "%s%sdissimilarity index %d%%%s\n",
++                                  line_prefix,
 +                                  set, similarity_index(p), reset);
                        break;
                }
                /* fallthru */
                            (!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
                                abbrev = 40;
                }
-               strbuf_addf(msg, "%sindex %s..", set,
 -              strbuf_addf(msg, "%sindex %.*s..%.*s",
 -                          line_prefix, abbrev, sha1_to_hex(one->sha1),
 -                          abbrev, sha1_to_hex(two->sha1));
++              strbuf_addf(msg, "%s%sindex %s..", set,
++                          line_prefix,
 +                          find_unique_abbrev(one->sha1, abbrev));
 +              strbuf_addstr(msg, find_unique_abbrev(two->sha1, abbrev));
                if (one->mode == two->mode)
                        strbuf_addf(msg, " %06o", one->mode);
 -              strbuf_addch(msg, '\n');
 +              strbuf_addf(msg, "%s\n", reset);
        }
 -      if (msg->len)
 -              strbuf_setlen(msg, msg->len - 1);
  }
  
  static void run_diff_cmd(const char *pgm,