diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-08-16 10:08:06 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-08-18 10:16:55 -0700 |
commit | 1aaf69e669b7fd67073d3024b386ac25ac77d0f8 (patch) | |
tree | 35d49af45158e859a9918eac1957965af800f5c7 /diff.c | |
parent | 6bf3b813486b4528feca39d599c256f662defc14 (diff) | |
download | git-1aaf69e669b7fd67073d3024b386ac25ac77d0f8.tar.gz |
diff: shortcut for diff'ing two binary SHA-1 objectsnd/large-blobs
If we are given two SHA-1 and asked to determine if they are different
(but not _what_ differences), we know right away by comparing SHA-1.
A side effect of this patch is, because large files are marked binary,
diff-tree will not need to unpack them. 'diff-index --cached' will not
either. But 'diff-files' still does.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -2324,6 +2324,19 @@ static void builtin_diff(const char *name_a, } else if (!DIFF_OPT_TST(o, TEXT) && ( (!textconv_one && diff_filespec_is_binary(one)) || (!textconv_two && diff_filespec_is_binary(two)) )) { + if (!one->data && !two->data && + S_ISREG(one->mode) && S_ISREG(two->mode) && + !DIFF_OPT_TST(o, BINARY)) { + if (!hashcmp(one->sha1, two->sha1)) { + if (must_show_header) + fprintf(o->file, "%s", header.buf); + goto free_ab_and_return; + } + fprintf(o->file, "%s", header.buf); + fprintf(o->file, "%sBinary files %s and %s differ\n", + line_prefix, lbl[0], lbl[1]); + goto free_ab_and_return; + } if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) die("unable to read files to diff"); /* Quite common confusing case */ |