Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorStephen P. Smith <ischis2@cox.net>2019-09-12 07:11:01 +0300
committerJunio C Hamano <gitster@pobox.com>2019-09-12 21:03:51 +0300
commit29f4332e66abf41e90d2f38e62370a42d8549c7e (patch)
treec4080bd9f5e7f2bad875eaf63fdff0dfaa79e3db /date.c
parent5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff)
Quit passing 'now' to date code
Commit b841d4ff43 (Add `human` format to test-tool, 2019-01-28) added a get_time() function which allows $GIT_TEST_DATE_NOW in the environment to override the current time. So we no longer need to interpret that variable in cmd__date(). Therefore, we can stop passing the "now" parameter down through the date functions, since nobody uses them. Note that we do need to make sure all of the previous callers that took a "now" parameter are correctly using get_time(). Signed-off-by: Stephen P. Smith <ischis2@cox.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-rw-r--r--date.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/date.c b/date.c
index 8126146c50..041db7db4e 100644
--- a/date.c
+++ b/date.c
@@ -128,16 +128,17 @@ static void get_time(struct timeval *now)
gettimeofday(now, NULL);
}
-void show_date_relative(timestamp_t time,
- const struct timeval *now,
- struct strbuf *timebuf)
+void show_date_relative(timestamp_t time, struct strbuf *timebuf)
{
+ struct timeval now;
timestamp_t diff;
- if (now->tv_sec < time) {
+
+ get_time(&now);
+ if (now.tv_sec < time) {
strbuf_addstr(timebuf, _("in the future"));
return;
}
- diff = now->tv_sec - time;
+ diff = now.tv_sec - time;
if (diff < 90) {
strbuf_addf(timebuf,
Q_("%"PRItime" second ago", "%"PRItime" seconds ago", diff), diff);
@@ -240,9 +241,7 @@ static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm
/* Show "today" times as just relative times */
if (hide.wday) {
- struct timeval now;
- get_time(&now);
- show_date_relative(time, &now, buf);
+ show_date_relative(time, buf);
return;
}
@@ -313,11 +312,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
}
if (mode->type == DATE_RELATIVE) {
- struct timeval now;
-
strbuf_reset(&timebuf);
- get_time(&now);
- show_date_relative(time, &now, &timebuf);
+ show_date_relative(time, &timebuf);
return timebuf.buf;
}
@@ -1288,15 +1284,18 @@ static timestamp_t approxidate_str(const char *date,
return (timestamp_t)update_tm(&tm, &now, 0);
}
-timestamp_t approxidate_relative(const char *date, const struct timeval *tv)
+timestamp_t approxidate_relative(const char *date)
{
+ struct timeval tv;
timestamp_t timestamp;
int offset;
int errors = 0;
if (!parse_date_basic(date, &timestamp, &offset))
return timestamp;
- return approxidate_str(date, tv, &errors);
+
+ get_time(&tv);
+ return approxidate_str(date, (const struct timeval *) &tv, &errors);
}
timestamp_t approxidate_careful(const char *date, int *error_ret)