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 <gitster@pobox.com>

Junio C Hamano committed Mar 11, 2016 at 14:53 UTC 0ce02b362078efe3e3511feb55d2cb5f8e751961
1 file changed +31 -16
rerere.c
+31 -16
@@ -621,6 +621,33 @@ int rerere_remaining(struct string_list *merge_rr)
621 return 0;
622 }
623
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 +
651 /*
652 * Find the conflict identified by "id"; the change between its
653 * "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)
662 {
663 FILE *f;
664 int ret;
638 - mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
665 + mmfile_t cur = {NULL, 0};
666 mmbuffer_t result = {NULL, 0};
667
668 /*
669 * Normalize the conflicts in path and write it out to
670 * "thisimage" temporary file.
671 */
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"))) {
674 ret = 1;
675 goto out;
676 }
677
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);
679 if (ret)
680 goto out;
681
@@ -684,8 +701,6 @@ static int merge(const struct rerere_id *id, const char *path)
701
702 out:
703 free(cur.ptr);
687 - free(base.ptr);
688 - free(other.ptr);
704 free(result.ptr);
705
706 return ret;