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
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
701
702
out:
703
free(cur.ptr);
687
- free(base.ptr);
688
- free(other.ptr);
704
free(result.ptr);
705
706
return ret;