Skip to content

Commit 5ea8227

Browse files
committed
rerere: represent time duration in timestamp_t internally
The two configuration variables, gc.rerereResolved and gc.rerereUnresolved, are measured in days and are passed as such into the prune_one() helper function, which worked in time_t to see if an entry in the rerere database is past its expiry. Instead, have the caller turn the number of days into the expiry timestamp. Further, use timestamp_t instead of time_t. This will make it possible to extend the way the configuration variable is spelled by using date.c::parse_expiry_date() that gives the expiry timestamp in timestamp_t. Signed-off-by: Junio C Hamano <[email protected]>
1 parent e579aaa commit 5ea8227

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

rerere.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,14 +1133,14 @@ int rerere_forget(struct pathspec *pathspec)
11331133
* Garbage collection support
11341134
*/
11351135

1136-
static time_t rerere_created_at(struct rerere_id *id)
1136+
static timestamp_t rerere_created_at(struct rerere_id *id)
11371137
{
11381138
struct stat st;
11391139

11401140
return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
11411141
}
11421142

1143-
static time_t rerere_last_used_at(struct rerere_id *id)
1143+
static timestamp_t rerere_last_used_at(struct rerere_id *id)
11441144
{
11451145
struct stat st;
11461146

@@ -1157,11 +1157,11 @@ static void unlink_rr_item(struct rerere_id *id)
11571157
id->collection->status[id->variant] = 0;
11581158
}
11591159

1160-
static void prune_one(struct rerere_id *id, time_t now,
1161-
int cutoff_resolve, int cutoff_noresolve)
1160+
static void prune_one(struct rerere_id *id,
1161+
timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
11621162
{
1163-
time_t then;
1164-
int cutoff;
1163+
timestamp_t then;
1164+
timestamp_t cutoff;
11651165

11661166
then = rerere_last_used_at(id);
11671167
if (then)
@@ -1172,25 +1172,35 @@ static void prune_one(struct rerere_id *id, time_t now,
11721172
return;
11731173
cutoff = cutoff_noresolve;
11741174
}
1175-
if (then < now - cutoff * 86400)
1175+
if (then < cutoff)
11761176
unlink_rr_item(id);
11771177
}
11781178

1179+
static void config_get_expiry(const char *key, timestamp_t *cutoff, timestamp_t now)
1180+
{
1181+
int days;
1182+
1183+
if (!git_config_get_int(key, &days)) {
1184+
const int scale = 86400;
1185+
*cutoff = now - days * scale;
1186+
}
1187+
}
1188+
11791189
void rerere_gc(struct string_list *rr)
11801190
{
11811191
struct string_list to_remove = STRING_LIST_INIT_DUP;
11821192
DIR *dir;
11831193
struct dirent *e;
11841194
int i;
1185-
time_t now = time(NULL);
1186-
int cutoff_noresolve = 15;
1187-
int cutoff_resolve = 60;
1195+
timestamp_t now = time(NULL);
1196+
timestamp_t cutoff_noresolve = now - 15 * 86400;
1197+
timestamp_t cutoff_resolve = now - 60 * 86400;
11881198

11891199
if (setup_rerere(rr, 0) < 0)
11901200
return;
11911201

1192-
git_config_get_int("gc.rerereresolved", &cutoff_resolve);
1193-
git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
1202+
config_get_expiry("gc.rerereresolved", &cutoff_resolve, now);
1203+
config_get_expiry("gc.rerereunresolved", &cutoff_noresolve, now);
11941204
git_config(git_default_config, NULL);
11951205
dir = opendir(git_path("rr-cache"));
11961206
if (!dir)
@@ -1211,7 +1221,7 @@ void rerere_gc(struct string_list *rr)
12111221
for (id.variant = 0, id.collection = rr_dir;
12121222
id.variant < id.collection->status_nr;
12131223
id.variant++) {
1214-
prune_one(&id, now, cutoff_resolve, cutoff_noresolve);
1224+
prune_one(&id, cutoff_resolve, cutoff_noresolve);
12151225
if (id.collection->status[id.variant])
12161226
now_empty = 0;
12171227
}

0 commit comments

Comments
 (0)