summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-02-10 22:08:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-02-10 22:08:12 (GMT)
commit3d8bc74127bbb583bc437214a1d6c9afcf77646c (patch)
tree6d1788c66ea9e038252cf6641b5c580c641dcb88 /date.c
parentfd6abd0c65b38897da64ef883ed1934d2b2b1a3a (diff)
parent2c733fb24c10a9d7aacc51f956bf9b7881980870 (diff)
downloadgit-3d8bc74127bbb583bc437214a1d6c9afcf77646c.zip
git-3d8bc74127bbb583bc437214a1d6c9afcf77646c.tar.gz
git-3d8bc74127bbb583bc437214a1d6c9afcf77646c.tar.bz2
Merge branch 'jc/parse-date-raw'
* jc/parse-date-raw: parse_date(): '@' prefix forces git-timestamp parse_date(): allow ancient git-timestamp
Diffstat (limited to 'date.c')
-rw-r--r--date.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/date.c b/date.c
index 353e0a5..a5055ca 100644
--- a/date.c
+++ b/date.c
@@ -597,6 +597,33 @@ static int date_string(unsigned long date, int offset, char *buf, int len)
return snprintf(buf, len, "%lu %c%02d%02d", date, sign, offset / 60, offset % 60);
}
+/*
+ * Parse a string like "0 +0000" as ancient timestamp near epoch, but
+ * only when it appears not as part of any other string.
+ */
+static int match_object_header_date(const char *date, unsigned long *timestamp, int *offset)
+{
+ char *end;
+ unsigned long stamp;
+ int ofs;
+
+ if (*date < '0' || '9' <= *date)
+ return -1;
+ stamp = strtoul(date, &end, 10);
+ if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
+ return -1;
+ date = end + 2;
+ ofs = strtol(date, &end, 10);
+ if ((*end != '\0' && (*end != '\n')) || end != date + 4)
+ return -1;
+ ofs = (ofs / 100) * 60 + (ofs % 100);
+ if (date[-1] == '-')
+ ofs = -ofs;
+ *timestamp = stamp;
+ *offset = ofs;
+ return 0;
+}
+
/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
(i.e. English) day/month names, and it doesn't work correctly with %z. */
int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
@@ -622,6 +649,9 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
*offset = -1;
tm_gmt = 0;
+ if (*date == '@' &&
+ !match_object_header_date(date + 1, timestamp, offset))
+ return 0; /* success */
for (;;) {
int match = 0;
unsigned char c = *date;