summaryrefslogtreecommitdiffstats
path: root/rerere.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-03-11 14:53:05 -0800
committerJunio C Hamano <gitster@pobox.com>2016-04-06 15:52:40 -0700
commit0ce02b362078efe3e3511feb55d2cb5f8e751961 (patch)
tree1f376d19ad3a8db44acbb8748ff64669f09e1e28 /rerere.c
parent3d730ed9b21b5397be7fa5bf89298122980b0f58 (diff)
downloadgit-0ce02b362078efe3e3511feb55d2cb5f8e751961.tar.gz
git-0ce02b362078efe3e3511feb55d2cb5f8e751961.tar.xz
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>
Diffstat (limited to 'rerere.c')
-rw-r--r--rerere.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/rerere.c b/rerere.c
index 2b870e02a..e636d4b0f 100644
--- a/rerere.c
+++ b/rerere.c
@@ -622,6 +622,33 @@ int rerere_remaining(struct string_list *merge_rr)
}
/*
+ * Try using the given conflict resolution "ID" to see
+ * if that recorded conflict resolves cleanly what we
+ * got in the "cur".
+ */
+static int try_merge(const struct rerere_id *id, const char *path,
+ mmfile_t *cur, mmbuffer_t *result)
+{
+ int ret;
+ mmfile_t base = {NULL, 0}, other = {NULL, 0};
+
+ if (read_mmfile(&base, rerere_path(id, "preimage")) ||
+ read_mmfile(&other, rerere_path(id, "postimage")))
+ ret = 1;
+ else
+ /*
+ * A three-way merge. Note that this honors user-customizable
+ * low-level merge driver settings.
+ */
+ ret = ll_merge(result, path, &base, NULL, cur, "", &other, "", NULL);
+
+ free(base.ptr);
+ free(other.ptr);
+
+ return ret;
+}
+
+/*
* Find the conflict identified by "id"; the change between its
* "preimage" (i.e. a previous contents with conflict markers) and its
* "postimage" (i.e. the corresponding contents with conflicts
@@ -635,30 +662,20 @@ static int merge(const struct rerere_id *id, const char *path)
{
FILE *f;
int ret;
- mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
+ mmfile_t cur = {NULL, 0};
mmbuffer_t result = {NULL, 0};
/*
* Normalize the conflicts in path and write it out to
* "thisimage" temporary file.
*/
- if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) {
- ret = 1;
- goto out;
- }
-
- if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
- read_mmfile(&base, rerere_path(id, "preimage")) ||
- read_mmfile(&other, rerere_path(id, "postimage"))) {
+ if ((handle_file(path, NULL, rerere_path(id, "thisimage")) < 0) ||
+ read_mmfile(&cur, rerere_path(id, "thisimage"))) {
ret = 1;
goto out;
}
- /*
- * A three-way merge. Note that this honors user-customizable
- * low-level merge driver settings.
- */
- ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", NULL);
+ ret = try_merge(id, path, &cur, &result);
if (ret)
goto out;
@@ -684,8 +701,6 @@ static int merge(const struct rerere_id *id, const char *path)
out:
free(cur.ptr);
- free(base.ptr);
- free(other.ptr);
free(result.ptr);
return ret;