Skip to content

Commit

Permalink
rerere: explain the remainder
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 gc" and "rerere
clear".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jul 24, 2015
1 parent 963ec00 commit e828de8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ int rerere_forget(struct pathspec *pathspec)
return write_rr(&merge_rr, fd);
}

/*
* Garbage collection support
*/
static time_t rerere_created_at(const char *name)
{
struct stat st;
Expand All @@ -865,11 +868,19 @@ static time_t rerere_last_used_at(const char *name)
return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
}

/*
* Remove the recorded resolution for a given conflict ID
*/
static void unlink_rr_item(const char *name)
{
unlink(rerere_path(name, "thisimage"));
unlink(rerere_path(name, "preimage"));
unlink(rerere_path(name, "postimage"));
/*
* NEEDSWORK: what if this rmdir() fails? Wouldn't we then
* assume that we already have preimage recorded in
* do_plain_rerere()?
*/
rmdir(git_path("rr-cache/%s", name));
}

Expand All @@ -889,6 +900,7 @@ void rerere_gc(struct string_list *rr)
dir = opendir(git_path("rr-cache"));
if (!dir)
die_errno("unable to open rr-cache directory");
/* Collect stale conflict IDs ... */
while ((e = readdir(dir))) {
if (is_dot_or_dotdot(e->d_name))
continue;
Expand All @@ -906,11 +918,19 @@ void rerere_gc(struct string_list *rr)
string_list_append(&to_remove, e->d_name);
}
closedir(dir);
/* ... and then remove them one-by-one */
for (i = 0; i < to_remove.nr; i++)
unlink_rr_item(to_remove.items[i].string);
string_list_clear(&to_remove, 0);
}

/*
* During a conflict resolution, after "rerere" recorded the
* preimages, abandon them if the user did not resolve them or
* record their resolutions. And drop $GIT_DIR/MERGE_RR.
*
* NEEDSWORK: shouldn't we be calling this from "reset --hard"?
*/
void rerere_clear(struct string_list *merge_rr)
{
int i;
Expand Down

0 comments on commit e828de8

Please sign in to comment.