##// END OF EJS Templates
Date validation must check for 32-bit width. Don't use assert to check.
Bryan O'Sullivan -
r1197:8deb6981 default
parent child Browse files
Show More
@@ -1,47 +1,50
1 1 # changelog.py - changelog class for mercurial
2 2 #
3 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 import os, time
9 9 from revlog import *
10 10
11 11 class changelog(revlog):
12 12 def __init__(self, opener):
13 13 revlog.__init__(self, opener, "00changelog.i", "00changelog.d")
14 14
15 15 def extract(self, text):
16 16 if not text:
17 17 return (nullid, "", "0", [], "")
18 18 last = text.index("\n\n")
19 19 desc = text[last + 2:]
20 20 l = text[:last].splitlines()
21 21 manifest = bin(l[0])
22 22 user = l[1]
23 23 date = l[2]
24 24 if " " not in date:
25 25 date += " 0" # some tools used -d without a timezone
26 26 files = l[3:]
27 27 return (manifest, user, date, files, desc)
28 28
29 29 def read(self, node):
30 30 return self.extract(self.revision(node))
31 31
32 32 def add(self, manifest, list, desc, transaction, p1=None, p2=None,
33 33 user=None, date=None):
34 34 if date:
35 35 # validate explicit (probably user-specified) date and
36 # time zone offset
36 # time zone offset. values must fit in signed 32 bits for
37 # current 32-bit linux runtimes.
37 38 when, offset = map(int, date.split(' '))
38 time.localtime(when)
39 assert abs(offset) < 43200, 'bad time zone offset: %d' % offset
39 if abs(when) > 0x7fffffff:
40 raise ValueError('date exceeds 32 bits: %d' % when)
41 if abs(offset) >= 43200:
42 raise ValueError('impossible time zone offset: %d' % offset)
40 43 else:
41 44 if time.daylight: offset = time.altzone
42 45 else: offset = time.timezone
43 46 date = "%d %d" % (time.time(), offset)
44 47 list.sort()
45 48 l = [hex(manifest), user, date] + list + ["", desc]
46 49 text = "\n".join(l)
47 50 return self.addrevision(text, transaction, self.count(), p1, p2)
General Comments 0
You need to be logged in to leave comments. Login now