From: Jeff King <peff@peff.net>
To: David Reiss <dreiss@facebook.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Round-down years in "years+months" relative date view
Date: Fri, 28 Aug 2009 02:05:38 -0400 [thread overview]
Message-ID: <20090828060538.GA22416@coredump.intra.peff.net> (raw)
In-Reply-To: <4A97193A.8090502@facebook.com>
On Thu, Aug 27, 2009 at 04:39:38PM -0700, David Reiss wrote:
> Previously, a commit from 1 year and 7 months ago would display as
> "2 years, 7 months ago".
Wow, embarrassing.
Acked-by: Jeff King <peff@peff.net>
> Here's my test script. Let me know if you'd rather have it as part
> of the test suite.
I couldn't find any tests related to relative date processing, so it
would be really nice to have some. But I'm not sure of the best way to
do it without dealing with race conditions. Annoyingly, show_date calls
gettimeofday at a pretty low level, so there isn't a way of
instrumenting it short of LD_PRELOAD trickery (which is probably not
very portable).
But maybe a patch like this is worth doing, which would allow us to test
in a repeatable fashion:
---
diff --git a/date.c b/date.c
index e848d96..db2f831 100644
--- a/date.c
+++ b/date.c
@@ -86,6 +86,33 @@ static int local_tzoffset(unsigned long time)
return offset * eastwest;
}
+static int current_time(struct timeval *now)
+{
+ static struct timeval fake_time;
+ static int use_fake_time = -1;
+
+ if (use_fake_time == -1) {
+ const char *x = getenv("GIT_FAKE_TIME");
+ if (x) {
+ char buf[50];
+ if (parse_date(x, buf, sizeof(buf)) <= 0)
+ die("unable to parse GIT_FAKE_TIME");
+ fake_time.tv_sec = strtoul(buf, NULL, 10);
+ fake_time.tv_usec = 0;
+ use_fake_time = 1;
+ }
+ else
+ use_fake_time = 0;
+ }
+
+ if (use_fake_time == 1) {
+ memcpy(now, &fake_time, sizeof(*now));
+ return 0;
+ }
+
+ return gettimeofday(now, NULL);
+}
+
const char *show_date(unsigned long time, int tz, enum date_mode mode)
{
struct tm *tm;
@@ -99,7 +126,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
if (mode == DATE_RELATIVE) {
unsigned long diff;
struct timeval now;
- gettimeofday(&now, NULL);
+ current_time(&now);
if (now.tv_sec < time)
return "in the future";
diff = now.tv_sec - time;
@@ -929,7 +956,7 @@ unsigned long approxidate(const char *date)
if (parse_date(date, buffer, sizeof(buffer)) > 0)
return strtoul(buffer, NULL, 10);
- gettimeofday(&tv, NULL);
+ current_time(&tv);
time_sec = tv.tv_sec;
localtime_r(&time_sec, &tm);
now = tm;
next prev parent reply other threads:[~2009-08-28 6:06 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-27 23:39 [PATCH] Round-down years in "years+months" relative date view David Reiss
2009-08-28 6:05 ` Jeff King [this message]
2009-08-28 7:58 ` Alex Riesen
2009-08-28 15:02 ` Jeff King
2009-08-28 17:00 ` Alex Riesen
2009-08-28 17:15 ` Jeff King
2009-08-28 18:21 ` Alex Riesen
2009-08-28 22:01 ` A Large Angry SCM
2009-08-28 17:28 ` Nicolas Pitre
2009-08-28 18:01 ` Jeff King
2009-08-28 18:27 ` Alex Riesen
2009-08-28 18:39 ` Jeff King
2009-08-28 18:42 ` Alex Riesen
2009-08-28 18:49 ` Alex Riesen
2009-08-28 19:00 ` Nicolas Pitre
2009-08-28 19:08 ` Alex Riesen
2009-08-28 19:27 ` Nicolas Pitre
2009-08-28 19:49 ` Alex Riesen
2009-08-28 20:01 ` Nicolas Pitre
2009-08-28 19:03 ` Alex Riesen
2009-08-28 19:15 ` Jeff King
2009-08-28 19:20 ` Alex Riesen
2009-08-28 19:33 ` Alex Riesen
2009-08-28 20:52 ` [PATCH] Allow testing of _relative family of time formatting and parsing functions Alex Riesen
2009-08-28 20:54 ` Alex Riesen
2009-08-29 21:46 ` Junio C Hamano
2009-08-30 7:25 ` Alex Riesen
2009-08-30 7:51 ` Jeff King
2009-08-30 8:10 ` Alex Riesen
2009-08-30 9:13 ` [PATCH 1/2] Add date formatting and parsing functions relative to a given time Alex Riesen
2009-08-30 9:15 ` [PATCH 2/2] Allow testing of _relative family of time formatting and parsing functions Alex Riesen
2009-08-30 9:15 ` [PATCH 1/2] Add date formatting and parsing functions relative to a given time Jeff King
2009-08-30 9:36 ` Jeff King
2009-08-30 9:56 ` Alex Riesen
2009-08-30 10:08 ` Jeff King
2009-08-30 11:17 ` Alex Riesen
2009-08-30 21:43 ` [PATCH 1/3] " Jeff King
2009-08-30 21:51 ` Jeff King
2009-08-31 2:22 ` Jeff King
2009-08-31 2:26 ` [PATCH v2 1/4] " Jeff King
2009-08-31 6:08 ` Alex Riesen
2009-08-31 2:26 ` [PATCH v2 2/4] refactor test-date interface Jeff King
2009-08-31 2:30 ` [PATCH v2 3/4] tests: add date printing and parsing tests Jeff King
2009-09-01 3:03 ` Jeff King
2009-08-31 2:31 ` [PATCH v2 4/4] fix approxidate parsing of relative months and years Jeff King
2009-08-30 21:46 ` [PATCH 2/3] refactor test-date interface Jeff King
2009-08-30 21:47 ` [PATCH 3/3] tests: add date printing and parsing tests Jeff King
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=20090828060538.GA22416@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=dreiss@facebook.com \
--cc=git@vger.kernel.org \
/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 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 NNTP newsgroup(s).