Mercurial > public > mercurial-scm > hg
comparison mercurial/changelog.py @ 1321:b47f96a178a3
Clean up date and timezone handling.
We used to pass changelog dates around as a "unixtime timezone" string
containing a pair of encoded ints. Now, they get passed around as a
(unixtime, timezone) tuple of numbers, which makes much more sense.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 22 Sep 2005 23:19:47 -0700 |
parents | 71111d796e40 |
children | 085e3fc189b6 |
comparison
equal
deleted
inserted
replaced
1320:5f277e73778f | 1321:b47f96a178a3 |
---|---|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
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): |
13 revlog.__init__(self, opener, "00changelog.i", "00changelog.d") | 14 revlog.__init__(self, opener, "00changelog.i", "00changelog.d") |
14 | 15 |
18 last = text.index("\n\n") | 19 last = text.index("\n\n") |
19 desc = text[last + 2:] | 20 desc = text[last + 2:] |
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)) |
31 | 36 |
32 def add(self, manifest, list, desc, transaction, p1=None, p2=None, | 37 def add(self, manifest, list, desc, transaction, p1=None, p2=None, |
42 if abs(when) > 0x7fffffff: | 47 if abs(when) > 0x7fffffff: |
43 raise ValueError('date exceeds 32 bits: %d' % when) | 48 raise ValueError('date exceeds 32 bits: %d' % when) |
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) |
53 return self.addrevision(text, transaction, self.count(), p1, p2) | 56 return self.addrevision(text, transaction, self.count(), p1, p2) |