xdiff/xdl_cleanup_records: make execution of action easier to follow

Helped-by: Phillip Wood Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ezekiel Newren committed Apr 29, 2026 at 22:08 UTC f87808b7014cf06db4a7e19b193cf9aa7e965ebc
1 file changed +30 -10
xdiff/xprepare.c
+30 -10
@@ -336,24 +336,44 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
336 */
337 xdf1->nreff = 0;
338 for (i = xdf1->dstart; i <= xdf1->dend; i++) {
339 - if (action1[i] == KEEP ||
340 - (action1[i] == INVESTIGATE && !xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))) {
339 + uint8_t action = action1[i];
340 +
341 + if (action == INVESTIGATE) {
342 + if (!xdl_clean_mmatch(action1, i, xdf1->dstart, xdf1->dend))
343 + action = KEEP;
344 + else
345 + action = DISCARD;
346 + }
347 +
348 + if (action == KEEP) {
349 xdf1->reference_index[xdf1->nreff++] = i;
342 - /* changed[i] remains false, i.e. keep */
343 - } else
350 + /* changed[i] remains false */
351 + } else if (action == DISCARD) {
352 xdf1->changed[i] = true;
345 - /* i.e. discard */
353 + } else {
354 + BUG("Illegal state for action");
355 + }
356 }
357
358 xdf2->nreff = 0;
359 for (i = xdf2->dstart; i <= xdf2->dend; i++) {
350 - if (action2[i] == KEEP ||
351 - (action2[i] == INVESTIGATE && !xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))) {
360 + uint8_t action = action2[i];
361 +
362 + if (action == INVESTIGATE) {
363 + if (!xdl_clean_mmatch(action2, i, xdf2->dstart, xdf2->dend))
364 + action = KEEP;
365 + else
366 + action = DISCARD;
367 + }
368 +
369 + if (action == KEEP) {
370 xdf2->reference_index[xdf2->nreff++] = i;
353 - /* changed[i] remains false, i.e. keep */
354 - } else
371 + /* changed[i] remains false */
372 + } else if (action == DISCARD) {
373 xdf2->changed[i] = true;
356 - /* i.e. discard */
374 + } else {
375 + BUG("Illegal state for action");
376 + }
377 }
378
379 cleanup: