diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -5,8 +5,9 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, time from revlog import * +from demandload import demandload +demandload(globals(), "os time util") class changelog(revlog): def __init__(self, opener): @@ -20,11 +21,15 @@ class changelog(revlog): l = text[:last].splitlines() manifest = bin(l[0]) user = l[1] - date = l[2] - if " " not in date: - date += " 0" # some tools used -d without a timezone + date = l[2].split(' ') + time = int(date.pop(0)) + try: + # various tools did silly things with the time zone field. + timezone = int(date[0]) + except: + timezone = 0 files = l[3:] - return (manifest, user, date, files, desc) + return (manifest, user, (time, timezone), files, desc) def read(self, node): return self.extract(self.revision(node)) @@ -44,9 +49,7 @@ class changelog(revlog): if abs(offset) >= 43200: raise ValueError('impossible time zone offset: %d' % offset) else: - if time.daylight: offset = time.altzone - else: offset = time.timezone - date = "%d %d" % (time.time(), offset) + date = "%d %d" % util.makedate() list.sort() l = [hex(manifest), user, date] + list + ["", desc] text = "\n".join(l) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -264,7 +264,7 @@ def dodiff(fp, ui, repo, node1, node2, f if node2: change = repo.changelog.read(node2) mmap2 = repo.manifest.read(change[0]) - date2 = util.datestr(change) + date2 = util.datestr(change[2]) def read(f): return repo.file(f).read(mmap2[f]) else: @@ -282,7 +282,7 @@ def dodiff(fp, ui, repo, node1, node2, f change = repo.changelog.read(node1) mmap = repo.manifest.read(change[0]) - date1 = util.datestr(change) + date1 = util.datestr(change[2]) for f in c: to = None @@ -319,7 +319,7 @@ def show_changeset(ui, repo, rev=0, chan return changes = log.read(changenode) - date = util.datestr(changes) + date = util.datestr(changes[2]) parents = [(log.rev(p), ui.verbose and hex(p) or short(p)) for p in log.parents(changenode) diff --git a/mercurial/hgweb.py b/mercurial/hgweb.py --- a/mercurial/hgweb.py +++ b/mercurial/hgweb.py @@ -27,7 +27,7 @@ def age(x): return "%d %s" % (c, plural(t, c)) now = time.time() - then = int(x[2].split(' ')[0]) + then = x[2][0] delta = max(1, int(now - then)) scales = [["second", 1], @@ -155,13 +155,13 @@ class templater: common_filters = { "escape": cgi.escape, "age": age, - "date": util.datestr, + "date": lambda x: util.datestr(x[2]), "addbreaks": nl2br, "obfuscate": obfuscate, "short": (lambda x: x[:12]), "firstline": (lambda x: x.splitlines(1)[0]), "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), - "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), + "rfc822date": lambda x: util.datestr(x[2], "%a, %d %b %Y %H:%M:%S"), } class hgweb: @@ -185,7 +185,7 @@ class hgweb: self.allowpull = self.repo.ui.configbool("web", "allowpull", True) def date(self, cs): - return util.datestr(cs) + return util.datestr(cs[2]) def listfiles(self, files, mf): for f in files[:self.maxfiles]: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -544,21 +544,17 @@ def filechunkiter(f, size = 65536): yield s s = f.read(size) -def datestr(change=None, format='%c'): - """represent a change date as a localized time. - a change date is a 'unixtime offset' string, where unixtime is - seconds since the epoch, and offset is seconds away from UTC.""" - if change is None: - t = time.time() - if time.daylight: tz = time.altzone - else: tz = time.timezone - else: - t, tz = change[2].split(' ') - try: - # a conversion tool was sticking non-integer offsets into repos - tz = int(tz) - except ValueError: - tz = 0 +def makedate(): + t = time.time() + if time.daylight: tz = time.altzone + else: tz = time.timezone + return t, tz + +def datestr(date=None, format='%c'): + """represent a (unixtime, offset) tuple as a localized time. + unixtime is seconds since the epoch, and offset is the time zone's + number of seconds away from UTC.""" + t, tz = date or makedate() return ("%s %+03d%02d" % (time.strftime(format, time.gmtime(float(t) - tz)), -tz / 3600,