diff options
author | Christian Couder <chriscool@tuxfamily.org> | 2010-05-26 04:50:12 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-06-06 15:14:27 -0700 |
commit | 296c6bb21a6980f6e5b42f0790d6365c1e3f696f (patch) | |
tree | ee5833c88e3945984a5e87f5c428c5571c0efc8c /diff.c | |
parent | remove ecb parameter from xdi_diff_outf() (diff) | |
download | tgif-296c6bb21a6980f6e5b42f0790d6365c1e3f696f.tar.xz |
diff: fix "git show -C -C" output when renaming a binary file
A bug was introduced in 3e97c7c6af2901cec63bf35fcd43ae3472e24af8
(No diff -b/-w output for all-whitespace changes, Nov 19 2009)
that made the lines:
diff --git a/bar b/sub/bar
similarity index 100%
rename from bar
rename to sub/bar
disappear from "git show -C -C" output when file bar is a binary
file.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -1596,6 +1596,7 @@ static void builtin_diff(const char *name_a, struct diff_filespec *one, struct diff_filespec *two, const char *xfrm_msg, + int must_show_header, struct diff_options *o, int complete_rewrite) { @@ -1647,16 +1648,19 @@ static void builtin_diff(const char *name_a, strbuf_addf(&header, "%snew file mode %06o%s\n", set, two->mode, reset); if (xfrm_msg && xfrm_msg[0]) strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset); + must_show_header = 1; } else if (lbl[1][0] == '/') { strbuf_addf(&header, "%sdeleted file mode %06o%s\n", set, one->mode, reset); if (xfrm_msg && xfrm_msg[0]) strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset); + must_show_header = 1; } 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); + must_show_header = 1; } if (xfrm_msg && xfrm_msg[0]) strbuf_addf(&header, "%s%s%s\n", set, xfrm_msg, reset); @@ -1687,8 +1691,11 @@ static void builtin_diff(const char *name_a, (diff_filespec_is_binary(two) && !textconv_two) )) { /* Quite common confusing case */ if (mf1.size == mf2.size && - !memcmp(mf1.ptr, mf2.ptr, mf1.size)) + !memcmp(mf1.ptr, mf2.ptr, mf1.size)) { + if (must_show_header) + fprintf(o->file, "%s", header.buf); goto free_ab_and_return; + } fprintf(o->file, "%s", header.buf); strbuf_reset(&header); if (DIFF_OPT_TST(o, BINARY)) @@ -1706,7 +1713,7 @@ static void builtin_diff(const char *name_a, struct emit_callback ecbdata; const struct userdiff_funcname *pe; - if (!DIFF_XDL_TST(o, WHITESPACE_FLAGS)) { + if (!DIFF_XDL_TST(o, WHITESPACE_FLAGS) || must_show_header) { fprintf(o->file, "%s", header.buf); strbuf_reset(&header); } @@ -2315,8 +2322,10 @@ static void fill_metainfo(struct strbuf *msg, struct diff_filespec *one, struct diff_filespec *two, struct diff_options *o, - struct diff_filepair *p) + struct diff_filepair *p, + int *must_show_header) { + *must_show_header = 1; strbuf_init(msg, PATH_MAX * 2 + 300); switch (p->status) { case DIFF_STATUS_COPIED: @@ -2344,7 +2353,7 @@ static void fill_metainfo(struct strbuf *msg, /* fallthru */ default: /* nothing */ - ; + *must_show_header = 0; } if (one && two && hashcmp(one->sha1, two->sha1)) { int abbrev = DIFF_OPT_TST(o, FULL_INDEX) ? 40 : DEFAULT_ABBREV; @@ -2378,9 +2387,10 @@ static void run_diff_cmd(const char *pgm, { const char *xfrm_msg = NULL; int complete_rewrite = (p->status == DIFF_STATUS_MODIFIED) && p->score; + int must_show_header = 0; if (msg) { - fill_metainfo(msg, name, other, one, two, o, p); + fill_metainfo(msg, name, other, one, two, o, p, &must_show_header); xfrm_msg = msg->len ? msg->buf : NULL; } @@ -2399,7 +2409,8 @@ static void run_diff_cmd(const char *pgm, } if (one && two) builtin_diff(name, other ? other : name, - one, two, xfrm_msg, o, complete_rewrite); + one, two, xfrm_msg, must_show_header, + o, complete_rewrite); else fprintf(o->file, "* Unmerged path %s\n", name); } |