Re: [PATCH 01/17] xdiff: delete static forward declarations in xprepare
- From
Elijah Newren <newren@gmail.com>
- Date
- Sep 9, 2025, 08:55 UTC
- Message-ID
- <CABPp-BGn7LYJKh3Nvmb_UOCnprSw13NHApwqvC0G92DBYnOuAw@mail.gmail.com>
- In-Reply-To
- <9cf9d09c079060bb03556db270a3100ca62c6ba0.1757274320.git.gitgitgadget@gmail.com>
On Sun, Sep 7, 2025 at 12:45 PM Ezekiel Newren via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 151 quoted lines
>
> From: Ezekiel Newren <ezekielnewren@gmail.com>
>
> Move xdl_prepare_env() later in the file to avoid the need
> for static forward declarations.
>
> Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com>
> ---
> xdiff/xprepare.c | 116 ++++++++++++++++++++---------------------------
> 1 file changed, 50 insertions(+), 66 deletions(-)
>
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index e1d4017b2d..a45c5ee208 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -53,21 +53,6 @@ typedef struct s_xdlclassifier {
>
>
>
> -static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags);
> -static void xdl_free_classifier(xdlclassifier_t *cf);
> -static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t **rhash,
> - unsigned int hbits, xrecord_t *rec);
> -static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
> - xdlclassifier_t *cf, xdfile_t *xdf);
> -static void xdl_free_ctx(xdfile_t *xdf);
> -static int xdl_clean_mmatch(char const *dis, long i, long s, long e);
> -static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2);
> -static int xdl_trim_ends(xdfile_t *xdf1, xdfile_t *xdf2);
> -static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2);
> -
> -
> -
> -
> static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
> cf->flags = flags;
>
> @@ -242,57 +227,6 @@ static void xdl_free_ctx(xdfile_t *xdf) {
> }
>
>
> -int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
> - xdfenv_t *xe) {
> - long enl1, enl2, sample;
> - xdlclassifier_t cf;
> -
> - memset(&cf, 0, sizeof(cf));
> -
> - /*
> - * For histogram diff, we can afford a smaller sample size and
> - * thus a poorer estimate of the number of lines, as the hash
> - * table (rhash) won't be filled up/grown. The number of lines
> - * (nrecs) will be updated correctly anyway by
> - * xdl_prepare_ctx().
> - */
> - sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF
> - ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1);
> -
> - enl1 = xdl_guess_lines(mf1, sample) + 1;
> - enl2 = xdl_guess_lines(mf2, sample) + 1;
> -
> - if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
> - return -1;
> -
> - if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
> -
> - xdl_free_classifier(&cf);
> - return -1;
> - }
> - if (xdl_prepare_ctx(2, mf2, enl2, xpp, &cf, &xe->xdf2) < 0) {
> -
> - xdl_free_ctx(&xe->xdf1);
> - xdl_free_classifier(&cf);
> - return -1;
> - }
> -
> - if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
> - (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
> - xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) {
> -
> - xdl_free_ctx(&xe->xdf2);
> - xdl_free_ctx(&xe->xdf1);
> - xdl_free_classifier(&cf);
> - return -1;
> - }
> -
> - xdl_free_classifier(&cf);
> -
> - return 0;
> -}
> -
> -
> void xdl_free_env(xdfenv_t *xe) {
>
> xdl_free_ctx(&xe->xdf2);
> @@ -460,3 +394,53 @@ static int xdl_optimize_ctxs(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2
>
> return 0;
> }
> +
> +int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
> + xdfenv_t *xe) {
> + long enl1, enl2, sample;
> + xdlclassifier_t cf;
> +
> + memset(&cf, 0, sizeof(cf));
> +
> + /*
> + * For histogram diff, we can afford a smaller sample size and
> + * thus a poorer estimate of the number of lines, as the hash
> + * table (rhash) won't be filled up/grown. The number of lines
> + * (nrecs) will be updated correctly anyway by
> + * xdl_prepare_ctx().
> + */
> + sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF
> + ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1);
> +
> + enl1 = xdl_guess_lines(mf1, sample) + 1;
> + enl2 = xdl_guess_lines(mf2, sample) + 1;
> +
> + if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
> + return -1;
> +
> + if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
> +
> + xdl_free_classifier(&cf);
> + return -1;
> + }
> + if (xdl_prepare_ctx(2, mf2, enl2, xpp, &cf, &xe->xdf2) < 0) {
> +
> + xdl_free_ctx(&xe->xdf1);
> + xdl_free_classifier(&cf);
> + return -1;
> + }
> +
> + if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
> + (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
> + xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) {
> +
> + xdl_free_ctx(&xe->xdf2);
> + xdl_free_ctx(&xe->xdf1);
> + xdl_free_classifier(&cf);
> + return -1;
> + }
> +
> + xdl_free_classifier(&cf);
> +
> + return 0;
> +}
> --
> gitgitgadgetViewing this with --color-moved makes it clear that the changes exactly match what you summarize in the commit message.