From: Junio C Hamano <gitster@pobox.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Hermann Gausterer <git-mailinglist@mrq1.org>,
Git Mailinglist <git@vger.kernel.org>
Subject: Re: [BUG] minor: wrong handling of GIT_AUTHOR_DATE
Date: Sat, 16 Aug 2008 20:13:42 -0700 [thread overview]
Message-ID: <7vk5egbaft.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vr68obbpd.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Sat, 16 Aug 2008 19:46:22 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> You've taught people here and on the kernel list that the "date" can use
> any non-digit-non-word as a word separator, and "git log --since 2.days"
> is something you often do.
>
> People who followed that advice would have gotten used to this already, e.g.
>
> $ git reflog delete master@{07.04.2005.15:15:00.-0700}
>
> should not be broken.
>
> I think your first hunk needs to distinguish between "very-long-precision
> posint" (in which case we ignore because it is likely to be nanoseconds
> fraction) and others.
Perhaps like this.
-- >8 --
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat, 16 Aug 2008 16:17:50 -0700
Subject: [PATCH] date parsing: do not mistake fractional nanosecond that follow HH:MM:SS
Some program output nanosecond fractional after the usual HH:MM:SS format.
If the fraction is large enough, it can be interpreted as the seconds
since epoch, and can overwrite the already parsed date/time.
We also make sure we use the seconds since epoch interpretation only when
we have not seen any other date/time data in the input yet.
Note that we cannot unconditionally drop anything that follows '.'; people
have been taught that we allow '.' as a word separator and have got used
to formats like "--since 2.days" and "2008.08.16.01:23:45.-0700" to work.
Noticed-by: Hermann Gausterer
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
date.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/date.c b/date.c
index 35a5257..b2c5a8b 100644
--- a/date.c
+++ b/date.c
@@ -363,6 +363,11 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
tm->tm_hour = num;
tm->tm_min = num2;
tm->tm_sec = num3;
+ if (*end == '.') {
+ num = strspn(end+1, "0123456789");
+ if (9 <= num)
+ end += num + 1;
+ }
break;
}
return 0;
@@ -402,6 +407,15 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
return end - date;
}
+/* Have we filled in any part of the time/date yet? */
+static inline int nodate(struct tm *tm)
+{
+ return tm->tm_year < 0 &&
+ tm->tm_mon < 0 &&
+ tm->tm_mday < 0 &&
+ !(tm->tm_hour | tm->tm_min | tm->tm_sec);
+}
+
/*
* We've seen a digit. Time? Year? Date?
*/
@@ -418,7 +432,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
* more than 8 digits. This is because we don't want to rule out
* numbers like 20070606 as a YYYYMMDD date.
*/
- if (num >= 100000000) {
+ if (num >= 100000000 && nodate(tm)) {
time_t time = num;
if (gmtime_r(&time, tm)) {
*tm_gmt = 1;
--
1.6.0.rc3.17.gc14c8
next prev parent reply other threads:[~2008-08-17 3:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-16 20:53 [BUG] minor: wrong handling of GIT_AUTHOR_DATE Hermann Gausterer
2008-08-16 23:03 ` Linus Torvalds
2008-08-16 23:17 ` Linus Torvalds
2008-08-17 2:46 ` Junio C Hamano
2008-08-17 3:13 ` Junio C Hamano [this message]
2008-08-17 4:25 ` Linus Torvalds
2008-08-17 4:37 ` Linus Torvalds
2008-08-17 5:27 ` Junio C Hamano
2008-08-17 16:07 ` Linus Torvalds
2008-08-17 3:50 ` Linus Torvalds
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=7vk5egbaft.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git-mailinglist@mrq1.org \
--cc=git@vger.kernel.org \
--cc=torvalds@linux-foundation.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