Skip to content

Commit f290974

Browse files
Eric Wonggitster
authored andcommitted
Allow the Unix epoch to be a valid commit date
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8400d9 commit f290974

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

commit.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct commit *lookup_commit(const unsigned char *sha1)
5050

5151
static unsigned long parse_commit_date(const char *buf, const char *tail)
5252
{
53-
unsigned long date;
5453
const char *dateptr;
5554

5655
if (buf + 6 >= tail)
@@ -73,10 +72,7 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
7372
if (buf >= tail)
7473
return 0;
7574
/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
76-
date = strtoul(dateptr, NULL, 10);
77-
if (date == ULONG_MAX)
78-
date = 0;
79-
return date;
75+
return strtoul(dateptr, NULL, 10);
8076
}
8177

8278
static struct commit_graft **commit_graft;

fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
229229
struct commit_graft *graft;
230230
int parents = 0;
231231

232-
if (!commit->date)
232+
if (commit->date == ULONG_MAX)
233233
return error_func(&commit->object, FSCK_ERROR, "invalid author/committer line");
234234

235235
if (memcmp(buffer, "tree ", 5))

0 commit comments

Comments
 (0)