##// END OF EJS Templates
Fix bad behaviour when specifying an invalid date (issue700)...
Thomas Arendsen Hein -
r6139:989467e8 default
parent child Browse files
Show More
@@ -65,6 +65,10 b" def fetch(ui, repo, source='default', **"
65 modheads = repo.pull(other, heads=revs)
65 modheads = repo.pull(other, heads=revs)
66 return postincoming(other, modheads)
66 return postincoming(other, modheads)
67
67
68 date = opts.get('date')
69 if date:
70 opts['date'] = util.parsedate(date)
71
68 parent, p2 = repo.dirstate.parents()
72 parent, p2 = repo.dirstate.parents()
69 if parent != repo.changelog.tip():
73 if parent != repo.changelog.tip():
70 raise util.Abort(_('working dir not at tip '
74 raise util.Abort(_('working dir not at tip '
@@ -203,6 +203,11 b' def sign(ui, repo, *revs, **opts):'
203 mygpg = newgpg(ui, **opts)
203 mygpg = newgpg(ui, **opts)
204 sigver = "0"
204 sigver = "0"
205 sigmessage = ""
205 sigmessage = ""
206
207 date = opts.get('date')
208 if date:
209 opts['date'] = util.parsedate(date)
210
206 if revs:
211 if revs:
207 nodes = [repo.lookup(n) for n in revs]
212 nodes = [repo.lookup(n) for n in revs]
208 else:
213 else:
@@ -612,6 +612,8 b' class queue:'
612 force = opts.get('force')
612 force = opts.get('force')
613 user = opts.get('user')
613 user = opts.get('user')
614 date = opts.get('date')
614 date = opts.get('date')
615 if date:
616 date = util.parsedate(date)
615 self.check_reserved_name(patch)
617 self.check_reserved_name(patch)
616 if os.path.exists(self.join(patch)):
618 if os.path.exists(self.join(patch)):
617 raise util.Abort(_('patch "%s" already exists') % patch)
619 raise util.Abort(_('patch "%s" already exists') % patch)
@@ -640,7 +642,7 b' class queue:'
640 p.write("# HG changeset patch\n")
642 p.write("# HG changeset patch\n")
641 if user:
643 if user:
642 p.write("# User " + user + "\n")
644 p.write("# User " + user + "\n")
643 p.write("# Date " + date + "\n")
645 p.write("# Date %d %d\n" % date)
644 p.write("\n")
646 p.write("\n")
645 elif user:
647 elif user:
646 p.write("From: " + user + "\n")
648 p.write("From: " + user + "\n")
@@ -935,6 +937,9 b' class queue:'
935 if len(self.applied) == 0:
937 if len(self.applied) == 0:
936 self.ui.write("No patches applied\n")
938 self.ui.write("No patches applied\n")
937 return 1
939 return 1
940 newdate = opts.get('date')
941 if newdate:
942 newdate = '%d %d' % util.parsedate(newdate)
938 wlock = repo.wlock()
943 wlock = repo.wlock()
939 try:
944 try:
940 self.check_toppatch(repo)
945 self.check_toppatch(repo)
@@ -995,7 +1000,6 b' class queue:'
995 comments = ['From: ' + newuser, ''] + comments
1000 comments = ['From: ' + newuser, ''] + comments
996 user = newuser
1001 user = newuser
997
1002
998 newdate = opts.get('date')
999 if newdate:
1003 if newdate:
1000 if setheaderfield(comments, ['# Date '], newdate):
1004 if setheaderfield(comments, ['# Date '], newdate):
1001 date = newdate
1005 date = newdate
@@ -1115,6 +1115,9 b' def walkchangerevs(ui, repo, pats, chang'
1115
1115
1116 def commit(ui, repo, commitfunc, pats, opts):
1116 def commit(ui, repo, commitfunc, pats, opts):
1117 '''commit the specified files or all outstanding changes'''
1117 '''commit the specified files or all outstanding changes'''
1118 date = opts.get('date')
1119 if date:
1120 opts['date'] = util.parsedate(date)
1118 message = logmessage(opts)
1121 message = logmessage(opts)
1119
1122
1120 # extract addremove carefully -- this function can be called from a command
1123 # extract addremove carefully -- this function can be called from a command
@@ -196,6 +196,10 b' def backout(ui, repo, node=None, rev=Non'
196 if not rev:
196 if not rev:
197 raise util.Abort(_("please specify a revision to backout"))
197 raise util.Abort(_("please specify a revision to backout"))
198
198
199 date = opts.get('date')
200 if date:
201 opts['date'] = util.parsedate(date)
202
199 cmdutil.bail_if_changed(repo)
203 cmdutil.bail_if_changed(repo)
200 node = repo.lookup(rev)
204 node = repo.lookup(rev)
201
205
@@ -1440,6 +1444,10 b' def import_(ui, repo, patch1, *patches, '
1440 """
1444 """
1441 patches = (patch1,) + patches
1445 patches = (patch1,) + patches
1442
1446
1447 date = opts.get('date')
1448 if date:
1449 opts['date'] = util.parsedate(date)
1450
1443 if opts.get('exact') or not opts['force']:
1451 if opts.get('exact') or not opts['force']:
1444 cmdutil.bail_if_changed(repo)
1452 cmdutil.bail_if_changed(repo)
1445
1453
@@ -202,6 +202,7 b' class localrepository(repo.repository):'
202
202
203 date: date tuple to use if committing'''
203 date: date tuple to use if committing'''
204
204
205 date = util.parsedate(date)
205 for x in self.status()[:5]:
206 for x in self.status()[:5]:
206 if '.hgtags' in x:
207 if '.hgtags' in x:
207 raise util.Abort(_('working copy of .hgtags is changed '
208 raise util.Abort(_('working copy of .hgtags is changed '
@@ -1572,17 +1572,21 b' def strdate(string, format, defaults=[])'
1572 unixtime = localunixtime + offset
1572 unixtime = localunixtime + offset
1573 return unixtime, offset
1573 return unixtime, offset
1574
1574
1575 def parsedate(string, formats=None, defaults=None):
1575 def parsedate(date, formats=None, defaults=None):
1576 """parse a localized time string and return a (unixtime, offset) tuple.
1576 """parse a localized date/time string and return a (unixtime, offset) tuple.
1577
1577 The date may be a "unixtime offset" string or in one of the specified
1578 The date may be a "unixtime offset" string or in one of the specified
1578 formats."""
1579 formats. If the date already is a (unixtime, offset) tuple, it is returned.
1579 if not string:
1580 """
1581 if not date:
1580 return 0, 0
1582 return 0, 0
1583 if type(date) is type((0, 0)) and len(date) == 2:
1584 return date
1581 if not formats:
1585 if not formats:
1582 formats = defaultdateformats
1586 formats = defaultdateformats
1583 string = string.strip()
1587 date = date.strip()
1584 try:
1588 try:
1585 when, offset = map(int, string.split(' '))
1589 when, offset = map(int, date.split(' '))
1586 except ValueError:
1590 except ValueError:
1587 # fill out defaults
1591 # fill out defaults
1588 if not defaults:
1592 if not defaults:
@@ -1599,13 +1603,13 b' def parsedate(string, formats=None, defa'
1599
1603
1600 for format in formats:
1604 for format in formats:
1601 try:
1605 try:
1602 when, offset = strdate(string, format, defaults)
1606 when, offset = strdate(date, format, defaults)
1603 except (ValueError, OverflowError):
1607 except (ValueError, OverflowError):
1604 pass
1608 pass
1605 else:
1609 else:
1606 break
1610 break
1607 else:
1611 else:
1608 raise Abort(_('invalid date: %r ') % string)
1612 raise Abort(_('invalid date: %r ') % date)
1609 # validate explicit (probably user-specified) date and
1613 # validate explicit (probably user-specified) date and
1610 # time zone offset. values must fit in signed 32 bits for
1614 # time zone offset. values must fit in signed 32 bits for
1611 # current 32-bit linux runtimes. timezones go from UTC-12
1615 # current 32-bit linux runtimes. timezones go from UTC-12
@@ -2,16 +2,10 b''
2 transaction abort!
2 transaction abort!
3 rollback completed
3 rollback completed
4 abort: empty commit message
4 abort: empty commit message
5 transaction abort!
6 rollback completed
7 abort: impossible time zone offset: 4444444
5 abort: impossible time zone offset: 4444444
8 transaction abort!
9 rollback completed
10 abort: invalid date: '1\t15.1'
6 abort: invalid date: '1\t15.1'
11 transaction abort!
12 rollback completed
13 abort: invalid date: 'foo bar'
7 abort: invalid date: 'foo bar'
14 nothing changed
8 abort: date exceeds 32 bits: 111111111111
15 % commit added file that has been deleted
9 % commit added file that has been deleted
16 nothing changed
10 nothing changed
17 abort: file bar not found!
11 abort: file bar not found!
@@ -3,14 +3,8 b' changeset 3:107ce1ee2b43 backs out chang'
3 merging with changeset 2:e6c3abc120e7
3 merging with changeset 2:e6c3abc120e7
4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5 (branch merge, don't forget to commit)
5 (branch merge, don't forget to commit)
6 transaction abort!
7 rollback completed
8 abort: invalid date: 'should fail'
6 abort: invalid date: 'should fail'
9 transaction abort!
10 rollback completed
11 abort: date exceeds 32 bits: 100000000000000000
7 abort: date exceeds 32 bits: 100000000000000000
12 transaction abort!
13 rollback completed
14 abort: impossible time zone offset: 1400000
8 abort: impossible time zone offset: 1400000
15 Sun Jan 15 13:30:00 2006 +0500
9 Sun Jan 15 13:30:00 2006 +0500
16 Sun Jan 15 13:30:00 2006 -0800
10 Sun Jan 15 13:30:00 2006 -0800
General Comments 0
You need to be logged in to leave comments. Login now