{"thread":{"id":"51817","subject":"[PATCH 0/2] Date test code clean-up","startedAt":"2019-09-09T01:54:22Z","lastAt":"2019-09-13T17:25:29Z","messageCount":12,"participants":["Stephen P. Smith","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"382057","messageId":"20190909014711.3894-1-ischis2@cox.net","threadId":"51817","inReplyTo":null,"subject":"[PATCH 0/2] Date test code clean-up","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-09T01:47:09Z","receivedAt":"2019-09-09T01:54:22Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"As part of a previous patch submission[1], a cleanup patch was\nsuggested to remove a now unnecessary passing of a date environment\nvariable to the production code.\n\nWhile the two patches in the set could easily be submitted as a single\npatch, I split the removal of the getenv() call into a second\npatch. I did that to make the comment about the initialization of `x`\nmore localized to the change.\n\n[1] https://public-inbox.org/git/xmqq5zuge2y7.fsf@gitster-ct.c.googlers.com\n\nStephen P. Smith (2):\n  Quit passing 'now' to date code\n  test_date.c: Remove reference to GIT_TEST_DATE_NOW\n\n cache.h              |  5 ++---\n date.c               | 27 +++++++++++++--------------\n t/helper/test-date.c | 27 +++++++++------------------\n 3 files changed, 24 insertions(+), 35 deletions(-)\n\n-- \n2.23.0\n\n"},{"id":"382058","messageId":"20190909014711.3894-3-ischis2@cox.net","threadId":"51817","inReplyTo":"20190909014711.3894-1-ischis2@cox.net","subject":"[PATCH 2/2] test_date.c: Remove reference to GIT_TEST_DATE_NOW","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-09T01:47:11Z","receivedAt":"2019-09-09T01:54:23Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c.\nThe intialization of variable x with the value from GIT_TEST_DATE_NOW\nis unneeded since x is initalized by skip_prefix().\n\nSigned-off-by: Stephen P. Smith <ischis2@cox.net>\n---\n t/helper/test-date.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/t/helper/test-date.c b/t/helper/test-date.c\nindex deb5869343..099eff4f0f 100644\n--- a/t/helper/test-date.c\n+++ b/t/helper/test-date.c\n@@ -104,7 +104,6 @@ static void getnanos(const char **argv)\n int cmd__date(int argc, const char **argv)\n {\n \tconst char *x;\n-\tx = getenv(\"GIT_TEST_DATE_NOW\");\n \n \targv++;\n \tif (!*argv)\n-- \n2.23.0\n\n"},{"id":"382059","messageId":"20190909014711.3894-2-ischis2@cox.net","threadId":"51817","inReplyTo":"20190909014711.3894-1-ischis2@cox.net","subject":"[PATCH 1/2] Quit passing 'now' to date code","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-09T01:47:10Z","receivedAt":"2019-09-09T01:54:32Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"As part of a previous patch set, the get_time() function was added to\ndate.c eliminating the need to pass a `now` parameter from the test\ncode.\n\nSigned-off-by: Stephen P. Smith <ischis2@cox.net>\n---\n cache.h              |  5 ++---\n date.c               | 27 +++++++++++++--------------\n t/helper/test-date.c | 26 +++++++++-----------------\n 3 files changed, 24 insertions(+), 34 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex b1da1ab08f..48d4287aa7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1516,8 +1516,7 @@ struct date_mode {\n struct date_mode *date_mode_from_type(enum date_mode_type type);\n \n const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);\n-void show_date_relative(timestamp_t time, const struct timeval *now,\n-\t\t\tstruct strbuf *timebuf);\n+void show_date_relative(timestamp_t time, struct strbuf *timebuf);\n void show_date_human(timestamp_t time, int tz, const struct timeval *now,\n \t\t\tstruct strbuf *timebuf);\n int parse_date(const char *date, struct strbuf *out);\n@@ -1526,7 +1525,7 @@ int parse_expiry_date(const char *date, timestamp_t *timestamp);\n void datestamp(struct strbuf *out);\n #define approxidate(s) approxidate_careful((s), NULL)\n timestamp_t approxidate_careful(const char *, int *);\n-timestamp_t approxidate_relative(const char *date, const struct timeval *now);\n+timestamp_t approxidate_relative(const char *date);\n void parse_date_format(const char *format, struct date_mode *mode);\n int date_overflows(timestamp_t date);\n \ndiff --git a/date.c b/date.c\nindex 8126146c50..041db7db4e 100644\n--- a/date.c\n+++ b/date.c\n@@ -128,16 +128,17 @@ static void get_time(struct timeval *now)\n \t\tgettimeofday(now, NULL);\n }\n \n-void show_date_relative(timestamp_t time,\n-\t\t\tconst struct timeval *now,\n-\t\t\tstruct strbuf *timebuf)\n+void show_date_relative(timestamp_t time, struct strbuf *timebuf)\n {\n+\tstruct timeval now;\n \ttimestamp_t diff;\n-\tif (now->tv_sec < time) {\n+\n+\tget_time(&now);\n+\tif (now.tv_sec < time) {\n \t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n \t\treturn;\n \t}\n-\tdiff = now->tv_sec - time;\n+\tdiff = now.tv_sec - time;\n \tif (diff < 90) {\n \t\tstrbuf_addf(timebuf,\n \t\t\t Q_(\"%\"PRItime\" second ago\", \"%\"PRItime\" seconds ago\", diff), diff);\n@@ -240,9 +241,7 @@ static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm\n \n \t/* Show \"today\" times as just relative times */\n \tif (hide.wday) {\n-\t\tstruct timeval now;\n-\t\tget_time(&now);\n-\t\tshow_date_relative(time, &now, buf);\n+\t\tshow_date_relative(time, buf);\n \t\treturn;\n \t}\n \n@@ -313,11 +312,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)\n \t}\n \n \tif (mode->type == DATE_RELATIVE) {\n-\t\tstruct timeval now;\n-\n \t\tstrbuf_reset(&timebuf);\n-\t\tget_time(&now);\n-\t\tshow_date_relative(time, &now, &timebuf);\n+\t\tshow_date_relative(time, &timebuf);\n \t\treturn timebuf.buf;\n \t}\n \n@@ -1288,15 +1284,18 @@ static timestamp_t approxidate_str(const char *date,\n \treturn (timestamp_t)update_tm(&tm, &now, 0);\n }\n \n-timestamp_t approxidate_relative(const char *date, const struct timeval *tv)\n+timestamp_t approxidate_relative(const char *date)\n {\n+\tstruct timeval tv;\n \ttimestamp_t timestamp;\n \tint offset;\n \tint errors = 0;\n \n \tif (!parse_date_basic(date, &timestamp, &offset))\n \t\treturn timestamp;\n-\treturn approxidate_str(date, tv, &errors);\n+\n+\tget_time(&tv);\n+\treturn approxidate_str(date, (const struct timeval *) &tv, &errors);\n }\n \n timestamp_t approxidate_careful(const char *date, int *error_ret)\ndiff --git a/t/helper/test-date.c b/t/helper/test-date.c\nindex 585347ea48..deb5869343 100644\n--- a/t/helper/test-date.c\n+++ b/t/helper/test-date.c\n@@ -12,13 +12,13 @@ static const char *usage_msg = \"\\n\"\n \"  test-tool date is64bit\\n\"\n \"  test-tool date time_t-is64bit\\n\";\n \n-static void show_relative_dates(const char **argv, struct timeval *now)\n+static void show_relative_dates(const char **argv)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tfor (; *argv; argv++) {\n \t\ttime_t t = atoi(*argv);\n-\t\tshow_date_relative(t, now, &buf);\n+\t\tshow_date_relative(t, &buf);\n \t\tprintf(\"%s -> %s\\n\", *argv, buf.buf);\n \t}\n \tstrbuf_release(&buf);\n@@ -74,20 +74,20 @@ static void parse_dates(const char **argv)\n \tstrbuf_release(&result);\n }\n \n-static void parse_approxidate(const char **argv, struct timeval *now)\n+static void parse_approxidate(const char **argv)\n {\n \tfor (; *argv; argv++) {\n \t\ttimestamp_t t;\n-\t\tt = approxidate_relative(*argv, now);\n+\t\tt = approxidate_relative(*argv);\n \t\tprintf(\"%s -> %s\\n\", *argv, show_date(t, 0, DATE_MODE(ISO8601)));\n \t}\n }\n \n-static void parse_approx_timestamp(const char **argv, struct timeval *now)\n+static void parse_approx_timestamp(const char **argv)\n {\n \tfor (; *argv; argv++) {\n \t\ttimestamp_t t;\n-\t\tt = approxidate_relative(*argv, now);\n+\t\tt = approxidate_relative(*argv);\n \t\tprintf(\"%s -> %\"PRItime\"\\n\", *argv, t);\n \t}\n }\n@@ -103,22 +103,14 @@ static void getnanos(const char **argv)\n \n int cmd__date(int argc, const char **argv)\n {\n-\tstruct timeval now;\n \tconst char *x;\n-\n \tx = getenv(\"GIT_TEST_DATE_NOW\");\n-\tif (x) {\n-\t\tnow.tv_sec = atoi(x);\n-\t\tnow.tv_usec = 0;\n-\t}\n-\telse\n-\t\tgettimeofday(&now, NULL);\n \n \targv++;\n \tif (!*argv)\n \t\tusage(usage_msg);\n \tif (!strcmp(*argv, \"relative\"))\n-\t\tshow_relative_dates(argv+1, &now);\n+\t\tshow_relative_dates(argv+1);\n \telse if (!strcmp(*argv, \"human\"))\n \t\tshow_human_dates(argv+1);\n \telse if (skip_prefix(*argv, \"show:\", &x))\n@@ -126,9 +118,9 @@ int cmd__date(int argc, const char **argv)\n \telse if (!strcmp(*argv, \"parse\"))\n \t\tparse_dates(argv+1);\n \telse if (!strcmp(*argv, \"approxidate\"))\n-\t\tparse_approxidate(argv+1, &now);\n+\t\tparse_approxidate(argv+1);\n \telse if (!strcmp(*argv, \"timestamp\"))\n-\t\tparse_approx_timestamp(argv+1, &now);\n+\t\tparse_approx_timestamp(argv+1);\n \telse if (!strcmp(*argv, \"getnanos\"))\n \t\tgetnanos(argv+1);\n \telse if (!strcmp(*argv, \"is64bit\"))\n-- \n2.23.0\n\n"},{"id":"382075","messageId":"20190909172832.GB30470@sigill.intra.peff.net","threadId":"51817","inReplyTo":"20190909014711.3894-2-ischis2@cox.net","subject":"Re: [PATCH 1/2] Quit passing 'now' to date code","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-09-09T17:28:33Z","receivedAt":"2019-09-09T17:28:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Sep 08, 2019 at 06:47:10PM -0700, Stephen P. Smith wrote:\n\n> As part of a previous patch set, the get_time() function was added to\n> date.c eliminating the need to pass a `now` parameter from the test\n> code.\n\nI'm glad to see this cleanup. I think it is worth explaining a bit more,\nthough, why this hunk in particular:\n\n> @@ -103,22 +103,14 @@ static void getnanos(const char **argv)\n>  \n>  int cmd__date(int argc, const char **argv)\n>  {\n> -\tstruct timeval now;\n>  \tconst char *x;\n> -\n>  \tx = getenv(\"GIT_TEST_DATE_NOW\");\n> -\tif (x) {\n> -\t\tnow.tv_sec = atoi(x);\n> -\t\tnow.tv_usec = 0;\n> -\t}\n> -\telse\n> -\t\tgettimeofday(&now, NULL);\n\n...is doing the right thing, since it was the site that actually used\nthe parameters that are being deleted. Maybe something like:\n\n  Commit b841d4ff43 (Add `human` format to test-tool, 2019-01-28) added\n  a get_time() function which allows $GIT_TEST_DATE_NOW in the\n  environment to override the current time. So we no longer need to\n  interpret that variable in cmd__date().\n\n  Likewise, we can stop passing the \"now\" parameter down through the\n  date functions, since nobody uses them. Note that we do need to make\n  sure all of the previous callers that took a \"now\" parameter are\n  correctly using get_time().\n\nwhich I think explains all of the hunks.\n\n-Peff\n"},{"id":"382076","messageId":"20190909172954.GC30470@sigill.intra.peff.net","threadId":"51817","inReplyTo":"20190909014711.3894-3-ischis2@cox.net","subject":"Re: [PATCH 2/2] test_date.c: Remove reference to GIT_TEST_DATE_NOW","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-09-09T17:29:54Z","receivedAt":"2019-09-09T17:29:56Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Sep 08, 2019 at 06:47:11PM -0700, Stephen P. Smith wrote:\n\n> Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c.\n> The intialization of variable x with the value from GIT_TEST_DATE_NOW\n> is unneeded since x is initalized by skip_prefix().\n\nIt took me a minute to understand what this second sentence meant. I'd\nhave actually expected \"x\" to go away, looking at the diff context.\n\nMaybe a more clear explanation would be: We can't get rid of the \"x\"\nvariable, since it serves as a generic scratch variable for parsing\nlater in the function.\n\n(I'd also probably have just rolled this into patch 1, but I'm OK with\nit either way).\n\n-Peff\n"},{"id":"382085","messageId":"xmqqh85ljp60.fsf@gitster-ct.c.googlers.com","threadId":"51817","inReplyTo":"20190909014711.3894-1-ischis2@cox.net","subject":"Re: [PATCH 0/2] Date test code clean-up","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-09T18:32:55Z","receivedAt":"2019-09-09T18:33:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Stephen P. Smith\" <ischis2@cox.net> writes:\n\n> As part of a previous patch submission[1], a cleanup patch was\n> suggested to remove a now unnecessary passing of a date environment\n> variable to the production code.\n\nIt looks like that the idea to realize that get_time() that is aware\nof GIT_TEST_DATE_NOW is always called before functions like\nshow_date_relative(), approxidate_str() and approxidate_careful(),\nand arrange it to be called in the lower level of the callchain,\nwhich makes sense to me.\n\n\nThanks for tying the loose end.\n"},{"id":"382093","messageId":"xmqqwoehi7ae.fsf@gitster-ct.c.googlers.com","threadId":"51817","inReplyTo":"20190909172954.GC30470@sigill.intra.peff.net","subject":"Re: [PATCH 2/2] test_date.c: Remove reference to GIT_TEST_DATE_NOW","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-09T19:44:25Z","receivedAt":"2019-09-09T19:44:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Sun, Sep 08, 2019 at 06:47:11PM -0700, Stephen P. Smith wrote:\n>\n>> Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c.\n>> The intialization of variable x with the value from GIT_TEST_DATE_NOW\n>> is unneeded since x is initalized by skip_prefix().\n>\n> It took me a minute to understand what this second sentence meant. I'd\n> have actually expected \"x\" to go away, looking at the diff context.\n>\n> Maybe a more clear explanation would be: We can't get rid of the \"x\"\n> variable, since it serves as a generic scratch variable for parsing\n> later in the function.\n>\n> (I'd also probably have just rolled this into patch 1, but I'm OK with\n> it either way).\n\nThanks for saying everything ;-)  I have nothing to add.\n"},{"id":"382197","messageId":"20190912041102.16266-3-ischis2@cox.net","threadId":"51817","inReplyTo":"20190912041102.16266-1-ischis2@cox.net","subject":"[PATCH v2 2/2] test_date.c: Remove reference to GIT_TEST_DATE_NOW","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-12T04:11:02Z","receivedAt":"2019-09-12T04:11:07Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c.\nWe can't get rid of the \"x\" variable, since it serves as a generic\nscratch variable for parsing later in the function.\n\nSigned-off-by: Stephen P. Smith <ischis2@cox.net>\n---\n t/helper/test-date.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/t/helper/test-date.c b/t/helper/test-date.c\nindex deb5869343..099eff4f0f 100644\n--- a/t/helper/test-date.c\n+++ b/t/helper/test-date.c\n@@ -104,7 +104,6 @@ static void getnanos(const char **argv)\n int cmd__date(int argc, const char **argv)\n {\n \tconst char *x;\n-\tx = getenv(\"GIT_TEST_DATE_NOW\");\n \n \targv++;\n \tif (!*argv)\n-- \n2.23.0\n\n"},{"id":"382198","messageId":"20190912041102.16266-1-ischis2@cox.net","threadId":"51817","inReplyTo":"20190909014711.3894-1-ischis2@cox.net","subject":"[PATCH v2 0/2] Date test code clean-up","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-12T04:11:00Z","receivedAt":"2019-09-12T04:11:07Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"As part of a previous patch submission[1], a cleanup patch was\nsuggested to remove a now unnecessary passing of a date environment\nvariable to the production code.\n\nWhile the two patches in the set could easily be submitted as a single\npatch, I split the removal of the getenv() call into a second\npatch. I did that to make the comment about the initialization of `x`\nmore localized to the change.\n\n[1] https://public-inbox.org/git/xmqq5zuge2y7.fsf@gitster-ct.c.googlers.com\n\nRange Diff:\n1:  f4170ad553 ! 1:  e2b8322d58 Quit passing 'now' to date code\n    @@ Metadata\n      ## Commit message ##\n         Quit passing 'now' to date code\n     \n    -    As part of a previous patch set, the get_time() function was added to\n    -    date.c eliminating the need to pass a `now` parameter from the test\n    -    code.\n    +    Commit b841d4ff43 (Add `human` format to test-tool, 2019-01-28) added\n    +    a get_time() function which allows $GIT_TEST_DATE_NOW in the\n    +    environment to override the current time. So we no longer need to\n    +    interpret that variable in cmd__date().\n     \n    -    This patch removes the unneeded `now` parameter.\n    +    Therefore, we can stop passing the \"now\" parameter down through the\n    +    date functions, since nobody uses them. Note that we do need to make\n    +    sure all of the previous callers that took a \"now\" parameter are\n    +    correctly using get_time().\n     \n      ## cache.h ##\n     @@ cache.h: struct date_mode {\n2:  3c7c4f1f55 ! 2:  18ec5b3b3d test_date.c: Remove reference to GIT_TEST_DATE_NOW\n    @@ Commit message\n         test_date.c: Remove reference to GIT_TEST_DATE_NOW\n     \n         Remove the reference to the GIT_TEST_DATE_NOW which is done in date.c.\n    -    The intialization of variable x with the value from GIT_TEST_DATE_NOW\n    -    is unneeded since x is initalized by skip_prefix().\n    +    We can't get rid of the \"x\" variable, since it serves as a generic\n    +    scratch variable for parsing later in the function.\n     \n      ## t/helper/test-date.c ##\n     @@ t/helper/test-date.c: static void getnanos(const char **argv)\n\n\nStephen P. Smith (2):\n  Quit passing 'now' to date code\n  test_date.c: Remove reference to GIT_TEST_DATE_NOW\n\n cache.h              |  5 ++---\n date.c               | 27 +++++++++++++--------------\n t/helper/test-date.c | 27 +++++++++------------------\n 3 files changed, 24 insertions(+), 35 deletions(-)\n\n-- \n2.23.0\n\n"},{"id":"382199","messageId":"20190912041102.16266-2-ischis2@cox.net","threadId":"51817","inReplyTo":"20190912041102.16266-1-ischis2@cox.net","subject":"[PATCH v2 1/2] Quit passing 'now' to date code","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2019-09-12T04:11:01Z","receivedAt":"2019-09-12T04:11:31Z","isPatch":true,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"Commit b841d4ff43 (Add `human` format to test-tool, 2019-01-28) added\na get_time() function which allows $GIT_TEST_DATE_NOW in the\nenvironment to override the current time. So we no longer need to\ninterpret that variable in cmd__date().\n\nTherefore, we can stop passing the \"now\" parameter down through the\ndate functions, since nobody uses them. Note that we do need to make\nsure all of the previous callers that took a \"now\" parameter are\ncorrectly using get_time().\n\nSigned-off-by: Stephen P. Smith <ischis2@cox.net>\n---\n cache.h              |  5 ++---\n date.c               | 27 +++++++++++++--------------\n t/helper/test-date.c | 26 +++++++++-----------------\n 3 files changed, 24 insertions(+), 34 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex b1da1ab08f..48d4287aa7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1516,8 +1516,7 @@ struct date_mode {\n struct date_mode *date_mode_from_type(enum date_mode_type type);\n \n const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);\n-void show_date_relative(timestamp_t time, const struct timeval *now,\n-\t\t\tstruct strbuf *timebuf);\n+void show_date_relative(timestamp_t time, struct strbuf *timebuf);\n void show_date_human(timestamp_t time, int tz, const struct timeval *now,\n \t\t\tstruct strbuf *timebuf);\n int parse_date(const char *date, struct strbuf *out);\n@@ -1526,7 +1525,7 @@ int parse_expiry_date(const char *date, timestamp_t *timestamp);\n void datestamp(struct strbuf *out);\n #define approxidate(s) approxidate_careful((s), NULL)\n timestamp_t approxidate_careful(const char *, int *);\n-timestamp_t approxidate_relative(const char *date, const struct timeval *now);\n+timestamp_t approxidate_relative(const char *date);\n void parse_date_format(const char *format, struct date_mode *mode);\n int date_overflows(timestamp_t date);\n \ndiff --git a/date.c b/date.c\nindex 8126146c50..041db7db4e 100644\n--- a/date.c\n+++ b/date.c\n@@ -128,16 +128,17 @@ static void get_time(struct timeval *now)\n \t\tgettimeofday(now, NULL);\n }\n \n-void show_date_relative(timestamp_t time,\n-\t\t\tconst struct timeval *now,\n-\t\t\tstruct strbuf *timebuf)\n+void show_date_relative(timestamp_t time, struct strbuf *timebuf)\n {\n+\tstruct timeval now;\n \ttimestamp_t diff;\n-\tif (now->tv_sec < time) {\n+\n+\tget_time(&now);\n+\tif (now.tv_sec < time) {\n \t\tstrbuf_addstr(timebuf, _(\"in the future\"));\n \t\treturn;\n \t}\n-\tdiff = now->tv_sec - time;\n+\tdiff = now.tv_sec - time;\n \tif (diff < 90) {\n \t\tstrbuf_addf(timebuf,\n \t\t\t Q_(\"%\"PRItime\" second ago\", \"%\"PRItime\" seconds ago\", diff), diff);\n@@ -240,9 +241,7 @@ static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm\n \n \t/* Show \"today\" times as just relative times */\n \tif (hide.wday) {\n-\t\tstruct timeval now;\n-\t\tget_time(&now);\n-\t\tshow_date_relative(time, &now, buf);\n+\t\tshow_date_relative(time, buf);\n \t\treturn;\n \t}\n \n@@ -313,11 +312,8 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)\n \t}\n \n \tif (mode->type == DATE_RELATIVE) {\n-\t\tstruct timeval now;\n-\n \t\tstrbuf_reset(&timebuf);\n-\t\tget_time(&now);\n-\t\tshow_date_relative(time, &now, &timebuf);\n+\t\tshow_date_relative(time, &timebuf);\n \t\treturn timebuf.buf;\n \t}\n \n@@ -1288,15 +1284,18 @@ static timestamp_t approxidate_str(const char *date,\n \treturn (timestamp_t)update_tm(&tm, &now, 0);\n }\n \n-timestamp_t approxidate_relative(const char *date, const struct timeval *tv)\n+timestamp_t approxidate_relative(const char *date)\n {\n+\tstruct timeval tv;\n \ttimestamp_t timestamp;\n \tint offset;\n \tint errors = 0;\n \n \tif (!parse_date_basic(date, &timestamp, &offset))\n \t\treturn timestamp;\n-\treturn approxidate_str(date, tv, &errors);\n+\n+\tget_time(&tv);\n+\treturn approxidate_str(date, (const struct timeval *) &tv, &errors);\n }\n \n timestamp_t approxidate_careful(const char *date, int *error_ret)\ndiff --git a/t/helper/test-date.c b/t/helper/test-date.c\nindex 585347ea48..deb5869343 100644\n--- a/t/helper/test-date.c\n+++ b/t/helper/test-date.c\n@@ -12,13 +12,13 @@ static const char *usage_msg = \"\\n\"\n \"  test-tool date is64bit\\n\"\n \"  test-tool date time_t-is64bit\\n\";\n \n-static void show_relative_dates(const char **argv, struct timeval *now)\n+static void show_relative_dates(const char **argv)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tfor (; *argv; argv++) {\n \t\ttime_t t = atoi(*argv);\n-\t\tshow_date_relative(t, now, &buf);\n+\t\tshow_date_relative(t, &buf);\n \t\tprintf(\"%s -> %s\\n\", *argv, buf.buf);\n \t}\n \tstrbuf_release(&buf);\n@@ -74,20 +74,20 @@ static void parse_dates(const char **argv)\n \tstrbuf_release(&result);\n }\n \n-static void parse_approxidate(const char **argv, struct timeval *now)\n+static void parse_approxidate(const char **argv)\n {\n \tfor (; *argv; argv++) {\n \t\ttimestamp_t t;\n-\t\tt = approxidate_relative(*argv, now);\n+\t\tt = approxidate_relative(*argv);\n \t\tprintf(\"%s -> %s\\n\", *argv, show_date(t, 0, DATE_MODE(ISO8601)));\n \t}\n }\n \n-static void parse_approx_timestamp(const char **argv, struct timeval *now)\n+static void parse_approx_timestamp(const char **argv)\n {\n \tfor (; *argv; argv++) {\n \t\ttimestamp_t t;\n-\t\tt = approxidate_relative(*argv, now);\n+\t\tt = approxidate_relative(*argv);\n \t\tprintf(\"%s -> %\"PRItime\"\\n\", *argv, t);\n \t}\n }\n@@ -103,22 +103,14 @@ static void getnanos(const char **argv)\n \n int cmd__date(int argc, const char **argv)\n {\n-\tstruct timeval now;\n \tconst char *x;\n-\n \tx = getenv(\"GIT_TEST_DATE_NOW\");\n-\tif (x) {\n-\t\tnow.tv_sec = atoi(x);\n-\t\tnow.tv_usec = 0;\n-\t}\n-\telse\n-\t\tgettimeofday(&now, NULL);\n \n \targv++;\n \tif (!*argv)\n \t\tusage(usage_msg);\n \tif (!strcmp(*argv, \"relative\"))\n-\t\tshow_relative_dates(argv+1, &now);\n+\t\tshow_relative_dates(argv+1);\n \telse if (!strcmp(*argv, \"human\"))\n \t\tshow_human_dates(argv+1);\n \telse if (skip_prefix(*argv, \"show:\", &x))\n@@ -126,9 +118,9 @@ int cmd__date(int argc, const char **argv)\n \telse if (!strcmp(*argv, \"parse\"))\n \t\tparse_dates(argv+1);\n \telse if (!strcmp(*argv, \"approxidate\"))\n-\t\tparse_approxidate(argv+1, &now);\n+\t\tparse_approxidate(argv+1);\n \telse if (!strcmp(*argv, \"timestamp\"))\n-\t\tparse_approx_timestamp(argv+1, &now);\n+\t\tparse_approx_timestamp(argv+1);\n \telse if (!strcmp(*argv, \"getnanos\"))\n \t\tgetnanos(argv+1);\n \telse if (!strcmp(*argv, \"is64bit\"))\n-- \n2.23.0\n\n"},{"id":"382281","messageId":"20190913050809.GA28353@sigill.intra.peff.net","threadId":"51817","inReplyTo":"20190912041102.16266-1-ischis2@cox.net","subject":"Re: [PATCH v2 0/2] Date test code clean-up","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-09-13T05:08:10Z","receivedAt":"2019-09-13T05:08:12Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 11, 2019 at 09:11:00PM -0700, Stephen P. Smith wrote:\n\n> Range Diff:\n> 1:  f4170ad553 ! 1:  e2b8322d58 Quit passing 'now' to date code\n> [...]\n\nThanks, this version addresses all of my concerns from v1 (and overall\nlooks good).\n\n-Peff\n"},{"id":"382312","messageId":"xmqqwoecds73.fsf@gitster-ct.c.googlers.com","threadId":"51817","inReplyTo":"20190913050809.GA28353@sigill.intra.peff.net","subject":"Re: [PATCH v2 0/2] Date test code clean-up","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-13T17:25:20Z","receivedAt":"2019-09-13T17:25:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Sep 11, 2019 at 09:11:00PM -0700, Stephen P. Smith wrote:\n>\n>> Range Diff:\n>> 1:  f4170ad553 ! 1:  e2b8322d58 Quit passing 'now' to date code\n>> [...]\n>\n> Thanks, this version addresses all of my concerns from v1 (and overall\n> looks good).\n\nYup, the result of applying these look good.\n\nThanks, both.\n"}]}