Skip to content

Commit fab01ec

Browse files
phillipwoodgitster
authored andcommitted
diff: fix --color-moved-ws=allow-indentation-change
If there is more than one potential moved block and the longest block is not the first element of the array of potential blocks then the block is cut short. With --color-moved=blocks this can leave moved lines unpainted if the shortened block does not meet the block length requirement. With --color-moved=zebra then in addition to the unpainted lines the moved color can change in the middle of a single block. Fix this by freeing the whitespace delta of the match we're discarding rather than the one we're keeping. Signed-off-by: Phillip Wood <[email protected]> Acked-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 626c0b5 commit fab01ec

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

diff.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,13 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
955955
/* Carry the white space delta forward */
956956
pmb[i]->next_line->wsd = pmb[i]->wsd;
957957
pmb[i] = pmb[i]->next_line;
958-
} else
958+
} else {
959+
if (pmb[i]->wsd) {
960+
free(pmb[i]->wsd->string);
961+
FREE_AND_NULL(pmb[i]->wsd);
962+
}
959963
pmb[i] = NULL;
964+
}
960965
}
961966
}
962967

@@ -977,10 +982,6 @@ static int shrink_potential_moved_blocks(struct moved_entry **pmb,
977982

978983
if (lp < pmb_nr && rp > -1 && lp < rp) {
979984
pmb[lp] = pmb[rp];
980-
if (pmb[rp]->wsd) {
981-
free(pmb[rp]->wsd->string);
982-
FREE_AND_NULL(pmb[rp]->wsd);
983-
}
984985
pmb[rp] = NULL;
985986
rp--;
986987
lp++;

0 commit comments

Comments
 (0)