@matheusbsbs / matheus-bagliano / commits / c86fbe5332
Fork 0

diff -c/--cc: do not include uninteresting deletion before leading context

When we include a few uninteresting lines before the interesting ones as context, we are only interested in seeing the surviving lines themselves and not the deleted lines that are before them. Mark the added leading context lines in give_context() and not show deleted lines form them. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 18, 2008 at 23:59 UTC c86fbe5332abe6b951731940b9a8676ea90a434c
1 file changed +5 -2
combine-diff.c
+5 -2
@@ -84,6 +84,7 @@ struct sline {
84 /* bit 0 up to (N-1) are on if the parent has this line (i.e.
85 * we did not change it).
86 * bit N is used for "interesting" lines, including context.
87 + * bit (N+1) is used for "do not show deletion before this".
88 */
89 unsigned long flag;
90 unsigned long *p_lno;
@@ -308,6 +309,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
309 {
310 unsigned long all_mask = (1UL<<num_parent) - 1;
311 unsigned long mark = (1UL<<num_parent);
312 + unsigned long no_pre_delete = (2UL<<num_parent);
313 unsigned long i;
314
315 /* Two groups of interesting lines may have a short gap of
@@ -329,7 +331,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
331
332 /* Paint a few lines before the first interesting line. */
333 while (j < i)
332 - sline[j++].flag |= mark;
334 + sline[j++].flag |= mark | no_pre_delete;
335
336 again:
337 /* we know up to i is to be included. where does the
@@ -502,6 +504,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
504 int use_color)
505 {
506 unsigned long mark = (1UL<<num_parent);
507 + unsigned long no_pre_delete = (2UL<<num_parent);
508 int i;
509 unsigned long lno = 0;
510 const char *c_frag = diff_get_color(use_color, DIFF_FRAGINFO);
@@ -581,7 +584,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
584 int j;
585 unsigned long p_mask;
586 sl = &sline[lno++];
584 - ll = sl->lost_head;
587 + ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
588 while (ll) {
589 fputs(c_old, stdout);
590 for (j = 0; j < num_parent; j++) {