Skip to content

Commit 963ec00

Browse files
committed
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 <[email protected]>
1 parent cc899ec commit 963ec00

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rerere.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
422422
strbuf_init(&io.input, 0);
423423
strbuf_attach(&io.input, result.ptr, result.size, result.size);
424424

425+
/*
426+
* Grab the conflict ID and optionally write the original
427+
* contents with conflict markers out.
428+
*/
425429
hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
426430
strbuf_release(&io.input);
427431
if (io.io.output)
@@ -786,19 +790,34 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
786790
int ret;
787791
struct string_list_item *item;
788792

793+
/*
794+
* Recreate the original conflict from the stages in the
795+
* index and compute the conflict ID
796+
*/
789797
ret = handle_cache(path, sha1, NULL);
790798
if (ret < 1)
791799
return error("Could not parse conflict hunks in '%s'", path);
800+
801+
/* Nuke the recorded resolution for the conflict */
792802
hex = xstrdup(sha1_to_hex(sha1));
793803
filename = rerere_path(hex, "postimage");
794804
if (unlink(filename))
795805
return (errno == ENOENT
796806
? error("no remembered resolution for %s", path)
797807
: error("cannot unlink %s: %s", filename, strerror(errno)));
798808

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+
*/
799814
handle_cache(path, sha1, rerere_path(hex, "preimage"));
800815
fprintf(stderr, "Updated preimage for '%s'\n", path);
801816

817+
/*
818+
* And remember that we can record resolution for this
819+
* conflict when the user is done.
820+
*/
802821
item = string_list_insert(rr, path);
803822
free(item->util);
804823
item->util = hex;
@@ -817,6 +836,11 @@ int rerere_forget(struct pathspec *pathspec)
817836

818837
fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE);
819838

839+
/*
840+
* The paths may have been resolved (incorrectly);
841+
* recover the original conflicted state and then
842+
* find the conflicted paths.
843+
*/
820844
unmerge_cache(pathspec);
821845
find_conflict(&conflict);
822846
for (i = 0; i < conflict.nr; i++) {

0 commit comments

Comments
 (0)