diff options
author | D Herring <dherring@at.tentpost.dot.com> | 2010-04-21 23:23:07 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@frugalware.org> | 2010-04-21 23:23:07 +0200 |
commit | 080ec591ac98cd2b24fd4627c315ec62ace3b746 (patch) | |
tree | 7b4fa34874e119195c02b8abc028b78ee7339c12 | |
parent | 514ae4f3b64dba6c98b9337b99bc3a37a0c17c81 (diff) | |
download | python-fastimport-080ec591ac98cd2b24fd4627c315ec62ace3b746.tar.gz |
fix timezones in darcs-fast-export, take 2
The previous patch had a flaw; it assumed that darcs was storing the committer's timezone.
Instead, darcs always stores UTC timestamps in an ISO 8601 format.
Tools like "darcs changes" convert this into the user's local time as a convenience.
I couldn't find an authoritative spec, but here are some relevant references.
http://wiki.darcs.net/NamedPatch
http://search.cpan.org/~david/Darcs-Inventory-1.4/lib/Darcs/Inventory/Patch.pm
http://bugs.darcs.net/issue140
To resolve the issue, this patch always reports that the timezone is UTC.
-rwxr-xr-x | exporters/darcs/darcs-fast-export | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/exporters/darcs/darcs-fast-export b/exporters/darcs/darcs-fast-export index 79590a6..fa850de 100755 --- a/exporters/darcs/darcs-fast-export +++ b/exporters/darcs/darcs-fast-export @@ -29,6 +29,7 @@ import os import sys import gzip import time +import calendar import shutil import subprocess import optparse @@ -82,22 +83,12 @@ class Handler: author = author[author.index('>')+2:] + ' ' + author[:author.index('>')+1] return author.encode('utf-8') - def get_time_info(self, patch): - date = time.strptime(patch, "%a %b %d %H:%M:%S %Z %Y") - timestamp = int(time.mktime(date)) - # calculate the timezone offset - fields=re.split('[ ]+', patch) - fields[4]="UTC" - patch_utc=" ".join(fields) - date_utc=time.strptime(patch_utc, "%a %b %d %H:%M:%S %Z %Y") - offset=int(time.timezone + time.mktime(date) - time.mktime(date_utc)) - hours, minutes = divmod(abs(offset), 3600) - if offset > 0: - sign = "-" - else: - sign = "+" - zone = "%s%02d%02d" % (sign, hours, minutes // 60) - return timestamp, zone + def get_date(self, patch): + try: + date = time.strptime(patch, "%Y%m%d%H%M%S") + except ValueError: + date = time.strptime(patch[:19] + patch[-5:], '%a %b %d %H:%M:%S %Y') + return calendar.timegm(date) def progress(self, s): print "progress [%s] %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), s) @@ -329,8 +320,8 @@ class Handler: print "mark :%s" % markcount if self.options.export_marks: self.export_marks.append(":%s %s" % (markcount, hash)) - date, zone = self.get_time_info(i.attributes['local_date'].value) - print "committer %s %s %s" % (self.get_author(i), date, zone) + date = self.get_date(i.attributes['date'].value) + print "committer %s %s +0000" % (self.get_author(i), date) print "data %d\n%s" % (len(message), message) if markcount > 1: print "from :%s" % (markcount-1) @@ -354,7 +345,7 @@ class Handler: tag = re.sub('[^\xe9-\xf8\w.\-]+', '_', message[4:].strip().split('\n')[0]).strip('_') print "tag %s" % tag print "from :%s" % markcount - print "tagger %s %s %s" % (self.get_author(i), date, zone) + print "tagger %s %s +0000" % (self.get_author(i), date) print "data %d\n%s" % (len(message), message) if count % self.prognum == 0: self.progress("%d/%d patches" % (count, patchnum)) |