Skip to content

Commit e828de8

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rerere.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ int rerere_forget(struct pathspec *pathspec)
853853
return write_rr(&merge_rr, fd);
854854
}
855855

856+
/*
857+
* Garbage collection support
858+
*/
856859
static time_t rerere_created_at(const char *name)
857860
{
858861
struct stat st;
@@ -865,11 +868,19 @@ static time_t rerere_last_used_at(const char *name)
865868
return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
866869
}
867870

871+
/*
872+
* Remove the recorded resolution for a given conflict ID
873+
*/
868874
static void unlink_rr_item(const char *name)
869875
{
870876
unlink(rerere_path(name, "thisimage"));
871877
unlink(rerere_path(name, "preimage"));
872878
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+
*/
873884
rmdir(git_path("rr-cache/%s", name));
874885
}
875886

@@ -889,6 +900,7 @@ void rerere_gc(struct string_list *rr)
889900
dir = opendir(git_path("rr-cache"));
890901
if (!dir)
891902
die_errno("unable to open rr-cache directory");
903+
/* Collect stale conflict IDs ... */
892904
while ((e = readdir(dir))) {
893905
if (is_dot_or_dotdot(e->d_name))
894906
continue;
@@ -906,11 +918,19 @@ void rerere_gc(struct string_list *rr)
906918
string_list_append(&to_remove, e->d_name);
907919
}
908920
closedir(dir);
921+
/* ... and then remove them one-by-one */
909922
for (i = 0; i < to_remove.nr; i++)
910923
unlink_rr_item(to_remove.items[i].string);
911924
string_list_clear(&to_remove, 0);
912925
}
913926

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+
*/
914934
void rerere_clear(struct string_list *merge_rr)
915935
{
916936
int i;

0 commit comments

Comments
 (0)