X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=builtin%2Frerere.c;h=67793fa2c795777b02c340551a5c4cee152ff68b;hb=0c1c798f20bb9956312247e091b23ba2e7baf7b4;hp=0048f9ef7fee24e5e058ef226f3b0fc93703fcf1;hpb=e1165dd1442017c2b2722027168c497640f25746;p=git.git diff --git a/builtin/rerere.c b/builtin/rerere.c index 0048f9ef7..67793fa2c 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -19,6 +19,12 @@ static time_t rerere_created_at(const char *name) return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime; } +static time_t rerere_last_used_at(const char *name) +{ + struct stat st; + return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime; +} + static void unlink_rr_item(const char *name) { unlink(rerere_path(name, "thisimage")); @@ -40,7 +46,7 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb) static void garbage_collect(struct string_list *rr) { - struct string_list to_remove = { NULL, 0, 0, 1 }; + struct string_list to_remove = STRING_LIST_INIT_DUP; DIR *dir; struct dirent *e; int i, cutoff; @@ -53,13 +59,18 @@ static void garbage_collect(struct string_list *rr) while ((e = readdir(dir))) { if (is_dot_or_dotdot(e->d_name)) continue; - then = rerere_created_at(e->d_name); - if (!then) - continue; - cutoff = (has_rerere_resolution(e->d_name) - ? cutoff_resolve : cutoff_noresolve); + + then = rerere_last_used_at(e->d_name); + if (then) { + cutoff = cutoff_resolve; + } else { + then = rerere_created_at(e->d_name); + if (!then) + continue; + cutoff = cutoff_noresolve; + } if (then < now - cutoff * 86400) - string_list_append(e->d_name, &to_remove); + string_list_append(&to_remove, e->d_name); } for (i = 0; i < to_remove.nr; i++) unlink_rr_item(to_remove.items[i].string); @@ -102,7 +113,7 @@ static int diff_two(const char *file1, const char *label1, int cmd_rerere(int argc, const char **argv, const char *prefix) { - struct string_list merge_rr = { NULL, 0, 0, 1 }; + struct string_list merge_rr = STRING_LIST_INIT_DUP; int i, fd, flags = 0; if (2 < argc) { @@ -135,7 +146,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix) if (!has_rerere_resolution(name)) unlink_rr_item(name); } - unlink_or_warn(git_path("rr-cache/MERGE_RR")); + unlink_or_warn(git_path("MERGE_RR")); } else if (!strcmp(argv[1], "gc")) garbage_collect(&merge_rr); else if (!strcmp(argv[1], "status"))