summaryrefslogtreecommitdiff
path: root/builtin/rerere.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/rerere.c')
-rw-r--r--builtin/rerere.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 39ad601..67793fa 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,11 +59,16 @@ 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(&to_remove, e->d_name);
}
@@ -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) {