Skip to content

Commit 4462731

Browse files
author
Junio C Hamano
committed
combine-diff: do not punt on removed or added files.
When we remove a file, the parents' contents are all removed so it is not that interesting to show all of them, but the fact it was removed when all parents had it *is* unusual. When we add a file, similarly the fact it was added when no parent wanted it *is* unusual, and in addition the result matters, so show it. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 2454c96 commit 4462731

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

combine-diff.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ static int uninteresting(struct diff_filepair *p)
88
{
99
if (diff_unmodified_pair(p))
1010
return 1;
11-
if (!S_ISREG(p->one->mode) || !S_ISREG(p->two->mode))
12-
return 1;
1311
return 0;
1412
}
1513

@@ -226,6 +224,9 @@ static void combine_diff(const unsigned char *parent, const char *ourtmp,
226224
unsigned long nmask = (1UL << n);
227225
struct sline *lost_bucket = NULL;
228226

227+
if (!cnt)
228+
return; /* result deleted */
229+
229230
write_temp_blob(parent_tmp, parent);
230231
sprintf(cmd, "diff --unified=0 -La/x -Lb/x '%s' '%s'",
231232
parent_tmp, ourtmp);
@@ -542,6 +543,9 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
542543
int i;
543544
unsigned long lno = 0;
544545

546+
if (!cnt)
547+
return; /* result deleted */
548+
545549
while (1) {
546550
struct sline *sl = &sline[lno];
547551
int hunk_end;
@@ -610,6 +614,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
610614
sline->flag |= imask;
611615
sline++;
612616
}
617+
/* the overall size of the file (sline[cnt]) */
618+
sline->p_lno[i] = sline->p_lno[j];
613619
}
614620

615621
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
@@ -665,27 +671,26 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
665671
if (*cp == '\n')
666672
cnt++;
667673
}
668-
if (result[size-1] != '\n')
674+
if (size && result[size-1] != '\n')
669675
cnt++; /* incomplete line */
670676

671677
sline = xcalloc(cnt+1, sizeof(*sline));
672678
ep = result;
673679
sline[0].bol = result;
680+
for (lno = 0; lno <= cnt; lno++) {
681+
sline[lno].lost_tail = &sline[lno].lost_head;
682+
sline[lno].flag = 0;
683+
}
674684
for (lno = 0, cp = result; cp - result < size; cp++) {
675685
if (*cp == '\n') {
676-
sline[lno].lost_tail = &sline[lno].lost_head;
677686
sline[lno].len = cp - sline[lno].bol;
678-
sline[lno].flag = 0;
679687
lno++;
680688
if (lno < cnt)
681689
sline[lno].bol = cp + 1;
682690
}
683691
}
684-
if (result[size-1] != '\n') {
685-
sline[cnt-1].lost_tail = &sline[cnt-1].lost_head;
692+
if (size && result[size-1] != '\n')
686693
sline[cnt-1].len = size - (sline[cnt-1].bol - result);
687-
sline[cnt-1].flag = 0;
688-
}
689694

690695
sline[0].p_lno = xcalloc((cnt+1) * num_parent, sizeof(unsigned long));
691696
for (lno = 0; lno < cnt; lno++)
@@ -750,7 +755,6 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
750755
}
751756
printf("..%06o\n", elem->mode);
752757
}
753-
/* if (show_hunks) perhaps */
754758
dump_sline(sline, cnt, num_parent);
755759
}
756760
if (ourtmp == ourtmp_buf)

0 commit comments

Comments
 (0)