From: Junio C Hamano Date: Fri, 18 Jun 2010 18:16:57 +0000 (-0700) Subject: Merge branch 'by/diff-graph' X-Git-Tag: v1.7.2-rc0~44 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=98ad90fbab90a423ca835956d3121c60db2eb218;p=git.git Merge branch 'by/diff-graph' * 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 --- 98ad90fbab90a423ca835956d3121c60db2eb218 diff --cc diff.c index b53b6ec8e,974b6a997..c6b5fb376 --- a/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 @@@ -1792,9 -1970,9 +1975,9 @@@ 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 */ @@@ -2430,13 -2610,15 +2624,14 @@@ (!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,