##// END OF EJS Templates
Clean up date and timezone handling....
Bryan O'Sullivan -
r1321:b47f96a1 default
parent child Browse files
Show More
@@ -5,8 +5,9 b''
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 import os, time
9 from revlog import *
8 from revlog import *
9 from demandload import demandload
10 demandload(globals(), "os time util")
10
11
11 class changelog(revlog):
12 class changelog(revlog):
12 def __init__(self, opener):
13 def __init__(self, opener):
@@ -20,11 +21,15 b' class changelog(revlog):'
20 l = text[:last].splitlines()
21 l = text[:last].splitlines()
21 manifest = bin(l[0])
22 manifest = bin(l[0])
22 user = l[1]
23 user = l[1]
23 date = l[2]
24 date = l[2].split(' ')
24 if " " not in date:
25 time = int(date.pop(0))
25 date += " 0" # some tools used -d without a timezone
26 try:
27 # various tools did silly things with the time zone field.
28 timezone = int(date[0])
29 except:
30 timezone = 0
26 files = l[3:]
31 files = l[3:]
27 return (manifest, user, date, files, desc)
32 return (manifest, user, (time, timezone), files, desc)
28
33
29 def read(self, node):
34 def read(self, node):
30 return self.extract(self.revision(node))
35 return self.extract(self.revision(node))
@@ -44,9 +49,7 b' class changelog(revlog):'
44 if abs(offset) >= 43200:
49 if abs(offset) >= 43200:
45 raise ValueError('impossible time zone offset: %d' % offset)
50 raise ValueError('impossible time zone offset: %d' % offset)
46 else:
51 else:
47 if time.daylight: offset = time.altzone
52 date = "%d %d" % util.makedate()
48 else: offset = time.timezone
49 date = "%d %d" % (time.time(), offset)
50 list.sort()
53 list.sort()
51 l = [hex(manifest), user, date] + list + ["", desc]
54 l = [hex(manifest), user, date] + list + ["", desc]
52 text = "\n".join(l)
55 text = "\n".join(l)
@@ -264,7 +264,7 b' def dodiff(fp, ui, repo, node1, node2, f'
264 if node2:
264 if node2:
265 change = repo.changelog.read(node2)
265 change = repo.changelog.read(node2)
266 mmap2 = repo.manifest.read(change[0])
266 mmap2 = repo.manifest.read(change[0])
267 date2 = util.datestr(change)
267 date2 = util.datestr(change[2])
268 def read(f):
268 def read(f):
269 return repo.file(f).read(mmap2[f])
269 return repo.file(f).read(mmap2[f])
270 else:
270 else:
@@ -282,7 +282,7 b' def dodiff(fp, ui, repo, node1, node2, f'
282
282
283 change = repo.changelog.read(node1)
283 change = repo.changelog.read(node1)
284 mmap = repo.manifest.read(change[0])
284 mmap = repo.manifest.read(change[0])
285 date1 = util.datestr(change)
285 date1 = util.datestr(change[2])
286
286
287 for f in c:
287 for f in c:
288 to = None
288 to = None
@@ -319,7 +319,7 b' def show_changeset(ui, repo, rev=0, chan'
319 return
319 return
320
320
321 changes = log.read(changenode)
321 changes = log.read(changenode)
322 date = util.datestr(changes)
322 date = util.datestr(changes[2])
323
323
324 parents = [(log.rev(p), ui.verbose and hex(p) or short(p))
324 parents = [(log.rev(p), ui.verbose and hex(p) or short(p))
325 for p in log.parents(changenode)
325 for p in log.parents(changenode)
@@ -27,7 +27,7 b' def age(x):'
27 return "%d %s" % (c, plural(t, c))
27 return "%d %s" % (c, plural(t, c))
28
28
29 now = time.time()
29 now = time.time()
30 then = int(x[2].split(' ')[0])
30 then = x[2][0]
31 delta = max(1, int(now - then))
31 delta = max(1, int(now - then))
32
32
33 scales = [["second", 1],
33 scales = [["second", 1],
@@ -155,13 +155,13 b' class templater:'
155 common_filters = {
155 common_filters = {
156 "escape": cgi.escape,
156 "escape": cgi.escape,
157 "age": age,
157 "age": age,
158 "date": util.datestr,
158 "date": lambda x: util.datestr(x[2]),
159 "addbreaks": nl2br,
159 "addbreaks": nl2br,
160 "obfuscate": obfuscate,
160 "obfuscate": obfuscate,
161 "short": (lambda x: x[:12]),
161 "short": (lambda x: x[:12]),
162 "firstline": (lambda x: x.splitlines(1)[0]),
162 "firstline": (lambda x: x.splitlines(1)[0]),
163 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
163 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
164 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"),
164 "rfc822date": lambda x: util.datestr(x[2], "%a, %d %b %Y %H:%M:%S"),
165 }
165 }
166
166
167 class hgweb:
167 class hgweb:
@@ -185,7 +185,7 b' class hgweb:'
185 self.allowpull = self.repo.ui.configbool("web", "allowpull", True)
185 self.allowpull = self.repo.ui.configbool("web", "allowpull", True)
186
186
187 def date(self, cs):
187 def date(self, cs):
188 return util.datestr(cs)
188 return util.datestr(cs[2])
189
189
190 def listfiles(self, files, mf):
190 def listfiles(self, files, mf):
191 for f in files[:self.maxfiles]:
191 for f in files[:self.maxfiles]:
@@ -544,21 +544,17 b' def filechunkiter(f, size = 65536):'
544 yield s
544 yield s
545 s = f.read(size)
545 s = f.read(size)
546
546
547 def datestr(change=None, format='%c'):
547 def makedate():
548 """represent a change date as a localized time.
548 t = time.time()
549 a change date is a 'unixtime offset' string, where unixtime is
549 if time.daylight: tz = time.altzone
550 seconds since the epoch, and offset is seconds away from UTC."""
550 else: tz = time.timezone
551 if change is None:
551 return t, tz
552 t = time.time()
552
553 if time.daylight: tz = time.altzone
553 def datestr(date=None, format='%c'):
554 else: tz = time.timezone
554 """represent a (unixtime, offset) tuple as a localized time.
555 else:
555 unixtime is seconds since the epoch, and offset is the time zone's
556 t, tz = change[2].split(' ')
556 number of seconds away from UTC."""
557 try:
557 t, tz = date or makedate()
558 # a conversion tool was sticking non-integer offsets into repos
559 tz = int(tz)
560 except ValueError:
561 tz = 0
562 return ("%s %+03d%02d" %
558 return ("%s %+03d%02d" %
563 (time.strftime(format, time.gmtime(float(t) - tz)),
559 (time.strftime(format, time.gmtime(float(t) - tz)),
564 -tz / 3600,
560 -tz / 3600,
General Comments 0
You need to be logged in to leave comments. Login now