Skip to content

Commit d63a9e2

Browse files
committed
rerere: simplify check_one_conflict() helper function
The helper function is responsible for inspecting the index and deciding if the path is merged, is conflicted in a way that we would want to handle, or is conflicted in a way that we cannot handle. Currently, only conflicts with both stage #2 and stage #3 are handled, but eventually we would want to be able to deal with delete-modify conflicts (i.e. only one of stages #2 and #3 exist). Streamline the implementation of the function to make it easier to extend. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5bdedac commit d63a9e2

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

rerere.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -499,41 +499,37 @@ static int handle_file(struct index_state *istate,
499499
}
500500

501501
/*
502-
* Look at a cache entry at "i" and see if it is not conflicting,
503-
* conflicting and we are willing to handle, or conflicting and
504-
* we are unable to handle, and return the determination in *type.
502+
* Look at a cache entry at "i" and see if it is not conflicting
503+
* (RESOLVED), conflicting and we are willing to handle (THREE_STAGED),
504+
* or conflicting and we are unable to handle (PUNTED), and return the
505+
* determination in *type.
506+
*
505507
* Return the cache index to be looked at next, by skipping the
506508
* stages we have already looked at in this invocation of this
507509
* function.
508510
*/
509511
static int check_one_conflict(struct index_state *istate, int i, int *type)
510512
{
511513
const struct cache_entry *e = istate->cache[i];
514+
unsigned int seen_stages = 0;
512515

513516
if (!ce_stage(e)) {
514517
*type = RESOLVED;
515518
return i + 1;
516519
}
517520

518521
*type = PUNTED;
519-
while (i < istate->cache_nr && ce_stage(istate->cache[i]) == 1)
520-
i++;
521-
522-
/* Only handle regular files with both stages #2 and #3 */
523-
if (i + 1 < istate->cache_nr) {
524-
const struct cache_entry *e2 = istate->cache[i];
525-
const struct cache_entry *e3 = istate->cache[i + 1];
526-
if (ce_stage(e2) == 2 &&
527-
ce_stage(e3) == 3 &&
528-
ce_same_name(e, e3) &&
529-
S_ISREG(e2->ce_mode) &&
530-
S_ISREG(e3->ce_mode))
531-
*type = THREE_STAGED;
522+
for (; i < istate->cache_nr; i++) {
523+
const struct cache_entry *n = istate->cache[i];
524+
if (!ce_same_name(n, e))
525+
break;
526+
if (S_ISREG(n->ce_mode))
527+
seen_stages |= 1u << (ce_stage(n) - 1);
532528
}
533529

534-
/* Skip the entries with the same name */
535-
while (i < istate->cache_nr && ce_same_name(e, istate->cache[i]))
536-
i++;
530+
if ((seen_stages & 6) == 6)
531+
*type = THREE_STAGED; /* has both stages #2 and #3 */
532+
537533
return i;
538534
}
539535

0 commit comments

Comments
 (0)