From patchwork Thu Sep 12 04:11:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stephen P. Smith" X-Patchwork-Id: 11142115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB9ED76 for ; Thu, 12 Sep 2019 04:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 944E721479 for ; Thu, 12 Sep 2019 04:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725972AbfILELH (ORCPT ); Thu, 12 Sep 2019 00:11:07 -0400 Received: from omta015.useast.a.cloudfilter.net ([34.195.253.206]:46123 "EHLO omta015.useast.a.cloudfilter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbfILELH (ORCPT ); Thu, 12 Sep 2019 00:11:07 -0400 Received: from cxr.smtp.a.cloudfilter.net ([10.0.17.147]) by cmsmtp with ESMTP id 87BLiLEvVLe2C8GRliMz4n; Thu, 12 Sep 2019 04:11:05 +0000 Received: from thunderbird.smith.home ([68.231.71.156]) by cmsmtp with ESMTPSA id 8GRiis8U8AqrF8GRjijY2N; Thu, 12 Sep 2019 04:11:05 +0000 Authentication-Results: cox.net; auth=pass (LOGIN) smtp.auth=ischis2@cox.net X-Authority-Analysis: v=2.3 cv=BdimLYl2 c=1 sm=1 tr=0 a=3BwGCz7hYCwPRAPwzRnSaA==:117 a=3BwGCz7hYCwPRAPwzRnSaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=J70Eh1EUuV4A:10 a=kviXuzpPAAAA:8 a=SgNXyPVP_kuMGiK11z4A:9 a=qrIFiuKZe2vaD64auk6j:22 Received: from thunderbird.smith.home (localhost [127.0.0.1]) by thunderbird.smith.home (Postfix) with ESMTP id 59921B81A82; Wed, 11 Sep 2019 21:11:02 -0700 (MST) From: "Stephen P. Smith" To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 1/2] Quit passing 'now' to date code Date: Wed, 11 Sep 2019 21:11:01 -0700 Message-Id: <20190912041102.16266-2-ischis2@cox.net> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190912041102.16266-1-ischis2@cox.net> References: <20190909014711.3894-1-ischis2@cox.net> <20190912041102.16266-1-ischis2@cox.net> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfBct3j+FzZ++f5tcO1giIj7kGpe1EzTSEbCqpuvDOJmCBO/oVUF67jmfnnODkRIb8xWbmKD1HUwn99iTmwdzvUPfypjrGI98CM7NpaSWL7nTVKwTIOrn c5kkchWmf/0IxEeh7nayaQL2l7tvcxExOvu5jyxG76lmBi7loV6I0E/icR9+3vvCPBYZrTraGwCqj0q1OU3dAfgByFkbPlvlFaITeiHgwZZXhf5FQMsnFzl5 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- cache.h | 5 ++--- date.c | 27 +++++++++++++-------------- t/helper/test-date.c | 26 +++++++++----------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/cache.h b/cache.h index b1da1ab08f..48d4287aa7 100644 --- a/cache.h +++ b/cache.h @@ -1516,8 +1516,7 @@ struct date_mode { struct date_mode *date_mode_from_type(enum date_mode_type type); const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode); -void show_date_relative(timestamp_t time, const struct timeval *now, - struct strbuf *timebuf); +void show_date_relative(timestamp_t time, struct strbuf *timebuf); void show_date_human(timestamp_t time, int tz, const struct timeval *now, struct strbuf *timebuf); int parse_date(const char *date, struct strbuf *out); @@ -1526,7 +1525,7 @@ int parse_expiry_date(const char *date, timestamp_t *timestamp); void datestamp(struct strbuf *out); #define approxidate(s) approxidate_careful((s), NULL) timestamp_t approxidate_careful(const char *, int *); -timestamp_t approxidate_relative(const char *date, const struct timeval *now); +timestamp_t approxidate_relative(const char *date); void parse_date_format(const char *format, struct date_mode *mode); int date_overflows(timestamp_t date); 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, ×tamp, &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) diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 585347ea48..deb5869343 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -12,13 +12,13 @@ static const char *usage_msg = "\n" " test-tool date is64bit\n" " test-tool date time_t-is64bit\n"; -static void show_relative_dates(const char **argv, struct timeval *now) +static void show_relative_dates(const char **argv) { struct strbuf buf = STRBUF_INIT; for (; *argv; argv++) { time_t t = atoi(*argv); - show_date_relative(t, now, &buf); + show_date_relative(t, &buf); printf("%s -> %s\n", *argv, buf.buf); } strbuf_release(&buf); @@ -74,20 +74,20 @@ static void parse_dates(const char **argv) strbuf_release(&result); } -static void parse_approxidate(const char **argv, struct timeval *now) +static void parse_approxidate(const char **argv) { for (; *argv; argv++) { timestamp_t t; - t = approxidate_relative(*argv, now); + t = approxidate_relative(*argv); printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601))); } } -static void parse_approx_timestamp(const char **argv, struct timeval *now) +static void parse_approx_timestamp(const char **argv) { for (; *argv; argv++) { timestamp_t t; - t = approxidate_relative(*argv, now); + t = approxidate_relative(*argv); printf("%s -> %"PRItime"\n", *argv, t); } } @@ -103,22 +103,14 @@ static void getnanos(const char **argv) int cmd__date(int argc, const char **argv) { - struct timeval now; const char *x; - x = getenv("GIT_TEST_DATE_NOW"); - if (x) { - now.tv_sec = atoi(x); - now.tv_usec = 0; - } - else - gettimeofday(&now, NULL); argv++; if (!*argv) usage(usage_msg); if (!strcmp(*argv, "relative")) - show_relative_dates(argv+1, &now); + show_relative_dates(argv+1); else if (!strcmp(*argv, "human")) show_human_dates(argv+1); else if (skip_prefix(*argv, "show:", &x)) @@ -126,9 +118,9 @@ int cmd__date(int argc, const char **argv) else if (!strcmp(*argv, "parse")) parse_dates(argv+1); else if (!strcmp(*argv, "approxidate")) - parse_approxidate(argv+1, &now); + parse_approxidate(argv+1); else if (!strcmp(*argv, "timestamp")) - parse_approx_timestamp(argv+1, &now); + parse_approx_timestamp(argv+1); else if (!strcmp(*argv, "getnanos")) getnanos(argv+1); else if (!strcmp(*argv, "is64bit")) From patchwork Thu Sep 12 04:11:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stephen P. Smith" X-Patchwork-Id: 11142113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76986112B for ; Thu, 12 Sep 2019 04:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 533A821479 for ; Thu, 12 Sep 2019 04:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725834AbfILELG (ORCPT ); Thu, 12 Sep 2019 00:11:06 -0400 Received: from omta015.useast.a.cloudfilter.net ([34.195.253.206]:39314 "EHLO omta015.useast.a.cloudfilter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbfILELG (ORCPT ); Thu, 12 Sep 2019 00:11:06 -0400 Received: from cxr.smtp.a.cloudfilter.net ([10.0.17.210]) by cmsmtp with ESMTP id 7zqziKc96Le2C8GRliMz4l; Thu, 12 Sep 2019 04:11:05 +0000 Received: from thunderbird.smith.home ([68.231.71.156]) by cmsmtp with ESMTPSA id 8GRiioeTaQvl08GRkiSmsP; Thu, 12 Sep 2019 04:11:05 +0000 Authentication-Results: cox.net; auth=pass (LOGIN) smtp.auth=ischis2@cox.net X-Authority-Analysis: v=2.3 cv=dvOl9Go4 c=1 sm=1 tr=0 a=3BwGCz7hYCwPRAPwzRnSaA==:117 a=3BwGCz7hYCwPRAPwzRnSaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=J70Eh1EUuV4A:10 a=kviXuzpPAAAA:8 a=yx_lj6salmlCj44auFUA:9 a=qrIFiuKZe2vaD64auk6j:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 Received: from thunderbird.smith.home (localhost [127.0.0.1]) by thunderbird.smith.home (Postfix) with ESMTP id 71EE5B81BD2; Wed, 11 Sep 2019 21:11:02 -0700 (MST) From: "Stephen P. Smith" To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 2/2] test_date.c: Remove reference to GIT_TEST_DATE_NOW Date: Wed, 11 Sep 2019 21:11:02 -0700 Message-Id: <20190912041102.16266-3-ischis2@cox.net> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190912041102.16266-1-ischis2@cox.net> References: <20190909014711.3894-1-ischis2@cox.net> <20190912041102.16266-1-ischis2@cox.net> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfI5gi76S2drm/XgV/Ui4udRXDtUPJ1CUvQoQZFokMApwFmtOSakjS3PkkwSlJ2Pd1I1+T+vEbre7ziwCIz1bWPg6IdSZqVaGZFmwLAqOo9MyNZZhzIsl VnrqutzxKaM/H7NIgw2cxSRpURLLNmkptltQco+HXkwqw7SnxdXkFcvKYYrf7LIq5bQzuCMztjuGRxrN2V/2fI46t4HEaAvbB9xCH7SnkGE+XtqhmxAuqUns Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c. We can't get rid of the "x" variable, since it serves as a generic scratch variable for parsing later in the function. Signed-off-by: Stephen P. Smith --- t/helper/test-date.c | 1 - 1 file changed, 1 deletion(-) diff --git a/t/helper/test-date.c b/t/helper/test-date.c index deb5869343..099eff4f0f 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -104,7 +104,6 @@ static void getnanos(const char **argv) int cmd__date(int argc, const char **argv) { const char *x; - x = getenv("GIT_TEST_DATE_NOW"); argv++; if (!*argv)