From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, christian.couder@gmail.com, peff@peff.net,
sunshine@sunshineco.com
Subject: [PATCH 2/2] read-cache: use time_t instead of unsigned long
Date: Mon, 12 Nov 2018 23:40:17 -0800 [thread overview]
Message-ID: <20181113074017.17292-1-carenas@gmail.com> (raw)
In-Reply-To: <xmqq7ehi1gpb.fsf@gitster-ct.c.googlers.com>
There are still some more possible improvements around this code but
they are orthogonal to this change :
* migrate to approxidate_careful or parse_expiry_date
* maybe make sure only approxidate are used for expiration
Changes in v2:
* improved commit message as suggested by Eric
* failsafe against time_t truncation as suggested by Junio
-- >8 --
Subject: [PATCH v2 2/2] read-cache: use time specific types instead of
unsigned long
b968372279 ("read-cache: unlink old sharedindex files", 2017-03-06)
introduced get_shared_index_expire_date using unsigned long to track
the modification times of a shared index.
dddbad728c ("timestamp_t: a new data type for timestamps", 2017-04-26)
shows why that might be problematic so move to timestamp_t/time_t.
if time_t can't represent a valid time keep the indexes for failsafe
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
read-cache.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 7b1354d759..7d322f11c8 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2625,9 +2625,9 @@ static int write_split_index(struct index_state *istate,
static const char *shared_index_expire = "2.weeks.ago";
-static unsigned long get_shared_index_expire_date(void)
+static timestamp_t get_shared_index_expire_date(void)
{
- static unsigned long shared_index_expire_date;
+ static timestamp_t shared_index_expire_date;
static int shared_index_expire_date_prepared;
if (!shared_index_expire_date_prepared) {
@@ -2643,12 +2643,12 @@ static unsigned long get_shared_index_expire_date(void)
static int should_delete_shared_index(const char *shared_index_path)
{
struct stat st;
- unsigned long expiration;
+ time_t expiration;
+ timestamp_t t = get_shared_index_expire_date();
- /* Check timestamp */
- expiration = get_shared_index_expire_date();
- if (!expiration)
+ if (!t || date_overflows(t))
return 0;
+ expiration = t;
if (stat(shared_index_path, &st))
return error_errno(_("could not stat '%s'"), shared_index_path);
if (st.st_mtime > expiration)
--
2.19.1.856.g8858448bb
next prev parent reply other threads:[~2018-11-13 7:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-12 8:40 [PATCH 0/2] avoid unsigned long for timestamps Carlo Marcelo Arenas Belón
2018-11-12 8:40 ` [PATCH 1/2] builtin/commit: use timestamp_t in parse_force_date Carlo Marcelo Arenas Belón
2018-11-12 8:40 ` [PATCH 2/2] read-cache: use time_t instead of unsigned long Carlo Marcelo Arenas Belón
2018-11-12 8:42 ` Eric Sunshine
2018-11-12 10:53 ` Junio C Hamano
2018-11-12 14:54 ` Johannes Schindelin
2018-11-12 15:03 ` Junio C Hamano
2018-11-13 7:40 ` Carlo Marcelo Arenas Belón [this message]
2018-11-13 8:49 ` Johannes Schindelin
2018-11-13 9:10 ` Carlo Arenas
2018-11-13 9:43 ` Junio C Hamano
2018-11-12 12:06 ` [PATCH 0/2] avoid unsigned long for timestamps Johannes Schindelin
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181113074017.17292-1-carenas@gmail.com \
--to=carenas@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).