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

[PATCH] Allow the Unix epoch to be a valid commit date

From
EWEric Wong <normalperson@yhbt.net>
Date
Jul 3, 2009, 04:34 UTC
Message-ID
<20090703043454.GA20080@dcvr.yhbt.net>
In-Reply-To
<20090703042846.GA14767@dcvr.yhbt.net>

It is common practice to use the Unix epoch as a fallback date when a suitable date is not available. This is true of git svn and possibly other importing tools that import non-git history into git.

Instead of clobbering established strtoul() error reporting semantics with our own, preserve the strtoul() error value of ULONG_MAX for fsck.c to handle.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 commit.c |    6 +-----
 fsck.c   |    2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/commit.c b/commit.c
index aa3b35b..a47fb4d 100644
--- a/commit.c
+++ b/commit.c
@@ -50,7 +50,6 @@ struct commit *lookup_commit(const unsigned char *sha1)
 
 static unsigned long parse_commit_date(const char *buf, const char *tail)
 {
-	unsigned long date;
 	const char *dateptr;
 
 	if (buf + 6 >= tail)
@@ -73,10 +72,7 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
 	if (buf >= tail)
 		return 0;
 	/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
-	date = strtoul(dateptr, NULL, 10);
-	if (date == ULONG_MAX)
-		date = 0;
-	return date;
+	return strtoul(dateptr, NULL, 10);
 }
 
 static struct commit_graft **commit_graft;
diff --git a/fsck.c b/fsck.c
index 511b82c..89278c1 100644
--- a/fsck.c
+++ b/fsck.c
@@ -229,7 +229,7 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
 	struct commit_graft *graft;
 	int parents = 0;
 
-	if (!commit->date)
+	if (commit->date == ULONG_MAX)
 		return error_func(&commit->object, FSCK_ERROR, "invalid author/committer line");
 
 	if (memcmp(buffer, "tree ", 5))
-- 
Eric Wong
Previous: Eric WongNext: Junio C Hamano
Message 3 of 4 in “git-svn producing "invalid author/committer line"”
  1. esskov@oncable.dkJul 2, 2009
  2. Eric WongJul 3, 2009
  3. Allow the Unix epoch to be a valid commit dateEric Wong, Jul 3, 2009
  4. Junio C HamanoJul 5, 2009

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.