diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2021-12-09 11:29:58 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-12-09 22:24:05 +0100 |
commit | 0990658bf85a0763ffd628b1dd57a33c27b25450 (patch) | |
tree | 5ef406a84590430fcea17443f08b67a0428f36fa /diff.c | |
parent | diff --color-moved: factor out function (diff) | |
download | git-0990658bf85a0763ffd628b1dd57a33c27b25450.tar.xz git-0990658bf85a0763ffd628b1dd57a33c27b25450.zip |
diff --color-moved: rewind when discarding pmb
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -1205,7 +1205,15 @@ static void mark_color_as_moved(struct diff_options *o, if (!match) { int i; - adjust_last_block(o, n, block_length); + if (!adjust_last_block(o, n, block_length) && + block_length > 1) { + /* + * Rewind in case there is another match + * starting at the second line of the block + */ + match = NULL; + n -= block_length; + } for(i = 0; i < pmb_nr; i++) moved_block_clear(&pmb[i]); pmb_nr = 0; @@ -1230,10 +1238,20 @@ static void mark_color_as_moved(struct diff_options *o, pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr); if (pmb_nr == 0) { - fill_potential_moved_blocks( - o, hm, match, l, &pmb, &pmb_alloc, &pmb_nr); - if (adjust_last_block(o, n, block_length) && - pmb_nr && last_symbol != l->s) + int contiguous = adjust_last_block(o, n, block_length); + + if (!contiguous && block_length > 1) + /* + * Rewind in case there is another match + * starting at the second line of the block + */ + n -= block_length; + else + fill_potential_moved_blocks(o, hm, match, l, + &pmb, &pmb_alloc, + &pmb_nr); + + if (contiguous && pmb_nr && last_symbol != l->s) flipped_block = (flipped_block + 1) % 2; else flipped_block = 0; |