diff --git a/hgext/fetch.py b/hgext/fetch.py --- a/hgext/fetch.py +++ b/hgext/fetch.py @@ -65,6 +65,10 @@ def fetch(ui, repo, source='default', ** 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 ' diff --git a/hgext/gpg.py b/hgext/gpg.py --- a/hgext/gpg.py +++ b/hgext/gpg.py @@ -203,6 +203,11 @@ def sign(ui, repo, *revs, **opts): 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: diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -612,6 +612,8 @@ class queue: 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 @@ class queue: 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 @@ class queue: 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 @@ class queue: comments = ['From: ' + newuser, ''] + comments user = newuser - newdate = opts.get('date') if newdate: if setheaderfield(comments, ['# Date '], newdate): date = newdate diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1115,6 +1115,9 @@ def walkchangerevs(ui, repo, pats, chang 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 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -196,6 +196,10 @@ def backout(ui, repo, node=None, rev=Non 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 @@ def import_(ui, repo, patch1, *patches, """ 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) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -202,6 +202,7 @@ class localrepository(repo.repository): 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 ' diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1572,17 +1572,21 @@ def strdate(string, format, defaults=[]) 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 @@ def parsedate(string, formats=None, defa 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 diff --git a/tests/test-commit.out b/tests/test-commit.out --- a/tests/test-commit.out +++ b/tests/test-commit.out @@ -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! diff --git a/tests/test-parse-date.out b/tests/test-parse-date.out --- a/tests/test-parse-date.out +++ b/tests/test-parse-date.out @@ -3,14 +3,8 @@ changeset 3:107ce1ee2b43 backs out chang 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