Skip to content

Commit 90ef0f1

Browse files
peffgitster
authored andcommitted
parse_commit(): describe more date-parsing failure modes
The previous few commits improved the parsing of dates in malformed commit objects. But there's one big case left implicit: we may still feed garbage to parse_timestamp(). This is preferable to trying to be more strict, but let's document the thinking in a comment. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 089d9ad commit 90ef0f1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

commit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
143143
/*
144144
* We know there is at least one digit (or dash), so we'll begin
145145
* parsing there and stop at worst case at eol.
146+
*
147+
* Note that we may feed parse_timestamp() extra characters here if the
148+
* commit is malformed, and it will parse as far as it can. For
149+
* example, "123foo456" would return "123". That might be questionable
150+
* (versus returning "0"), but it would help in a hypothetical case
151+
* like "123456+0100", where the whitespace from the timezone is
152+
* missing. Since such syntactic errors may be baked into history and
153+
* hard to correct now, let's err on trying to make our best guess
154+
* here, rather than insist on perfect syntax.
146155
*/
147156
return parse_timestamp(dateptr, NULL, 10);
148157
}

0 commit comments

Comments
 (0)