diff options
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r-- | src/nvim/diff.c | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 1d70145209..5c43b2498e 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -73,21 +73,21 @@ static TriState diff_a_works = kNone; // used for diff input typedef struct { char_u *din_fname; // used for external diff - mmfile_t din_mmfile; // used for internal diff + mmfile_t din_mmfile; // used for internal diff } diffin_T; // used for diff result typedef struct { char_u *dout_fname; // used for external diff - garray_T dout_ga; // used for internal diff + garray_T dout_ga; // used for internal diff } diffout_T; // two diff inputs and one result typedef struct { - diffin_T dio_orig; // original file input - diffin_T dio_new; // new file input - diffout_T dio_diff; // diff result - int dio_internal; // using internal diff + diffin_T dio_orig; // original file input + diffin_T dio_new; // new file input + diffout_T dio_diff; // diff result + int dio_internal; // using internal diff } diffio_T; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -702,9 +702,9 @@ static void clear_diffout(diffout_T *dout) /// @return FAIL for failure. static int diff_write_buffer(buf_T *buf, diffin_T *din) { - linenr_T lnum; + linenr_T lnum; char_u *s; - long len = 0; + long len = 0; char_u *ptr; // xdiff requires one big block of memory with all the text. @@ -732,7 +732,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { for (s = ml_get_buf(buf, lnum, false); *s != NUL; ) { if (diff_flags & DIFF_ICASE) { - char_u cbuf[MB_MAXBYTES + 1]; + char_u cbuf[MB_MAXBYTES + 1]; // xdiff doesn't support ignoring case, fold-case the text. int c = PTR2CHAR(s); @@ -787,10 +787,10 @@ static int diff_write(buf_T *buf, diffin_T *din) /// @param dio /// @param idx_orig /// @param eap can be NULL -static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap) +static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap) { buf_T *buf; - int idx_new; + int idx_new; if (dio->dio_internal) { ga_init(&dio->dio_diff.dout_ga, sizeof(char *), 1000); @@ -928,7 +928,7 @@ void ex_diffupdate(exarg_T *eap) } // Only use the internal method if it did not fail for one of the buffers. - diffio_T diffio; + diffio_T diffio; memset(&diffio, 0, sizeof(diffio)); diffio.dio_internal = diff_internal() && !diff_internal_failed(); @@ -1044,9 +1044,9 @@ static int check_external_diff(diffio_T *diffio) /// static int diff_file_internal(diffio_T *diffio) { - xpparam_t param; - xdemitconf_t emit_cfg; - xdemitcb_t emit_cb; + xpparam_t param; + xdemitconf_t emit_cfg; + xdemitcb_t emit_cb; memset(¶m, 0, sizeof(param)); memset(&emit_cfg, 0, sizeof(emit_cfg)); @@ -1985,26 +1985,6 @@ static int diff_cmp(char_u *s1, char_u *s2) return 0; } -/// Return the number of filler lines above "lnum". -/// -/// @param wp -/// @param lnum -/// -/// @return Number of filler lines above lnum -int diff_check_fill(win_T *wp, linenr_T lnum) -{ - // be quick when there are no filler lines - if (!(diff_flags & DIFF_FILLER)) { - return 0; - } - int n = diff_check(wp, lnum); - - if (n <= 0) { - return 0; - } - return n; -} - /// Set the topline of "towin" to match the position in "fromwin", so that they /// show the same diff'ed lines. /// @@ -2030,6 +2010,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin) } towin->w_topfill = 0; + // search for a change that includes "lnum" in the list of diffblocks. for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) { @@ -2255,6 +2236,13 @@ bool diffopt_closeoff(void) return (diff_flags & DIFF_CLOSE_OFF) != 0; } +// Return true if 'diffopt' contains "filler". +bool diffopt_filler(void) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + return (diff_flags & DIFF_FILLER) != 0; +} + /// Find the difference within a changed line. /// /// @param wp window whose current buffer to check @@ -3033,8 +3021,8 @@ static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, li long *count_new) { char_u *p; - long f1, l1, f2, l2; - int difftype; + long f1, l1, f2, l2; + int difftype; // The line must be one of three formats: // change: {first}[,{last}]c{first}[,{last}] @@ -3088,7 +3076,7 @@ static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_ori linenr_T *lnum_new, long *count_new) { char_u *p; - long oldline, oldcount, newline, newcount; + long oldline, oldcount, newline, newcount; // Parse unified diff hunk header: // @@ -oldline,oldcount +newline,newcount @@ |