Browse Source

rerere: explain the remainder

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>
maint
Junio C Hamano 10 years ago
parent
commit
e828de826b
  1. 20
      rerere.c

20
rerere.c

@ -853,6 +853,9 @@ int rerere_forget(struct pathspec *pathspec)
return write_rr(&merge_rr, fd); return write_rr(&merge_rr, fd);
} }


/*
* Garbage collection support
*/
static time_t rerere_created_at(const char *name) static time_t rerere_created_at(const char *name)
{ {
struct stat st; struct stat st;
@ -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; 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) static void unlink_rr_item(const char *name)
{ {
unlink(rerere_path(name, "thisimage")); unlink(rerere_path(name, "thisimage"));
unlink(rerere_path(name, "preimage")); unlink(rerere_path(name, "preimage"));
unlink(rerere_path(name, "postimage")); 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)); rmdir(git_path("rr-cache/%s", name));
} }


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

Loading…
Cancel
Save