Skip to content

Commit

Permalink
rerere: simplify handle_file() helper function
Browse files Browse the repository at this point in the history
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, and 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 <gitster@pobox.com>
  • Loading branch information
gitster committed Aug 3, 2023
1 parent 5bdedac commit adbda9c
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,41 +499,38 @@ static int handle_file(struct index_state *istate,
}

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

if (!ce_stage(e)) {
*type = RESOLVED;
return i + 1;
}

*type = PUNTED;
while (i < istate->cache_nr && ce_stage(istate->cache[i]) == 1)
i++;
for (; i < istate->cache_nr; i++) {
const struct cache_entry *n = istate->cache[i];
if (!ce_same_name(n, e))
break;
if (S_ISREG(n->ce_mode))
seen_stages |= 1u << (ce_stage(n) - 1);
}

/* Only handle regular files with both stages #2 and #3 */
if (i + 1 < istate->cache_nr) {
const struct cache_entry *e2 = istate->cache[i];
const struct cache_entry *e3 = istate->cache[i + 1];
if (ce_stage(e2) == 2 &&
ce_stage(e3) == 3 &&
ce_same_name(e, e3) &&
S_ISREG(e2->ce_mode) &&
S_ISREG(e3->ce_mode))
*type = THREE_STAGED;
}
if ((seen_stages & 6) == 6)
*type = THREE_STAGED;

/* Skip the entries with the same name */
while (i < istate->cache_nr && ce_same_name(e, istate->cache[i]))
i++;
return i;
}

Expand Down Expand Up @@ -1245,7 +1242,7 @@ void rerere_clear(struct repository *r, struct string_list *merge_rr)

for (i = 0; i < merge_rr->nr; i++) {
struct rerere_id *id = merge_rr->items[i].util;
if (!has_rerere_resolution(id)) {
if (!has_rerere_resolution(id)) {
unlink_rr_item(id);
rmdir(rerere_path(id, NULL));
}
Expand Down

0 comments on commit adbda9c

Please sign in to comment.