git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] minor: wrong handling of GIT_AUTHOR_DATE

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 16, 2008, 23:17 UTC
Message-ID
<alpine.LFD.1.10.0808161613520.3324@nehalem.linux-foundation.org>
In-Reply-To
<alpine.LFD.1.10.0808161543160.3324@nehalem.linux-foundation.org>
On Sat, 16 Aug 2008, Linus Torvalds wrote:
Show 5 quoted lines
> 
> Junio: we might also make the code that actually parses the 
> seconds-per-epoch thing only trigger if we haven't already seen a date (ie 
> it might check for "tm->tm_year < 0" etc before accepting that seconds 
> format).

Here's a slightly expanded version of the previous patch, which will ignore those big integer if it has already seen any human-readable date format (either any time except 0:00:00 or any normal date).

It includes the fractional second parsing code from the previous patch too, since that's an independent thing and makes sense regardless.

Junio, your call. But this one gets the date right for strings that just randomly have some big number in them, ie

	[torvalds@nehalem git]$ ./test-date "17:25:54 917476713 2008-06-04 -0700"
	17:25:54 917476713 2008-06-04 -0700 -> 1212625554 -0700 -> Wed Jun  4 17:25:54 2008
	17:25:54 917476713 2008-06-04 -0700 -> Wed Jun  4 17:25:54 2008

because it will now see that "nodate()" is not true. I think it's a good idea to only accept the epoch format when there hasn't been any other time format visible.

			Linus
---
 date.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/date.c b/date.c
index 35a5257..e11e78e 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;
+
+			/* Ignore any possible fractional seconds */
+			if (*end == '.')
+				(void) strtol(end+1, &end, 10);
+
 			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;
Previous: Linus TorvaldsNext: Junio C Hamano
Message 3 of 10 in “[BUG] minor: wrong handling of GIT_AUTHOR_DATE”
  1. Hermann GaustererAug 16, 2008
  2. Linus TorvaldsAug 16, 2008
  3. Linus TorvaldsAug 16, 2008
  4. Junio C HamanoAug 17, 2008
  5. Junio C HamanoAug 17, 2008
  6. Linus TorvaldsAug 17, 2008
  7. Linus TorvaldsAug 17, 2008
  8. Junio C HamanoAug 17, 2008
  9. Linus TorvaldsAug 17, 2008
  10. Linus TorvaldsAug 17, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.