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>
Junio C Hamano committed
Jun 30, 2015 at 22:43 UTC
e828de826bd0b852337b9625354c7c73d8de20c0
1 file changed
+20
rerere.c
+20
@@ -853,6 +853,9 @@ int rerere_forget(struct pathspec *pathspec)
853
return write_rr(&merge_rr, fd);
854
}
855
856
+/*
857
+ * Garbage collection support
858
+ */
859
static time_t rerere_created_at(const char *name)
860
{
861
struct stat st;
@@ -865,11 +868,19 @@ static time_t rerere_last_used_at(const char *name)
868
return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
869
}
870
871
+/*
872
+ * Remove the recorded resolution for a given conflict ID
873
+ */
874
static void unlink_rr_item(const char *name)
875
{
876
unlink(rerere_path(name, "thisimage"));
877
unlink(rerere_path(name, "preimage"));
878
unlink(rerere_path(name, "postimage"));
879
+ /*
880
+ * NEEDSWORK: what if this rmdir() fails? Wouldn't we then
881
+ * assume that we already have preimage recorded in
882
+ * do_plain_rerere()?
883
+ */
884
rmdir(git_path("rr-cache/%s", name));
885
}
886
@@ -889,6 +900,7 @@ void rerere_gc(struct string_list *rr)
900
dir = opendir(git_path("rr-cache"));
901
if (!dir)
902
die_errno("unable to open rr-cache directory");
903
+ /* Collect stale conflict IDs ... */
904
while ((e = readdir(dir))) {
905
if (is_dot_or_dotdot(e->d_name))
906
continue;
@@ -906,11 +918,19 @@ void rerere_gc(struct string_list *rr)
918
string_list_append(&to_remove, e->d_name);
919
}
920
closedir(dir);
921
+ /* ... and then remove them one-by-one */
922
for (i = 0; i < to_remove.nr; i++)
923
unlink_rr_item(to_remove.items[i].string);
924
string_list_clear(&to_remove, 0);
925
}
926
927
+/*
928
+ * During a conflict resolution, after "rerere" recorded the
929
+ * preimages, abandon them if the user did not resolve them or
930
+ * record their resolutions. And drop $GIT_DIR/MERGE_RR.
931
+ *
932
+ * NEEDSWORK: shouldn't we be calling this from "reset --hard"?
933
+ */
934
void rerere_clear(struct string_list *merge_rr)
935
{
936
int i;