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@xxxxxxxx> > 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; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html