From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 037AF1F667 for ; Sat, 19 Aug 2017 20:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751614AbdHSUgq (ORCPT ); Sat, 19 Aug 2017 16:36:46 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:59414 "EHLO sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751535AbdHSUgq (ORCPT ); Sat, 19 Aug 2017 16:36:46 -0400 X-Greylist: delayed 383 seconds by postgrey-1.27 at vger.kernel.org; Sat, 19 Aug 2017 16:36:46 EDT Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 3D5FB8E99B; Sat, 19 Aug 2017 16:30:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=sasl; bh=Py/y tAdp5nheLyKjfpARRDH3/i4=; b=Vdw3bcctGbspsV+aEyVnPSg7ISjLSy2Up3SD z/uZe8LIwi498O9V116Nk6jjAmYz5Am9CJlSa5i1n4/EStxDUgMSHHUoDF2up6f0 ZKt6AcQD8jKX6X2bYwEiUUVLomtat53cPuuuAjzdX1Nz6AQnEG3nbxyqwt7bWNzp +AO8ehs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; q=dns; s=sasl; b= MRrSNvJMvNd5DrnMKlzlBoJSG0Jwo73r1XkXMFx7oX79SkTgwH/uCdsNptB9SSVg ZFioXJT2espldQVRInu+v4/HqMqLKYDp3oKtXjsMhXp1Lo2GDHS4l8eYWTkUJvdn sgs/aBVL79Ix1NPCmNte3XzhXh0XaC1v3WVYuO647sQ= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 359348E99A; Sat, 19 Aug 2017 16:30:17 -0400 (EDT) Received: from pobox.com (unknown [104.132.0.95]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 93EC78E995; Sat, 19 Aug 2017 16:30:16 -0400 (EDT) From: Junio C Hamano To: git@vger.kernel.org Cc: Uwe Hausbrand Subject: [PATCH 1/2] rerere: represent time duration in timestamp_t internally Date: Sat, 19 Aug 2017 13:30:12 -0700 Message-Id: <20170819203013.3053-2-gitster@pobox.com> X-Mailer: git-send-email 2.14.1-405-g52c75fc716 In-Reply-To: <20170819203013.3053-1-gitster@pobox.com> References: <20170819203013.3053-1-gitster@pobox.com> X-Pobox-Relay-ID: 36182524-851D-11E7-B59E-FE4B1A68708C-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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