From: Jeff King <peff@peff.net>
To: Colin Smith <colin.webdev@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] pass TIME_DATE_NOW to approxidate future-check
Date: Thu, 13 Nov 2014 06:04:52 -0500 [thread overview]
Message-ID: <20141113110452.GA4386@peff.net> (raw)
In-Reply-To: <20141113110325.GD8329@peff.net>
The approxidate functions accept an extra "now" parameter to
avoid calling time() themselves. We use this in our test
suite to make sure we have a consistent time for computing
relative dates. However, deep in the bowels of approxidate,
we also call time() to check whether possible dates are far
in the future. Let's make sure that the "now" override makes
it to that spot, too, so we can consistently test that
feature.
Signed-off-by: Jeff King <peff@peff.net>
---
This code path also gets called from the more-strict parse_date (which
does not know about the current time). This continues to call time()
dynamically, but it is not clear to me if that ever actually matters in
practice.
date.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/date.c b/date.c
index 59dfe57..e1a4d49 100644
--- a/date.c
+++ b/date.c
@@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
return 0;
}
-static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
+static int match_multi_number(unsigned long num, char c, const char *date,
+ char *end, struct tm *tm, time_t now)
{
- time_t now;
struct tm now_tm;
struct tm *refuse_future;
long num2, num3;
@@ -433,7 +433,8 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
case '-':
case '/':
case '.':
- now = time(NULL);
+ if (!now)
+ now = time(NULL);
refuse_future = NULL;
if (gmtime_r(&now, &now_tm))
refuse_future = &now_tm;
@@ -513,7 +514,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
case '/':
case '-':
if (isdigit(end[1])) {
- int match = match_multi_number(num, *end, date, end, tm);
+ int match = match_multi_number(num, *end, date, end, tm, 0);
if (match)
return match;
}
@@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
return end;
}
-static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
+static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
+ time_t now)
{
char *end;
unsigned long number = strtoul(date, &end, 10);
@@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
case '/':
case '-':
if (isdigit(end[1])) {
- int match = match_multi_number(number, *end, date, end, tm);
+ int match = match_multi_number(number, *end, date, end,
+ tm, now);
if (match)
return date + match;
}
@@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date,
date++;
if (isdigit(c)) {
pending_number(&tm, &number);
- date = approxidate_digit(date-1, &tm, &number);
+ date = approxidate_digit(date-1, &tm, &number, time_sec);
touched = 1;
continue;
}
--
2.1.2.596.g7379948
next prev parent reply other threads:[~2014-11-13 11:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-13 0:27 Bug: git log showing nothing when using --since and --until flags with specific dates Colin Smith
2014-11-13 9:36 ` Jeff King
2014-11-13 11:03 ` [PATCH 0/2] approxidate and future ISO-like times Jeff King
2014-11-13 11:04 ` Jeff King [this message]
2014-11-13 11:07 ` [PATCH 2/2] approxidate: allow ISO-like dates far in the future Jeff King
2014-11-13 21:11 ` Junio C Hamano
2014-11-13 21:36 ` Jeff King
2014-11-13 21:43 ` Jeff King
2014-11-13 22:36 ` Junio C Hamano
[not found] ` <CA+EOSBn0-ZFOPaeU92a0YWPW_S9kenoRUjJMp-Nhm-azftrEfA@mail.gmail.com>
2014-11-14 8:47 ` Jeff King
2014-11-14 22:15 ` Junio C Hamano
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=20141113110452.GA4386@peff.net \
--to=peff@peff.net \
--cc=colin.webdev@gmail.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).