Skip to content

Commit

Permalink
vim-patch:9.1.0743: diff mode does not handle overlapping diffs corre…
Browse files Browse the repository at this point in the history
…ctly (neovim#30532)

Problem:  diff mode does not handle overlapping diffs correctly
Solution: correct the logic to handle overlapping blocks
          (Yukihiro Nakadaira)

Vim merges overlapped diff blocks and it doesn't work expectedly
in some situation.

closes: vim/vim#15735

vim/vim@06fe70c

Co-authored-by: Yukihiro Nakadaira <[email protected]>
  • Loading branch information
zeertzjq and ynkdir authored Sep 27, 2024
1 parent a9287dd commit 6f2fe8a
Show file tree
Hide file tree
Showing 3 changed files with 751 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/nvim/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,7 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne
for (int i = idx_orig; i < idx_new; i++) {
if (curtab->tp_diffbuf[i] != NULL) {
dp->df_lnum[i] -= off;
dp->df_count[i] += off;
}
}
dp->df_lnum[idx_new] = hunk->lnum_new;
Expand All @@ -1619,11 +1620,7 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne
dp->df_count[idx_new] = (linenr_T)hunk->count_new - off;
} else {
// second overlap of new block with existing block
dp->df_count[idx_new] += (linenr_T)hunk->count_new - (linenr_T)hunk->count_orig
+ dpl->df_lnum[idx_orig] +
dpl->df_count[idx_orig]
- (dp->df_lnum[idx_orig] +
dp->df_count[idx_orig]);
dp->df_count[idx_new] += (linenr_T)hunk->count_new;
}

// Adjust the size of the block to include all the lines to the
Expand All @@ -1632,11 +1629,8 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne
- (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]);

if (off < 0) {
// new change ends in existing block, adjust the end if not
// done already
if (*notsetp) {
dp->df_count[idx_new] += -off;
}
// new change ends in existing block, adjust the end
dp->df_count[idx_new] += -off;
off = 0;
}

Expand Down
Loading

0 comments on commit 6f2fe8a

Please sign in to comment.