Replace all read_fd use with strbuf_read, and get rid of it.
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index c054b234b877952501dcf05b2ea312ae77441042..7290309ea9c01a6800aaa25d7a74d789adfd31c7 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1548,8 +1548,8 @@ static int populate_from_stdin(struct diff_filespec *s)
 {
        struct strbuf buf;
 
-       strbuf_init(&buf);
-       if (strbuf_read(&buf, 0) < 0)
+       strbuf_init(&buf, 0);
+       if (strbuf_read(&buf, 0, 0) < 0)
                return error("error while reading from stdin %s",
                                     strerror(errno));
 
@@ -3135,6 +3135,22 @@ static void diffcore_apply_filter(const char *filter)
        *q = outq;
 }
 
+/* Check whether two filespecs with the same mode and size are identical */
+static int diff_filespec_is_identical(struct diff_filespec *one,
+                                     struct diff_filespec *two)
+{
+       if (S_ISGITLINK(one->mode)) {
+               diff_fill_sha1_info(one);
+               diff_fill_sha1_info(two);
+               return !hashcmp(one->sha1, two->sha1);
+       }
+       if (diff_populate_filespec(one, 0))
+               return 0;
+       if (diff_populate_filespec(two, 0))
+               return 0;
+       return !memcmp(one->data, two->data, one->size);
+}
+
 static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
 {
        int i;
@@ -3166,10 +3182,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
                    diff_populate_filespec(p->one, 1) ||
                    diff_populate_filespec(p->two, 1) ||
                    (p->one->size != p->two->size) ||
-
-                   diff_populate_filespec(p->one, 0) || /* (2) */
-                   diff_populate_filespec(p->two, 0) ||
-                   memcmp(p->one->data, p->two->data, p->one->size))
+                   !diff_filespec_is_identical(p->one, p->two)) /* (2) */
                        diff_q(&outq, p);
                else {
                        /*