Skip to content

Commit

Permalink
diff -c/--cc: do not include uninteresting deletion before leading co…
Browse files Browse the repository at this point in the history
…ntext

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>
  • Loading branch information
Junio C Hamano committed Jun 19, 2008
1 parent 4afbcab commit c86fbe5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct sline {
/* bit 0 up to (N-1) are on if the parent has this line (i.e.
* we did not change it).
* bit N is used for "interesting" lines, including context.
* bit (N+1) is used for "do not show deletion before this".
*/
unsigned long flag;
unsigned long *p_lno;
Expand Down Expand Up @@ -308,6 +309,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
{
unsigned long all_mask = (1UL<<num_parent) - 1;
unsigned long mark = (1UL<<num_parent);
unsigned long no_pre_delete = (2UL<<num_parent);
unsigned long i;

/* Two groups of interesting lines may have a short gap of
Expand All @@ -329,7 +331,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)

/* Paint a few lines before the first interesting line. */
while (j < i)
sline[j++].flag |= mark;
sline[j++].flag |= mark | no_pre_delete;

again:
/* we know up to i is to be included. where does the
Expand Down Expand Up @@ -502,6 +504,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
int use_color)
{
unsigned long mark = (1UL<<num_parent);
unsigned long no_pre_delete = (2UL<<num_parent);
int i;
unsigned long lno = 0;
const char *c_frag = diff_get_color(use_color, DIFF_FRAGINFO);
Expand Down Expand Up @@ -581,7 +584,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
int j;
unsigned long p_mask;
sl = &sline[lno++];
ll = sl->lost_head;
ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
while (ll) {
fputs(c_old, stdout);
for (j = 0; j < num_parent; j++) {
Expand Down

0 comments on commit c86fbe5

Please sign in to comment.