summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-03-28 21:48:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-04-06 22:54:41 (GMT)
commit890fca84be9d2419939f64872648ebe79e68a0b2 (patch)
tree9c805fa721b2da244619ecfee91dd87de5d38b67
parent0ce02b362078efe3e3511feb55d2cb5f8e751961 (diff)
downloadgit-890fca84be9d2419939f64872648ebe79e68a0b2.zip
git-890fca84be9d2419939f64872648ebe79e68a0b2.tar.gz
git-890fca84be9d2419939f64872648ebe79e68a0b2.tar.bz2
rerere: adjust 'forget' to multi-variant world order
Because conflicts with the same contents inside conflict blocks enclosed by "<<<<<<<" and ">>>>>>>" can now have multiple variants to help three-way merge to adjust to the differences outside the conflict blocks, "rerere forget $path" needs to be taught that there may be multiple recorded resolutions that share the same conflict hash (which groups the conflicts with "the same contents inside conflict blocks"), among which there are some that would not be relevant to the conflict we are looking at. These "other variants" that happen to share the same conflict hash should not be cleared, and the variant that would apply to the current conflict may not be the zero-th one (which is the only one that is cleared by the current code). After finding the conflict hash, iterate over the existing variants and try to resolve the conflict using each of them to find the one that "cleanly" resolves the current conflict. That is the one we want to forget and record the preimage for, so that the user can record the corrected resolution. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--rerere.c28
-rwxr-xr-xt/t4200-rerere.sh10
2 files changed, 37 insertions, 1 deletions
diff --git a/rerere.c b/rerere.c
index e636d4b..1693866 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1038,7 +1038,33 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
/* Nuke the recorded resolution for the conflict */
id = new_rerere_id(sha1);
- id->variant = 0; /* for now */
+
+ for (id->variant = 0;
+ id->variant < id->collection->status_nr;
+ id->variant++) {
+ mmfile_t cur = { NULL, 0 };
+ mmbuffer_t result = {NULL, 0};
+ int cleanly_resolved;
+
+ if (!has_rerere_resolution(id))
+ continue;
+
+ handle_cache(path, sha1, rerere_path(id, "thisimage"));
+ if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
+ free(cur.ptr);
+ return error("Failed to update conflicted state in '%s'",
+ path);
+ }
+ cleanly_resolved = !try_merge(id, path, &cur, &result);
+ free(result.ptr);
+ free(cur.ptr);
+ if (cleanly_resolved)
+ break;
+ }
+
+ if (id->collection->status_nr <= id->variant)
+ return error("no remembered resolution for '%s'", path);
+
filename = rerere_path(id, "postimage");
if (unlink(filename))
return (errno == ENOENT
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index a85fc7d..1a080e7 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -536,6 +536,16 @@ test_expect_success 'multiple identical conflicts' '
test_cmp file1.expect file1 &&
test_cmp file2.expect file2 &&
+ # Forget resolution for file2
+ git rerere forget file2 &&
+ echo file2 >expect &&
+ git rerere status >actual &&
+ test_cmp expect actual &&
+ count_pre_post 2 1 &&
+
+ # file2 already has correct resolution, so record it again
+ git rerere &&
+
# Pretend that the resolutions are old again
find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&