From 93cfa7c7a85efbdb00daade4ad0afc11bd2fdf37 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 26 Jan 2010 11:58:00 -0800 Subject: approxidate_careful() reports errorneous date string For a long time, the time based reflog syntax (e.g. master@{yesterday}) didn't complain when the "human readable" timestamp was misspelled, as the underlying mechanism tried to be as lenient as possible. The funny thing was that parsing of "@{now}" even relied on the fact that anything not recognized by the machinery returned the current timestamp. Introduce approxidate_careful() that takes an optional pointer to an integer, that gets assigned 1 when the input does not make sense as a timestamp. As I am too lazy to fix all the callers that use approxidate(), most of the callers do not take advantage of the error checking, but convert the code to parse reflog to use it as a demonstration. Tests are mostly from Jeff King. Signed-off-by: Junio C Hamano --- sha1_name.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index 44bb62d270..f4a74fe99f 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -395,8 +395,11 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) } else if (0 <= nth) at_time = 0; else { + int errors = 0; char *tmp = xstrndup(str + at + 2, reflog_len); - at_time = approxidate(tmp); + at_time = approxidate_careful(tmp, &errors); + if (errors) + die("Bogus timestamp '%s'", tmp); free(tmp); } if (read_ref_at(real_ref, at_time, nth, sha1, NULL, -- cgit v1.2.3 From a5e10acbb946305ca42f510cdb196d171020238e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 27 Jan 2010 10:53:09 -0800 Subject: Update @{bogus.timestamp} fix not to die() The caller will say "It is not a valid object name" if it wants to, and some callers may even try to see if it names an object and otherwise try to see if it is a path. Pointed out by Jeff King. Signed-off-by: Junio C Hamano --- sha1_name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index f4a74fe99f..04fb3b8fed 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -398,9 +398,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) int errors = 0; char *tmp = xstrndup(str + at + 2, reflog_len); at_time = approxidate_careful(tmp, &errors); - if (errors) - die("Bogus timestamp '%s'", tmp); free(tmp); + if (errors) + return -1; } if (read_ref_at(real_ref, at_time, nth, sha1, NULL, &co_time, &co_tz, &co_cnt)) { -- cgit v1.2.3