diff.c: move diffcore_skip_stat_unmatch core logic out for reuse later
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jan 25, 2014 at 13:46 UTC
fceb907225745b91aa8b9e0ef2ea068b0351ea01
1 file changed
+28
-21
diff.c
+28
-21
@@ -4592,6 +4592,33 @@ static int diff_filespec_is_identical(struct diff_filespec *one,
4592
return !memcmp(one->data, two->data, one->size);
4593
}
4594
4595
+static int diff_filespec_check_stat_unmatch(struct diff_filepair *p)
4596
+{
4597
+ /*
4598
+ * 1. Entries that come from stat info dirtiness
4599
+ * always have both sides (iow, not create/delete),
4600
+ * one side of the object name is unknown, with
4601
+ * the same mode and size. Keep the ones that
4602
+ * do not match these criteria. They have real
4603
+ * differences.
4604
+ *
4605
+ * 2. At this point, the file is known to be modified,
4606
+ * with the same mode and size, and the object
4607
+ * name of one side is unknown. Need to inspect
4608
+ * the identical contents.
4609
+ */
4610
+ if (!DIFF_FILE_VALID(p->one) || /* (1) */
4611
+ !DIFF_FILE_VALID(p->two) ||
4612
+ (p->one->sha1_valid && p->two->sha1_valid) ||
4613
+ (p->one->mode != p->two->mode) ||
4614
+ diff_populate_filespec(p->one, 1) ||
4615
+ diff_populate_filespec(p->two, 1) ||
4616
+ (p->one->size != p->two->size) ||
4617
+ !diff_filespec_is_identical(p->one, p->two)) /* (2) */
4618
+ return 1;
4619
+ return 0;
4620
+}
4621
+
4622
static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
4623
{
4624
int i;
@@ -4602,27 +4629,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
4629
for (i = 0; i < q->nr; i++) {
4630
struct diff_filepair *p = q->queue[i];
4631
4605
- /*
4606
- * 1. Entries that come from stat info dirtiness
4607
- * always have both sides (iow, not create/delete),
4608
- * one side of the object name is unknown, with
4609
- * the same mode and size. Keep the ones that
4610
- * do not match these criteria. They have real
4611
- * differences.
4612
- *
4613
- * 2. At this point, the file is known to be modified,
4614
- * with the same mode and size, and the object
4615
- * name of one side is unknown. Need to inspect
4616
- * the identical contents.
4617
- */
4618
- if (!DIFF_FILE_VALID(p->one) || /* (1) */
4619
- !DIFF_FILE_VALID(p->two) ||
4620
- (p->one->sha1_valid && p->two->sha1_valid) ||
4621
- (p->one->mode != p->two->mode) ||
4622
- diff_populate_filespec(p->one, 1) ||
4623
- diff_populate_filespec(p->two, 1) ||
4624
- (p->one->size != p->two->size) ||
4625
- !diff_filespec_is_identical(p->one, p->two)) /* (2) */
4632
+ if (diff_filespec_check_stat_unmatch(p))
4633
diff_q(&outq, p);
4634
else {
4635
/*