Skip to content

Commit

Permalink
rerere: explain "rerere forget" codepath
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 24, 2015
1 parent cc899ec commit 963ec00
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -786,19 +790,34 @@ 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))
return (errno == ENOENT
? 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;
Expand All @@ -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++) {
Expand Down

0 comments on commit 963ec00

Please sign in to comment.