##// END OF EJS Templates
Commit date validation: more stringent checks, more useful error messages.
Bryan O'Sullivan -
r1202:71111d79 default
parent child Browse files
Show More
@@ -35,7 +35,10 b' class changelog(revlog):'
35 # validate explicit (probably user-specified) date and
35 # validate explicit (probably user-specified) date and
36 # time zone offset. values must fit in signed 32 bits for
36 # time zone offset. values must fit in signed 32 bits for
37 # current 32-bit linux runtimes.
37 # current 32-bit linux runtimes.
38 when, offset = map(int, date.split(' '))
38 try:
39 when, offset = map(int, date.split(' '))
40 except ValueError:
41 raise ValueError('invalid date: %r' % date)
39 if abs(when) > 0x7fffffff:
42 if abs(when) > 0x7fffffff:
40 raise ValueError('date exceeds 32 bits: %d' % when)
43 raise ValueError('date exceeds 32 bits: %d' % when)
41 if abs(offset) >= 43200:
44 if abs(offset) >= 43200:
@@ -660,7 +660,10 b' def commit(ui, repo, *pats, **opts):'
660 files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
660 files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
661 else:
661 else:
662 files = []
662 files = []
663 repo.commit(files, message, opts['user'], opts['date'], match)
663 try:
664 repo.commit(files, message, opts['user'], opts['date'], match)
665 except ValueError, inst:
666 raise util.Abort(str(inst))
664
667
665 def copy(ui, repo, source, dest):
668 def copy(ui, repo, source, dest):
666 """mark a file as copied or renamed for the next commit"""
669 """mark a file as copied or renamed for the next commit"""
@@ -1264,7 +1267,10 b' def rawcommit(ui, repo, *flist, **rc):'
1264
1267
1265 rc['parent'] = map(repo.lookup, rc['parent'])
1268 rc['parent'] = map(repo.lookup, rc['parent'])
1266
1269
1267 repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
1270 try:
1271 repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
1272 except ValueError, inst:
1273 raise util.Abort(str(inst))
1268
1274
1269 def recover(ui, repo):
1275 def recover(ui, repo):
1270 """roll back an interrupted transaction"""
1276 """roll back an interrupted transaction"""
@@ -1502,7 +1508,10 b' def tag(ui, repo, name, rev=None, **opts'
1502
1508
1503 message = (opts['message'] or opts['text'] or
1509 message = (opts['message'] or opts['text'] or
1504 "Added tag %s for changeset %s" % (name, r))
1510 "Added tag %s for changeset %s" % (name, r))
1505 repo.commit([".hgtags"], message, opts['user'], opts['date'])
1511 try:
1512 repo.commit([".hgtags"], message, opts['user'], opts['date'])
1513 except ValueError, inst:
1514 raise util.Abort(str(inst))
1506
1515
1507 def tags(ui, repo):
1516 def tags(ui, repo):
1508 """list repository tags"""
1517 """list repository tags"""
@@ -1,90 +1,15 b''
1 Traceback (most recent call last):
2 File "/tmp/hgtests.22041.15131.11536.3935/install/bin/hg", line 13, in ?
3 commands.run()
4 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1809, in run
5 sys.exit(dispatch(sys.argv[1:]))
6 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1945, in dispatch
7 return d()
8 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1930, in <lambda>
9 d = lambda: func(u, repo, *args, **cmdoptions)
10 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 663, in commit
11 repo.commit(files, message, opts['user'], opts['date'], match)
12 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/localrepo.py", line 398, in commit
13 n = self.changelog.add(mn, changed, text, tr, p1, p2, user, date)
14 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/changelog.py", line 42, in add
15 raise ValueError('impossible time zone offset: %d' % offset)
16 ValueError: impossible time zone offset: 4444444
17 transaction abort!
1 transaction abort!
18 rollback completed
2 rollback completed
19 Traceback (most recent call last):
3 abort: impossible time zone offset: 4444444
20 File "/tmp/hgtests.22041.15131.11536.3935/install/bin/hg", line 13, in ?
4 transaction abort!
21 commands.run()
5 rollback completed
22 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1809, in run
6 abort: invalid date: '1\t15.1'
23 sys.exit(dispatch(sys.argv[1:]))
24 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1945, in dispatch
25 return d()
26 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1930, in <lambda>
27 d = lambda: func(u, repo, *args, **cmdoptions)
28 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 663, in commit
29 repo.commit(files, message, opts['user'], opts['date'], match)
30 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/localrepo.py", line 398, in commit
31 n = self.changelog.add(mn, changed, text, tr, p1, p2, user, date)
32 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/changelog.py", line 38, in add
33 when, offset = map(int, date.split(' '))
34 ValueError: invalid literal for int(): 1 15.1
35 transaction abort!
7 transaction abort!
36 rollback completed
8 rollback completed
37 Traceback (most recent call last):
9 abort: invalid date: 'foo bar'
38 File "/tmp/hgtests.22041.15131.11536.3935/install/bin/hg", line 13, in ?
39 commands.run()
40 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1809, in run
41 sys.exit(dispatch(sys.argv[1:]))
42 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1945, in dispatch
43 return d()
44 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1930, in <lambda>
45 d = lambda: func(u, repo, *args, **cmdoptions)
46 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 663, in commit
47 repo.commit(files, message, opts['user'], opts['date'], match)
48 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/localrepo.py", line 398, in commit
49 n = self.changelog.add(mn, changed, text, tr, p1, p2, user, date)
50 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/changelog.py", line 38, in add
51 when, offset = map(int, date.split(' '))
52 ValueError: invalid literal for int(): foo
53 transaction abort!
10 transaction abort!
54 rollback completed
11 rollback completed
55 Traceback (most recent call last):
12 abort: invalid date: ' 1 4444'
56 File "/tmp/hgtests.22041.15131.11536.3935/install/bin/hg", line 13, in ?
57 commands.run()
58 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1809, in run
59 sys.exit(dispatch(sys.argv[1:]))
60 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1945, in dispatch
61 return d()
62 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1930, in <lambda>
63 d = lambda: func(u, repo, *args, **cmdoptions)
64 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 663, in commit
65 repo.commit(files, message, opts['user'], opts['date'], match)
66 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/localrepo.py", line 398, in commit
67 n = self.changelog.add(mn, changed, text, tr, p1, p2, user, date)
68 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/changelog.py", line 38, in add
69 when, offset = map(int, date.split(' '))
70 ValueError: invalid literal for int():
71 transaction abort!
13 transaction abort!
72 rollback completed
14 rollback completed
73 Traceback (most recent call last):
15 abort: date exceeds 32 bits: 111111111111
74 File "/tmp/hgtests.22041.15131.11536.3935/install/bin/hg", line 13, in ?
75 commands.run()
76 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1809, in run
77 sys.exit(dispatch(sys.argv[1:]))
78 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1945, in dispatch
79 return d()
80 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 1930, in <lambda>
81 d = lambda: func(u, repo, *args, **cmdoptions)
82 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/commands.py", line 663, in commit
83 repo.commit(files, message, opts['user'], opts['date'], match)
84 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/localrepo.py", line 398, in commit
85 n = self.changelog.add(mn, changed, text, tr, p1, p2, user, date)
86 File "/tmp/hgtests.22041.15131.11536.3935/install/lib/python/mercurial/changelog.py", line 40, in add
87 raise ValueError('date exceeds 32 bits: %d' % when)
88 ValueError: date exceeds 32 bits: 111111111111
89 transaction abort!
90 rollback completed
General Comments 0
You need to be logged in to leave comments. Login now