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>
Junio C Hamano committed
Jun 30, 2015 at 22:42 UTC
963ec003560765bde56a880d89c75056ebe9e990
1 file changed
+24
rerere.c
+24
@@ -422,6 +422,10 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
422
strbuf_init(&io.input, 0);
423
strbuf_attach(&io.input, result.ptr, result.size, result.size);
424
425
+ /*
426
+ * Grab the conflict ID and optionally write the original
427
+ * contents with conflict markers out.
428
+ */
429
hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
430
strbuf_release(&io.input);
431
if (io.io.output)
@@ -786,9 +790,15 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
790
int ret;
791
struct string_list_item *item;
792
793
+ /*
794
+ * Recreate the original conflict from the stages in the
795
+ * index and compute the conflict ID
796
+ */
797
ret = handle_cache(path, sha1, NULL);
798
if (ret < 1)
799
return error("Could not parse conflict hunks in '%s'", path);
800
+
801
+ /* Nuke the recorded resolution for the conflict */
802
hex = xstrdup(sha1_to_hex(sha1));
803
filename = rerere_path(hex, "postimage");
804
if (unlink(filename))
@@ -796,9 +806,18 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
806
? error("no remembered resolution for %s", path)
807
: error("cannot unlink %s: %s", filename, strerror(errno)));
808
809
+ /*
810
+ * Update the preimage so that the user can resolve the
811
+ * conflict in the working tree, run us again to record
812
+ * the postimage.
813
+ */
814
handle_cache(path, sha1, rerere_path(hex, "preimage"));
815
fprintf(stderr, "Updated preimage for '%s'\n", path);
816
817
+ /*
818
+ * And remember that we can record resolution for this
819
+ * conflict when the user is done.
820
+ */
821
item = string_list_insert(rr, path);
822
free(item->util);
823
item->util = hex;
@@ -817,6 +836,11 @@ int rerere_forget(struct pathspec *pathspec)
836
837
fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
838
839
+ /*
840
+ * The paths may have been resolved (incorrectly);
841
+ * recover the original conflicted state and then
842
+ * find the conflicted paths.
843
+ */
844
unmerge_cache(pathspec);
845
find_conflict(&conflict);
846
for (i = 0; i < conflict.nr; i++) {