@matheusbsbs / matheus-bagliano / commits / 3b0f5e88ee
Fork 0

combine-diff: special case --unified=0

Even when --unified=0 is given, the main loop to show the combined textual diff needs to handle a line that is unchanged but has lines that were deleted relative to a parent before it (because that is where the lost lines hang). However, such a line should not be emitted in the final output. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 3, 2007 at 12:37 UTC 3b0f5e88ee039e96822d7d0127a59d78936c222f
1 file changed +30 -4
combine-diff.c
+30 -4
@@ -482,11 +482,11 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
482 return has_interesting;
483 }
484
485 -static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n)
485 +static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n, unsigned long null_context)
486 {
487 l0 = sline[l0].p_lno[n];
488 l1 = sline[l1].p_lno[n];
489 - printf(" -%lu,%lu", l0, l1-l0);
489 + printf(" -%lu,%lu", l0, l1-l0-null_context);
490 }
491
492 static int hunk_comment_line(const char *bol)
@@ -519,6 +519,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
519 unsigned long hunk_end;
520 unsigned long rlines;
521 const char *hunk_comment = NULL;
522 + unsigned long null_context = 0;
523
524 while (lno <= cnt && !(sline[lno].flag & mark)) {
525 if (hunk_comment_line(sline[lno].bol))
@@ -535,10 +536,28 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
536 rlines = hunk_end - lno;
537 if (cnt < hunk_end)
538 rlines--; /* pointing at the last delete hunk */
539 +
540 + if (!context) {
541 + /*
542 + * Even when running with --unified=0, all
543 + * lines in the hunk needs to be processed in
544 + * the loop below in order to show the
545 + * deletion recorded in lost_head. However,
546 + * we do not want to show the resulting line
547 + * with all blank context markers in such a
548 + * case. Compensate.
549 + */
550 + unsigned long j;
551 + for (j = lno; j < hunk_end; j++)
552 + if (!(sline[j].flag & (mark-1)))
553 + null_context++;
554 + rlines -= null_context;
555 + }
556 +
557 fputs(c_frag, stdout);
558 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
559 for (i = 0; i < num_parent; i++)
541 - show_parent_lno(sline, lno, hunk_end, i);
560 + show_parent_lno(sline, lno, hunk_end, i, null_context);
561 printf(" +%lu,%lu ", lno+1, rlines);
562 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
563
@@ -578,8 +597,15 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
597 if (cnt < lno)
598 break;
599 p_mask = 1;
581 - if (!(sl->flag & (mark-1)))
600 + if (!(sl->flag & (mark-1))) {
601 + /*
602 + * This sline was here to hang the
603 + * lost lines in front of it.
604 + */
605 + if (!context)
606 + continue;
607 fputs(c_plain, stdout);
608 + }
609 else
610 fputs(c_new, stdout);
611 for (j = 0; j < num_parent; j++) {