From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Uwe Hausbrand <uwe.hausbrand@gmx.de>
Subject: [PATCH 1/2] rerere: represent time duration in timestamp_t internally
Date: Sat, 19 Aug 2017 13:30:12 -0700 [thread overview]
Message-ID: <20170819203013.3053-2-gitster@pobox.com> (raw)
In-Reply-To: <20170819203013.3053-1-gitster@pobox.com>
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 <gitster@pobox.com>
---
rerere.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/rerere.c b/rerere.c
index 70634d456c..f0b4bce881 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1133,14 +1133,14 @@ int rerere_forget(struct pathspec *pathspec)
* Garbage collection support
*/
-static time_t rerere_created_at(struct rerere_id *id)
+static timestamp_t rerere_created_at(struct rerere_id *id)
{
struct stat st;
return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
}
-static time_t rerere_last_used_at(struct rerere_id *id)
+static timestamp_t rerere_last_used_at(struct rerere_id *id)
{
struct stat st;
@@ -1157,11 +1157,11 @@ static void unlink_rr_item(struct rerere_id *id)
id->collection->status[id->variant] = 0;
}
-static void prune_one(struct rerere_id *id, time_t now,
- int cutoff_resolve, int cutoff_noresolve)
+static void prune_one(struct rerere_id *id,
+ timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
{
- time_t then;
- int cutoff;
+ timestamp_t then;
+ timestamp_t cutoff;
then = rerere_last_used_at(id);
if (then)
@@ -1172,25 +1172,35 @@ static void prune_one(struct rerere_id *id, time_t now,
return;
cutoff = cutoff_noresolve;
}
- if (then < now - cutoff * 86400)
+ if (then < cutoff)
unlink_rr_item(id);
}
+static void config_get_expiry(const char *key, timestamp_t *cutoff, timestamp_t now)
+{
+ int days;
+
+ if (!git_config_get_int(key, &days)) {
+ const int scale = 86400;
+ *cutoff = now - days * scale;
+ }
+}
+
void rerere_gc(struct string_list *rr)
{
struct string_list to_remove = STRING_LIST_INIT_DUP;
DIR *dir;
struct dirent *e;
int i;
- time_t now = time(NULL);
- int cutoff_noresolve = 15;
- int cutoff_resolve = 60;
+ timestamp_t now = time(NULL);
+ timestamp_t cutoff_noresolve = now - 15 * 86400;
+ timestamp_t cutoff_resolve = now - 60 * 86400;
if (setup_rerere(rr, 0) < 0)
return;
- git_config_get_int("gc.rerereresolved", &cutoff_resolve);
- git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
+ config_get_expiry("gc.rerereresolved", &cutoff_resolve, now);
+ config_get_expiry("gc.rerereunresolved", &cutoff_noresolve, now);
git_config(git_default_config, NULL);
dir = opendir(git_path("rr-cache"));
if (!dir)
@@ -1211,7 +1221,7 @@ void rerere_gc(struct string_list *rr)
for (id.variant = 0, id.collection = rr_dir;
id.variant < id.collection->status_nr;
id.variant++) {
- prune_one(&id, now, cutoff_resolve, cutoff_noresolve);
+ prune_one(&id, cutoff_resolve, cutoff_noresolve);
if (id.collection->status[id.variant])
now_empty = 0;
}
--
2.14.1-405-g52c75fc716
next prev parent reply other threads:[~2017-08-19 20:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 12:59 fatal: bad numeric config value '60 days' for 'gc.rerereresolved': invalid unit Uwe Hausbrand
2017-07-21 14:30 ` Martin Ågren
2017-07-21 14:33 ` Junio C Hamano
2017-07-21 17:35 ` Uwe Hausbrand
2017-08-19 20:30 ` [PATCH 0/2] accept non-integer for "this many days" expiry specification Junio C Hamano
2017-08-19 20:30 ` Junio C Hamano [this message]
2017-08-19 20:30 ` [PATCH 2/2] rerere: allow approxidate in gc.rerereResolved/gc.rerereUnresolved Junio C Hamano
2017-08-20 21:45 ` Ramsay Jones
2017-08-21 0:20 ` Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 0/6] accept non-integer for "this many days" expiry specification Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 1/6] t4200: give us a clean slate after "rerere gc" tests Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 2/6] t4200: make "rerere gc" test more robust Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 3/6] t4200: gather "rerere gc" together Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 4/6] t4200: parameterize "rerere gc" custom expiry test Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 5/6] rerere: represent time duration in timestamp_t internally Junio C Hamano
2017-08-22 21:46 ` [PATCH v2 6/6] rerere: allow approxidate in gc.rerereResolved/gc.rerereUnresolved Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170819203013.3053-2-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=uwe.hausbrand@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.