From: Yee Cheng Chin Date: Tue, 18 Nov 2025 00:26:15 +0000 (-0800) Subject: Merge branch 'xdiff-new' into xdiff-upstream-v2.52.0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d353c6f2c8;p=thirdparty%2Fvim.git Merge branch 'xdiff-new' into xdiff-upstream-v2.52.0 --- d353c6f2c8524baef72c48a50c08cffcc4581b75 diff --cc src/xdiff/xdiff.h index a9169d30ce,2cecde5afe..1f8681b456 --- a/src/xdiff/xdiff.h +++ b/src/xdiff/xdiff.h @@@ -82,12 -82,10 +82,12 @@@ typedef struct s_xpparam unsigned long flags; /* -I */ + #if 0 // unused by Vim regex_t **ignore_regex; size_t ignore_regex_nr; +#endif - /* See Documentation/diff-options.txt. */ + /* See Documentation/diff-options.adoc. */ char **anchors; size_t anchors_nr; } xpparam_t; diff --cc src/xdiff/xdiffi.c index 5a6f0cdcd3,6f3998ee54..fe6b5cda6f --- a/src/xdiff/xdiffi.c +++ b/src/xdiff/xdiffi.c @@@ -497,13 -489,13 +489,13 @@@ static void measure_split(const xdfile_ m->indent = -1; } else { m->end_of_file = 0; - m->indent = xget_indent(xdf->recs[split]); - m->indent = get_indent(&xdf->recs[split]); ++ m->indent = xget_indent(&xdf->recs[split]); } m->pre_blank = 0; m->pre_indent = -1; for (i = split - 1; i >= 0; i--) { - m->pre_indent = xget_indent(xdf->recs[i]); - m->pre_indent = get_indent(&xdf->recs[i]); ++ m->pre_indent = xget_indent(&xdf->recs[i]); if (m->pre_indent != -1) break; m->pre_blank += 1; @@@ -516,7 -508,7 +508,7 @@@ m->post_blank = 0; m->post_indent = -1; for (i = split + 1; i < xdf->nrec; i++) { - m->post_indent = xget_indent(xdf->recs[i]); - m->post_indent = get_indent(&xdf->recs[i]); ++ m->post_indent = xget_indent(&xdf->recs[i]); if (m->post_indent != -1) break; m->post_blank += 1; @@@ -794,12 -786,6 +786,12 @@@ static int group_slide_up(xdfile_t *xdf } } - static void xdl_bug(const char *msg) ++void xdl_bug(const char *msg) +{ + fprintf(stderr, "BUG: %s\n", msg); + exit(1); +} + /* * Move back and forward change groups for a consistent and pretty diff output. * This also helps in finding joinable change groups and reducing the diff @@@ -1017,10 -1003,9 +1009,10 @@@ static void xdl_mark_ignorable_lines(xd } } +#if 0 // unused by Vim static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) { regmatch_t regmatch; - int i; + size_t i; for (i = 0; i < xpp->ignore_regex_nr; i++) if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, diff --cc src/xdiff/xemit.c index 585ca54135,b2f1f30cd3..94d61a9615 --- a/src/xdiff/xemit.c +++ b/src/xdiff/xemit.c @@@ -22,28 -22,22 +22,27 @@@ #include "xinclude.h" - static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) { - *rec = xdf->recs[ri]->ptr; - - return xdf->recs[ri]->size; - } - - - static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) { - long size, psize = (long)strlen(pre); - char const *rec; - - size = xdl_get_rec(xdf, ri, &rec); - if (xdl_emit_diffrec(rec, size, pre, psize, ecb) < 0) { + static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) + { + xrecord_t *rec = &xdf->recs[ri]; - if (xdl_emit_diffrec(rec->ptr, rec->size, pre, strlen(pre), ecb) < 0) ++ if (xdl_emit_diffrec(rec->ptr, rec->size, pre, (long)strlen(pre), ecb) < 0) return -1; - } return 0; } ++#define signed_add_overflows(a, b) \ ++ ((b) > LONG_MAX - (a)) ++ + static long saturating_add(long a, long b) + { + return signed_add_overflows(a, b) ? LONG_MAX : a + b; + } + ++#undef signed_add_overflows + /* * Starting at the passed change atom, find the latest change atom to be included * inside the differential hunk according to the specified configuration. @@@ -117,15 -110,13 +118,15 @@@ static long def_ff(const char *rec, lon static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri, char *buf, long sz) { - const char *rec; - long len = xdl_get_rec(xdf, ri, &rec); + xrecord_t *rec = &xdf->recs[ri]; + if (!xecfg->find_func) - return def_ff(rec, len, buf, sz); - return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv); + return def_ff(rec->ptr, rec->size, buf, sz); + return xecfg->find_func(rec->ptr, rec->size, buf, sz, xecfg->find_func_priv); } +#endif +#if 0 static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri) { char dummy[1]; @@@ -158,21 -147,16 +159,19 @@@ static long get_func_line(xdfenv_t *xe } return -1; } +#endif +#if 0 static int is_empty_rec(xdfile_t *xdf, long ri) { - const char *rec; - long len = xdl_get_rec(xdf, ri, &rec); + xrecord_t *rec = &xdf->recs[ri]; + long i = 0; - while (len > 0 && XDL_ISSPACE(*rec)) { - rec++; - len--; - } - return !len; + for (; i < rec->size && XDL_ISSPACE(rec->ptr[i]); i++); + + return i == rec->size; } +#endif int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, xdemitconf_t const *xecfg) { diff --cc src/xdiff/xinclude.h index 1e0fbbaaa8,a4285ac0eb..776cb5e13e --- a/src/xdiff/xinclude.h +++ b/src/xdiff/xinclude.h @@@ -20,29 -20,6 +20,32 @@@ * */ +// The following includes come from Vim: + +// defines HAVE_ATTRIBUTE_UNUSED +#ifdef HAVE_CONFIG_H +# ifdef VMS +# include "config.h" +# else +# include "../auto/config.h" +# endif +#endif + +// Mark unused function arguments with UNUSED, so that gcc -Wunused-parameter +// can be used to check for mistakes. +#if defined(HAVE_ATTRIBUTE_UNUSED) || defined(__MINGW32__) +# define UNUSED __attribute__((unused)) +#else +# define UNUSED +#endif + +#if defined(_MSC_VER) +# define inline __inline +#endif + ++// Vim replacement for BUG() ++void xdl_bug(const char *msg); ++ #if !defined(XINCLUDE_H) #define XINCLUDE_H diff --cc src/xdiff/xprepare.c index c84549f6c5,192334f1b7..7f6c80f348 --- a/src/xdiff/xprepare.c +++ b/src/xdiff/xprepare.c @@@ -317,40 -210,47 +210,47 @@@ static bool xdl_clean_mmatch(uint8_t co /* * Scans the lines before 'i' to find a run of lines that either - * have no match (dis[j] == 0) or have multiple matches (dis[j] > 1). - * Note that we always call this function with dis[i] > 1, so the - * current line (i) is already a multimatch line. + * have no match (action[j] == DISCARD) or have multiple matches + * (action[j] == INVESTIGATE). Note that we always call this + * function with action[i] == INVESTIGATE, so the current line + * (i) is already a multimatch line. */ for (r = 1, rdis0 = 0, rpdis0 = 1; (i - r) >= s; r++) { - if (!dis[i - r]) + if (action[i - r] == DISCARD) rdis0++; - else if (dis[i - r] == 2) + else if (action[i - r] == INVESTIGATE) rpdis0++; - else + else if (action[i - r] == KEEP) break; + else - BUG("Illegal value for action[i - r]"); ++ xdl_bug("Illegal value for action[i - r]"); } /* - * If the run before the line 'i' found only multimatch lines, we - * return 0 and hence we don't make the current line (i) discarded. - * We want to discard multimatch lines only when they appear in the - * middle of runs with nomatch lines (dis[j] == 0). + * If the run before the line 'i' found only multimatch lines, + * we return false and hence we don't make the current line (i) + * discarded. We want to discard multimatch lines only when + * they appear in the middle of runs with nomatch lines + * (action[j] == DISCARD). */ if (rdis0 == 0) return 0; for (r = 1, rdis1 = 0, rpdis1 = 1; (i + r) <= e; r++) { - if (!dis[i + r]) + if (action[i + r] == DISCARD) rdis1++; - else if (dis[i + r] == 2) + else if (action[i + r] == INVESTIGATE) rpdis1++; - else + else if (action[i + r] == KEEP) break; + else - BUG("Illegal value for action[i + r]"); ++ xdl_bug("Illegal value for action[i + r]"); } /* - * If the run after the line 'i' found only multimatch lines, we - * return 0 and hence we don't make the current line (i) discarded. + * If the run after the line 'i' found only multimatch lines, + * we return false and hence we don't make the current line (i) + * discarded. */ if (rdis1 == 0) - return 0; + return false; rdis1 += rdis0; rpdis1 += rpdis0;