aboutsummaryrefslogtreecommitdiff
path: root/rerere.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-06-30 22:42:34 -0700
committerJunio C Hamano <gitster@pobox.com>2015-07-24 16:02:18 -0700
commit963ec003560765bde56a880d89c75056ebe9e990 (patch)
tree493bed5619b6474401d1e51897fd47a83b0f27c5 /rerere.c
parentcc899eca552a9b93788e6bca34aa0e4d86b251a0 (diff)
downloadgit-963ec003560765bde56a880d89c75056ebe9e990.tar.gz
git-963ec003560765bde56a880d89c75056ebe9e990.tar.xz
rerere: explain "rerere forget" codepath
Explain the internals of rerere as in-code comments, while sprinkling "NEEDSWORK" comment to highlight iffy bits and questionable assumptions. This covers the codepath that implements "rerere forget". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'rerere.c')
-rw-r--r--rerere.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/rerere.c b/rerere.c
index 6961c1738..c3e34d10d 100644
--- a/rerere.c
+++ b/rerere.c
@@ -422,6 +422,10 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
strbuf_init(&io.input, 0);
strbuf_attach(&io.input, result.ptr, result.size, result.size);
+ /*
+ * Grab the conflict ID and optionally write the original
+ * contents with conflict markers out.
+ */
hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
strbuf_release(&io.input);
if (io.io.output)
@@ -786,9 +790,15 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
int ret;
struct string_list_item *item;
+ /*
+ * Recreate the original conflict from the stages in the
+ * index and compute the conflict ID
+ */
ret = handle_cache(path, sha1, NULL);
if (ret < 1)
return error("Could not parse conflict hunks in '%s'", path);
+
+ /* Nuke the recorded resolution for the conflict */
hex = xstrdup(sha1_to_hex(sha1));
filename = rerere_path(hex, "postimage");
if (unlink(filename))
@@ -796,9 +806,18 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
? error("no remembered resolution for %s", path)
: error("cannot unlink %s: %s", filename, strerror(errno)));
+ /*
+ * Update the preimage so that the user can resolve the
+ * conflict in the working tree, run us again to record
+ * the postimage.
+ */
handle_cache(path, sha1, rerere_path(hex, "preimage"));
fprintf(stderr, "Updated preimage for '%s'\n", path);
+ /*
+ * And remember that we can record resolution for this
+ * conflict when the user is done.
+ */
item = string_list_insert(rr, path);
free(item->util);
item->util = hex;
@@ -817,6 +836,11 @@ int rerere_forget(struct pathspec *pathspec)
fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
+ /*
+ * The paths may have been resolved (incorrectly);
+ * recover the original conflicted state and then
+ * find the conflicted paths.
+ */
unmerge_cache(pathspec);
find_conflict(&conflict);
for (i = 0; i < conflict.nr; i++) {