Mercurial > hg-stable
changeset 6139:989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
commit (aborts _after_ typing in a commit message)
backout (aborted after the initial revert)
tag (edited .hgtags and couldn't commit)
import (patch applied, then commit fails)
qnew (aborts on bad dates, but writes any valid date into the # Date header)
qrefresh (like qnew)
sign (like tag)
fetch (merge, merge, merge, merge, abort)
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sun, 17 Feb 2008 21:34:28 +0100 |
parents | 09847b90beae |
children | 47e6d5d5913a |
files | hgext/fetch.py hgext/gpg.py hgext/mq.py mercurial/cmdutil.py mercurial/commands.py mercurial/localrepo.py mercurial/util.py tests/test-commit.out tests/test-parse-date.out |
diffstat | 9 files changed, 40 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/fetch.py Sun Feb 17 12:53:57 2008 +0100 +++ b/hgext/fetch.py Sun Feb 17 21:34:28 2008 +0100 @@ -65,6 +65,10 @@ modheads = repo.pull(other, heads=revs) return postincoming(other, modheads) + date = opts.get('date') + if date: + opts['date'] = util.parsedate(date) + parent, p2 = repo.dirstate.parents() if parent != repo.changelog.tip(): raise util.Abort(_('working dir not at tip '
--- a/hgext/gpg.py Sun Feb 17 12:53:57 2008 +0100 +++ b/hgext/gpg.py Sun Feb 17 21:34:28 2008 +0100 @@ -203,6 +203,11 @@ mygpg = newgpg(ui, **opts) sigver = "0" sigmessage = "" + + date = opts.get('date') + if date: + opts['date'] = util.parsedate(date) + if revs: nodes = [repo.lookup(n) for n in revs] else:
--- a/hgext/mq.py Sun Feb 17 12:53:57 2008 +0100 +++ b/hgext/mq.py Sun Feb 17 21:34:28 2008 +0100 @@ -612,6 +612,8 @@ force = opts.get('force') user = opts.get('user') date = opts.get('date') + if date: + date = util.parsedate(date) self.check_reserved_name(patch) if os.path.exists(self.join(patch)): raise util.Abort(_('patch "%s" already exists') % patch) @@ -640,7 +642,7 @@ p.write("# HG changeset patch\n") if user: p.write("# User " + user + "\n") - p.write("# Date " + date + "\n") + p.write("# Date %d %d\n" % date) p.write("\n") elif user: p.write("From: " + user + "\n") @@ -935,6 +937,9 @@ if len(self.applied) == 0: self.ui.write("No patches applied\n") return 1 + newdate = opts.get('date') + if newdate: + newdate = '%d %d' % util.parsedate(newdate) wlock = repo.wlock() try: self.check_toppatch(repo) @@ -995,7 +1000,6 @@ comments = ['From: ' + newuser, ''] + comments user = newuser - newdate = opts.get('date') if newdate: if setheaderfield(comments, ['# Date '], newdate): date = newdate
--- a/mercurial/cmdutil.py Sun Feb 17 12:53:57 2008 +0100 +++ b/mercurial/cmdutil.py Sun Feb 17 21:34:28 2008 +0100 @@ -1115,6 +1115,9 @@ def commit(ui, repo, commitfunc, pats, opts): '''commit the specified files or all outstanding changes''' + date = opts.get('date') + if date: + opts['date'] = util.parsedate(date) message = logmessage(opts) # extract addremove carefully -- this function can be called from a command
--- a/mercurial/commands.py Sun Feb 17 12:53:57 2008 +0100 +++ b/mercurial/commands.py Sun Feb 17 21:34:28 2008 +0100 @@ -196,6 +196,10 @@ if not rev: raise util.Abort(_("please specify a revision to backout")) + date = opts.get('date') + if date: + opts['date'] = util.parsedate(date) + cmdutil.bail_if_changed(repo) node = repo.lookup(rev) @@ -1440,6 +1444,10 @@ """ patches = (patch1,) + patches + date = opts.get('date') + if date: + opts['date'] = util.parsedate(date) + if opts.get('exact') or not opts['force']: cmdutil.bail_if_changed(repo)
--- a/mercurial/localrepo.py Sun Feb 17 12:53:57 2008 +0100 +++ b/mercurial/localrepo.py Sun Feb 17 21:34:28 2008 +0100 @@ -202,6 +202,7 @@ date: date tuple to use if committing''' + date = util.parsedate(date) for x in self.status()[:5]: if '.hgtags' in x: raise util.Abort(_('working copy of .hgtags is changed '
--- a/mercurial/util.py Sun Feb 17 12:53:57 2008 +0100 +++ b/mercurial/util.py Sun Feb 17 21:34:28 2008 +0100 @@ -1572,17 +1572,21 @@ unixtime = localunixtime + offset return unixtime, offset -def parsedate(string, formats=None, defaults=None): - """parse a localized time string and return a (unixtime, offset) tuple. +def parsedate(date, formats=None, defaults=None): + """parse a localized date/time string and return a (unixtime, offset) tuple. + The date may be a "unixtime offset" string or in one of the specified - formats.""" - if not string: + formats. If the date already is a (unixtime, offset) tuple, it is returned. + """ + if not date: return 0, 0 + if type(date) is type((0, 0)) and len(date) == 2: + return date if not formats: formats = defaultdateformats - string = string.strip() + date = date.strip() try: - when, offset = map(int, string.split(' ')) + when, offset = map(int, date.split(' ')) except ValueError: # fill out defaults if not defaults: @@ -1599,13 +1603,13 @@ for format in formats: try: - when, offset = strdate(string, format, defaults) + when, offset = strdate(date, format, defaults) except (ValueError, OverflowError): pass else: break else: - raise Abort(_('invalid date: %r ') % string) + raise Abort(_('invalid date: %r ') % date) # validate explicit (probably user-specified) date and # time zone offset. values must fit in signed 32 bits for # current 32-bit linux runtimes. timezones go from UTC-12
--- a/tests/test-commit.out Sun Feb 17 12:53:57 2008 +0100 +++ b/tests/test-commit.out Sun Feb 17 21:34:28 2008 +0100 @@ -2,16 +2,10 @@ transaction abort! rollback completed abort: empty commit message -transaction abort! -rollback completed abort: impossible time zone offset: 4444444 -transaction abort! -rollback completed abort: invalid date: '1\t15.1' -transaction abort! -rollback completed abort: invalid date: 'foo bar' -nothing changed +abort: date exceeds 32 bits: 111111111111 % commit added file that has been deleted nothing changed abort: file bar not found!
--- a/tests/test-parse-date.out Sun Feb 17 12:53:57 2008 +0100 +++ b/tests/test-parse-date.out Sun Feb 17 21:34:28 2008 +0100 @@ -3,14 +3,8 @@ merging with changeset 2:e6c3abc120e7 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) -transaction abort! -rollback completed abort: invalid date: 'should fail' -transaction abort! -rollback completed abort: date exceeds 32 bits: 100000000000000000 -transaction abort! -rollback completed abort: impossible time zone offset: 1400000 Sun Jan 15 13:30:00 2006 +0500 Sun Jan 15 13:30:00 2006 -0800