Skip to content

Commit 0ce02b3

Browse files
committed
rerere: split code to call ll_merge() further
The merge() helper function is given an existing rerere ID (i.e. the name of the .git/rr-cache/* subdirectory, and the variant number) that identifies one <preimage, postimage> pair, try to see if the conflicted state in the given path can be resolved by using the pair, and if this succeeds, then update the conflicted path with the result in the working tree. To implement rerere_forget() in the multiple variant world, we'd need a helper to do the "see if a <preimage, postimage> pair cleanly resolves a conflicted state we have in-core" part, without actually touching any file in the working tree, in order to identify which variant(s) to remove. Split the logic to do so into a separate helper function try_merge() out of merge(). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d730ed commit 0ce02b3

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

rerere.c

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,33 @@ int rerere_remaining(struct string_list *merge_rr)
621621
return 0;
622622
}
623623

624+
/*
625+
* Try using the given conflict resolution "ID" to see
626+
* if that recorded conflict resolves cleanly what we
627+
* got in the "cur".
628+
*/
629+
static int try_merge(const struct rerere_id *id, const char *path,
630+
mmfile_t *cur, mmbuffer_t *result)
631+
{
632+
int ret;
633+
mmfile_t base = {NULL, 0}, other = {NULL, 0};
634+
635+
if (read_mmfile(&base, rerere_path(id, "preimage")) ||
636+
read_mmfile(&other, rerere_path(id, "postimage")))
637+
ret = 1;
638+
else
639+
/*
640+
* A three-way merge. Note that this honors user-customizable
641+
* low-level merge driver settings.
642+
*/
643+
ret = ll_merge(result, path, &base, NULL, cur, "", &other, "", NULL);
644+
645+
free(base.ptr);
646+
free(other.ptr);
647+
648+
return ret;
649+
}
650+
624651
/*
625652
* Find the conflict identified by "id"; the change between its
626653
* "preimage" (i.e. a previous contents with conflict markers) and its
@@ -635,30 +662,20 @@ static int merge(const struct rerere_id *id, const char *path)
635662
{
636663
FILE *f;
637664
int ret;
638-
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
665+
mmfile_t cur = {NULL, 0};
639666
mmbuffer_t result = {NULL, 0};
640667

641668
/*
642669
* Normalize the conflicts in path and write it out to
643670
* "thisimage" temporary file.
644671
*/
645-
if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) {
646-
ret = 1;
647-
goto out;
648-
}
649-
650-
if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
651-
read_mmfile(&base, rerere_path(id, "preimage")) ||
652-
read_mmfile(&other, rerere_path(id, "postimage"))) {
672+
if ((handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) ||
673+
read_mmfile(&cur, rerere_path(id, "thisimage"))) {
653674
ret = 1;
654675
goto out;
655676
}
656677

657-
/*
658-
* A three-way merge. Note that this honors user-customizable
659-
* low-level merge driver settings.
660-
*/
661-
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL);
678+
ret = try_merge(id, path, &cur, &result);
662679
if (ret)
663680
goto out;
664681

@@ -684,8 +701,6 @@ static int merge(const struct rerere_id *id, const char *path)
684701

685702
out:
686703
free(cur.ptr);
687-
free(base.ptr);
688-
free(other.ptr);
689704
free(result.ptr);
690705

691706
return ret;

0 commit comments

Comments
 (0)