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>
Junio C Hamano committed
Feb 6, 2006 at 18:54 UTC
4462731e0597c31c68466601a5d74b2edb145d6d
1 file changed
+14
-10
combine-diff.c
+14
-10
@@ -8,8 +8,6 @@ static int uninteresting(struct diff_filepair *p)
8
{
9
if (diff_unmodified_pair(p))
10
return 1;
11
- if (!S_ISREG(p->one->mode) || !S_ISREG(p->two->mode))
12
- return 1;
11
return 0;
12
}
13
@@ -226,6 +224,9 @@ static void combine_diff(const unsigned char *parent, const char *ourtmp,
224
unsigned long nmask = (1UL << n);
225
struct sline *lost_bucket = NULL;
226
227
+ if (!cnt)
228
+ return; /* result deleted */
229
+
230
write_temp_blob(parent_tmp, parent);
231
sprintf(cmd, "diff --unified=0 -La/x -Lb/x '%s' '%s'",
232
parent_tmp, ourtmp);
@@ -542,6 +543,9 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
543
int i;
544
unsigned long lno = 0;
545
546
+ if (!cnt)
547
+ return; /* result deleted */
548
+
549
while (1) {
550
struct sline *sl = &sline[lno];
551
int hunk_end;
@@ -610,6 +614,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
614
sline->flag |= imask;
615
sline++;
616
}
617
+ /* the overall size of the file (sline[cnt]) */
618
+ sline->p_lno[i] = sline->p_lno[j];
619
}
620
621
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,
671
if (*cp == '\n')
672
cnt++;
673
}
668
- if (result[size-1] != '\n')
674
+ if (size && result[size-1] != '\n')
675
cnt++; /* incomplete line */
676
677
sline = xcalloc(cnt+1, sizeof(*sline));
678
ep = result;
679
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
+ }
684
for (lno = 0, cp = result; cp - result < size; cp++) {
685
if (*cp == '\n') {
676
- sline[lno].lost_tail = &sline[lno].lost_head;
686
sline[lno].len = cp - sline[lno].bol;
678
- sline[lno].flag = 0;
687
lno++;
688
if (lno < cnt)
689
sline[lno].bol = cp + 1;
690
}
691
}
684
- if (result[size-1] != '\n') {
685
- sline[cnt-1].lost_tail = &sline[cnt-1].lost_head;
692
+ if (size && result[size-1] != '\n')
693
sline[cnt-1].len = size - (sline[cnt-1].bol - result);
687
- sline[cnt-1].flag = 0;
688
- }
694
695
sline[0].p_lno = xcalloc((cnt+1) * num_parent, sizeof(unsigned long));
696
for (lno = 0; lno < cnt; lno++)
@@ -750,7 +755,6 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
755
}
756
printf("..%06o\n", elem->mode);
757
}
753
- /* if (show_hunks) perhaps */
758
dump_sline(sline, cnt, num_parent);
759
}
760
if (ourtmp == ourtmp_buf)