Thu Aug 7 04:41:45 UTC 2008 Alberto Bertogli <albertito@gmail.com>
* Handle old date formats
Very old darcs commits use a different time format, that leaks out in some
operations like annotate. This patch makes darcsweb able to handle it.
Thanks to Simon Michael <simon@joyful.com> for the report and the help.
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2016-03-01 02:46:32.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2016-03-01 02:46:32.000000000 +0000
@@ -292,6 +292,21 @@
lf.close()
+def parse_darcs_time(s):
+ "Try to convert a darcs' time string into a Python time tuple."
+ try:
+ return time.strptime(s, "%Y%m%d%H%M%S")
+ except ValueError:
+ # very old darcs commits use a different format, for example:
+ # "Wed May 21 19:39:10 CEST 2003"
+ # we can't parse the "CEST" part reliably, so we leave it out
+ fmt = "%a %b %d %H:%M:%S %Y"
+ parts = s.split()
+ ns = ' '.join(parts[0:4]) + ' ' + parts[5]
+ return time.strptime(ns, fmt)
+
+
+
#
# generic html functions
#
@@ -733,8 +748,7 @@
au = au[:au.find('<')].strip()
p.shortauthor = fixu8(escape(au))
- td = time.strptime(attrs.get('date', None),
- "%Y%m%d%H%M%S")
+ td = parse_darcs_time(attrs.get('date', None))
p.date = time.mktime(td)
p.date_str = time.strftime("%a, %d %b %Y %H:%M:%S", td)
@@ -994,8 +1008,7 @@
lastname = lastname.childNodes[0].wholeText
annotate.lastchange_name = fixu8(lastname)
- lastdate = lastpatch.getAttribute("date")
- lastdate = time.strptime(lastdate, "%Y%m%d%H%M%S")
+ lastdate = parse_darcs_time(lastpatch.getAttribute("date"))
annotate.lastchange_date = lastdate
annotate.patches[annotate.lastchange_hash] = annotate.lastchange_date
@@ -1017,7 +1030,7 @@
phash = patch.getAttribute("hash")
pauthor = patch.getAttribute("author")
pdate = patch.getAttribute("date")
- pdate = time.strptime(pdate, "%Y%m%d%H%M%S")
+ pdate = parse_darcs_time(pdate)
else:
# added lines inherit the creation from the annotate
# patch