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:03 UTC
Message-ID
<alpine.LFD.1.10.0808161543160.3324@nehalem.linux-foundation.org>
In-Reply-To
<20080816205325.GD10729@mrq1.org>
On Sat, 16 Aug 2008, Hermann Gausterer wrote:
Show 21 quoted lines
> 
> i used "stat" to get the timestamp of a file
> and set the git history to this date with
> this command:
> 
> GIT_AUTHOR_DATE=`stat -c '%y' "$FILE"`
> 
> old files (created with an older kernel)
> produced this output.
> 
> 2008-05-28 14:21:35.000000000 +0200
> 
> but new files return nanosecond resolution
> timestamps.
> 
> 2008-06-04 17:25:54.917476713 +0200
> 
> of course this resolution is NOT needed
> for git, but git DOES NOT ignore this time-
> stamps. it changes the date to something
> completly wrong :-/

Git uses a fairly odd date parsing library, and it turns out that 917476713 +0200 is actually a perfectly valid date in the git format, because one thing git allows is the "seconds since epoch" one. So doing

	[torvalds@nehalem git]$ ./test-date "917476713 +0200"
	917476713 +0200 -> 917476713 +0200 -> Wed Jan 27 14:38:33 1999
	917476713 +0200 -> Wed Jan 27 14:38:33 1999

and it turns out that git will totally ignore any other format date when i sees this standard format (yes, that is literally the format that git uses internally).

So because git date parsing doesn't even really understand fractional seconds, and thus doesn't parse it, it will take the fraction, and if it was larger than 100000000, it will assume it's a seconds-since-epoch date.

Unlucky.
Anyway, something like this should fix it.
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).
		Linus
---
Subject: Ignore fractional seconds in date parsing
From: Linus Torvalds <torvads@linux-foundation.org>

.. otherwise a nanosecond resolution fractional second might be interpreted as a seconds-since-epoch date format string and overwrite the date we so carefully just parsed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Noticed-by: Hermann Gausterer <git-mailinglist@mrq1.org>
---
 date.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/date.c b/date.c
index 35a5257..5e502da 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;
Previous: Hermann GaustererNext: Linus Torvalds
Message 2 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.