From: Ezekiel Newren via GitGitGadget Date: Wed, 08 Apr 2026 20:26:22 GMT Subject: [PATCH v5 0/6] Xdiff cleanup part 3 Message-ID: In-Reply-To: Changes in v5: * drop commit "xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarity". * add braces around the else clause I didn't see a better way to rewrite how action is used so I reverted to what it used to be. Changes in v4: * Change SIZE_MAX to PTRDIFF_MAX. Changes in v3: * run make DEVELOPER=1 on each commit and fix all compiler issues v2 is a radical departure from v1 Changes in v2: * make the flow of xdl_cleanup_records() easier to follow There is no performance or behavioral change introduced in this patch series. === original cover letter bellow === Patch series summary: * patch 1: Introduce the ivec type * patch 2: Create the function xdl_do_classic_diff() * patches 3-4: generic cleanup * patches 5-8: convert from dstart/dend (in xdfile_t) to delta_start/delta_end (in xdfenv_t) * patches 9-10: move xdl_cleanup_records(), and related, from xprepare.c to xdiffi.c Things that will be addressed in future patch series: * Make xdl_cleanup_records() easier to read * convert recs/nrec into an ivec * convert changed to an ivec * remove reference_index/nreff from xdfile_t and turn it into an ivec * splitting minimal_perfect_hash out as its own ivec * improve the performance of the classifier and parsing/hashing lines === before this patch series typedef struct s_xdfile { xrecord_t *recs; size_t nrec; ptrdiff_t dstart, dend; bool *changed; size_t *reference_index; size_t nreff; } xdfile_t; typedef struct s_xdfenv { xdfile_t xdf1, xdf2; } xdfenv_t; === after this patch series typedef struct s_xdfile { xrecord_t *recs; size_t nrec; bool *changed; size_t *reference_index; size_t nreff; } xdfile_t; typedef struct s_xdfenv { xdfile_t xdf1, xdf2; size_t delta_start, delta_end; size_t mph_size; } xdfenv_t; Ezekiel Newren (6): xdiff/xdl_cleanup_records: delete local recs pointer xdiff: use unambiguous types in xdl_bogo_sqrt() xdiff/xdl_cleanup_records: use unambiguous types xdiff/xdl_cleanup_records: make limits more clear xdiff/xdl_cleanup_records: make setting action easier to follow xdiff/xdl_cleanup_records: put braces around the else clause xdiff/xdiffi.c | 2 +- xdiff/xprepare.c | 56 +++++++++++++++++++++++++++++++----------------- xdiff/xutils.c | 4 ++-- xdiff/xutils.h | 2 +- 4 files changed, 40 insertions(+), 24 deletions(-) base-commit: ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2156%2Fezekielnewren%2Fxdiff-cleanup-3-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2156/ezekielnewren/xdiff-cleanup-3-v5 Pull-Request: https://github.com/git/git/pull/2156 Range-diff vs v4: 1: da32a9747c = 1: b31924a949 xdiff/xdl_cleanup_records: delete local recs pointer 2: 86b0ad100c = 2: 1822166fef xdiff: use unambiguous types in xdl_bogo_sqrt() 3: 39a35365ae = 3: 85aa0da90c xdiff/xdl_cleanup_records: use unambiguous types 4: 75fe3ea125 = 4: fec2b0f38a xdiff/xdl_cleanup_records: make limits more clear 5: 0cf1412d01 = 5: 88c68fa89a xdiff/xdl_cleanup_records: make setting action easier to follow 6: fd14ccafc4 ! 6: 699e198fa9 xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarity @@ Metadata Author: Ezekiel Newren ## Commit message ## - xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarity - - Make it clear that INVESTIGATE is turned into KEEP or DISCARD based on - the result of xdl_clean_mmatch() which reduces actionX[i] into a - boolean value. + xdiff/xdl_cleanup_records: put braces around the else clause Signed-off-by: Ezekiel Newren ## xdiff/xprepare.c ## @@ xdiff/xprepare.c: static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd - */ - xdf1->nreff = 0; - for (i = xdf1->dstart; i <= xdf1->dend; i++) { -- if (action1[i] == KEEP || -- (action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) { -+ if (action1[i] == INVESTIGATE) { -+ if (!xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend)) -+ action1[i] = KEEP; -+ else -+ action1[i] = DISCARD; -+ } -+ -+ if (action1[i] == KEEP) { + (action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) { xdf1->reference_index[xdf1->nreff++] = i; -- /* changed[i] remains false, i.e. keep */ + /* changed[i] remains false, i.e. keep */ - } else -+ /* changed[i] remains false */ -+ } else if (action1[i] == DISCARD) ++ } else { xdf1->changed[i] = true; -- /* i.e. discard */ -+ else -+ BUG("Illegal state for action1[i]"); + /* i.e. discard */ ++ } } xdf2->nreff = 0; - for (i = xdf2->dstart; i <= xdf2->dend; i++) { -- if (action2[i] == KEEP || -- (action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) { -+ if (action2[i] == INVESTIGATE) { -+ if (!xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend)) -+ action2[i] = KEEP; -+ else -+ action2[i] = DISCARD; -+ } -+ -+ if (action2[i] == KEEP) { +@@ xdiff/xprepare.c: static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd + (action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) { xdf2->reference_index[xdf2->nreff++] = i; -- /* changed[i] remains false, i.e. keep */ + /* changed[i] remains false, i.e. keep */ - } else -+ /* changed[i] remains false */ -+ } else if (action2[i] == DISCARD) ++ } else { xdf2->changed[i] = true; -- /* i.e. discard */ -+ else -+ BUG("Illegal state for action2[i]"); + /* i.e. discard */ ++ } } cleanup: -- gitgitgadget