Commit 60d50d7c authored by Boris Feld's avatar Boris Feld
Browse files

util: extract all date-related utils in utils/dateutil module

With this commit, util.py lose 262 lines

Note for extensions author, if this commit breaks your extension, you can pull
the step-by-step split here to help you more easily pinpoint the renaming that
broke your extension:

    hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ac1f6453010d

Differential Revision: https://phab.mercurial-scm.org/D2282
parent 4de15c54e59f
......@@ -59,8 +59,8 @@ from mercurial import (
patch,
registrar,
scmutil,
util,
)
from mercurial.utils import dateutil
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
......@@ -382,7 +382,7 @@ def synthesize(ui, repo, descpath, **opts):
message = 'synthesized wide repo with %d files' % (len(files),)
mc = context.memctx(repo, [pctx.node(), nullid], message,
files, filectxfn, ui.username(),
'%d %d' % util.makedate())
'%d %d' % dateutil.makedate())
initnode = mc.commit()
if ui.debugflag:
hexfn = hex
......
......@@ -49,6 +49,7 @@ from mercurial import (
ui as uimod,
util,
)
from mercurial.utils import dateutil
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
......@@ -164,7 +165,7 @@ def wrapui(ui):
return
ui._bbinlog = True
default = self.configdate('devel', 'default-date')
date = util.datestr(default, '%Y/%m/%d %H:%M:%S')
date = dateutil.datestr(default, '%Y/%m/%d %H:%M:%S')
user = util.getuser()
pid = '%d' % util.getpid()
formattedmsg = msg[0] % msg[1:]
......
......@@ -23,8 +23,8 @@ from mercurial import (
pycompat,
registrar,
scmutil,
util,
)
from mercurial.utils import dateutil
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -65,7 +65,7 @@ def countrate(ui, repo, amap, *pats, **opts):
rate = {}
df = False
if opts.get('date'):
df = util.matchdate(opts['date'])
df = dateutil.matchdate(opts['date'])
m = scmutil.match(repo[None], pats, opts)
def prep(ctx, fns):
......
......@@ -541,7 +541,7 @@ class mapfile(dict):
self.fp = None
def makedatetimestamp(t):
"""Like util.makedate() but for time t instead of current time"""
"""Like dateutil.makedate() but for time t instead of current time"""
delta = (datetime.datetime.utcfromtimestamp(t) -
datetime.datetime.fromtimestamp(t))
tz = delta.days * 86400 + delta.seconds
......
......@@ -19,6 +19,7 @@ from mercurial import (
scmutil,
util,
)
from mercurial.utils import dateutil
from . import (
bzr,
......@@ -355,7 +356,7 @@ class converter(object):
dates = {}
def getdate(n):
if n not in dates:
dates[n] = util.parsedate(self.commitcache[n].date)
dates[n] = dateutil.parsedate(self.commitcache[n].date)
return dates[n]
def picknext(nodes):
......
......@@ -18,6 +18,7 @@ from mercurial import (
pycompat,
util,
)
from mercurial.utils import dateutil
from . import (
common,
......@@ -93,7 +94,7 @@ class convert_cvs(converter_source):
cs.comment = self.recode(cs.comment)
if self.ui.configbool('convert', 'localtimezone'):
cs.date = makedatetimestamp(cs.date[0])
date = util.datestr(cs.date, '%Y-%m-%d %H:%M:%S %1%2')
date = dateutil.datestr(cs.date, '%Y-%m-%d %H:%M:%S %1%2')
self.tags.update(dict.fromkeys(cs.tags, id))
files = {}
......
......@@ -17,6 +17,7 @@ from mercurial import (
pycompat,
util,
)
from mercurial.utils import dateutil
pickle = util.pickle
......@@ -192,7 +193,7 @@ def createlog(ui, directory=None, root="", rlog=True, cache=None):
if oldlog:
date = oldlog[-1].date # last commit date as a (time,tz) tuple
date = util.datestr(date, '%Y/%m/%d %H:%M:%S %1%2')
date = dateutil.datestr(date, '%Y/%m/%d %H:%M:%S %1%2')
# build the CVS commandline
cmd = ['cvs', '-q']
......@@ -336,7 +337,7 @@ def createlog(ui, directory=None, root="", rlog=True, cache=None):
if len(d.split()) != 3:
# cvs log dates always in GMT
d = d + ' UTC'
e.date = util.parsedate(d, ['%y/%m/%d %H:%M:%S',
e.date = dateutil.parsedate(d, ['%y/%m/%d %H:%M:%S',
'%Y/%m/%d %H:%M:%S',
'%Y-%m-%d %H:%M:%S'])
e.author = scache(match.group(2))
......@@ -901,7 +902,7 @@ def debugcvsps(ui, *args, **opts):
# bug-for-bug compatibility with cvsps.
ui.write('---------------------\n')
ui.write(('PatchSet %d \n' % cs.id))
ui.write(('Date: %s\n' % util.datestr(cs.date,
ui.write(('Date: %s\n' % dateutil.datestr(cs.date,
'%Y/%m/%d %H:%M:%S %1%2')))
ui.write(('Author: %s\n' % cs.author))
ui.write(('Branch: %s\n' % (cs.branch or 'HEAD')))
......
......@@ -16,6 +16,7 @@ from mercurial import (
error,
util,
)
from mercurial.utils import dateutil
from . import common
NoRepo = common.NoRepo
......@@ -148,12 +149,14 @@ class darcs_source(common.converter_source, common.commandline):
def getcommit(self, rev):
elt = self.changes[rev]
date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
dateformat = '%a %b %d %H:%M:%S %Z %Y'
date = dateutil.strdate(elt.get('local_date'), dateformat)
desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
# etree can return unicode objects for name, comment, and author,
# so recode() is used to ensure str objects are emitted.
newdateformat = '%Y-%m-%d %H:%M:%S %1%2'
return common.commit(author=self.recode(elt.get('author')),
date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
date=dateutil.datestr(date, newdateformat),
desc=self.recode(desc).strip(),
parents=self.parents[rev])
......
......@@ -19,6 +19,7 @@ from mercurial import (
error,
util,
)
from mercurial.utils import dateutil
from . import common
class gnuarch_source(common.converter_source, common.commandline):
......@@ -280,8 +281,8 @@ class gnuarch_source(common.converter_source, common.commandline):
catlog = self.catlogparser.parsestr(data)
# Commit date
self.changes[rev].date = util.datestr(
util.strdate(catlog['Standard-date'],
self.changes[rev].date = dateutil.datestr(
dateutil.strdate(catlog['Standard-date'],
'%Y-%m-%d %H:%M:%S'))
# Commit author
......
......@@ -36,6 +36,7 @@ from mercurial import (
scmutil,
util,
)
from mercurial.utils import dateutil
stringio = util.stringio
from . import common
......@@ -583,7 +584,7 @@ class mercurial_source(common.converter_source):
crev = rev
return common.commit(author=ctx.user(),
date=util.datestr(ctx.date(),
date=dateutil.datestr(ctx.date(),
'%Y-%m-%d %H:%M:%S %1%2'),
desc=ctx.description(),
rev=crev,
......
......@@ -14,8 +14,8 @@ from mercurial.i18n import _
from mercurial import (
error,
pycompat,
util,
)
from mercurial.utils import dateutil
from . import common
......@@ -310,9 +310,10 @@ class monotone_source(common.converter_source, common.commandline):
certs = self.mtngetcerts(rev)
if certs.get('suspend') == certs["branch"]:
extra['close'] = 1
dateformat = "%Y-%m-%dT%H:%M:%S"
return common.commit(
author=certs["author"],
date=util.datestr(util.strdate(certs["date"], "%Y-%m-%dT%H:%M:%S")),
date=dateutil.datestr(dateutil.strdate(certs["date"], dateformat)),
desc=certs["changelog"],
rev=rev,
parents=self.mtnrun("parents", rev).splitlines(),
......
......@@ -14,6 +14,7 @@ from mercurial import (
error,
util,
)
from mercurial.utils import dateutil
from . import common
......@@ -346,7 +347,7 @@ class p4_source(common.converter_source):
parents = []
return common.commit(author=self.recode(obj["user"]),
date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
date=dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
parents=parents, desc=desc, branch=None, rev=obj['change'],
extra={"p4": obj['change'], "convert_revision": obj['change']})
......
......@@ -16,6 +16,7 @@ from mercurial import (
util,
vfs as vfsmod,
)
from mercurial.utils import dateutil
from . import common
......@@ -891,7 +892,7 @@ class svn_source(converter_source):
# Example SVN datetime. Includes microseconds.
# ISO-8601 conformant
# '2007-01-04T17:35:00.902377Z'
date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
date = dateutil.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
if self.ui.configbool('convert', 'localtimezone'):
date = makedatetimestamp(date[0])
......@@ -913,7 +914,7 @@ class svn_source(converter_source):
branch = None
cset = commit(author=author,
date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
date=dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
desc=log,
parents=parents,
branch=branch,
......
......@@ -23,6 +23,7 @@ from mercurial import (
registrar,
util,
)
from mercurial.utils import dateutil
release = lock.release
cmdtable = {}
......@@ -64,7 +65,7 @@ def fetch(ui, repo, source='default', **opts):
opts = pycompat.byteskwargs(opts)
date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
opts['date'] = dateutil.parsedate(date)
parent, _p2 = repo.dirstate.parents()
branch = repo.dirstate.branch()
......
......@@ -21,6 +21,7 @@ from mercurial import (
registrar,
util,
)
from mercurial.utils import dateutil
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -258,7 +259,7 @@ def _dosign(ui, repo, *revs, **opts):
date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
opts['date'] = dateutil.parsedate(date)
if revs:
nodes = [repo.lookup(n) for n in revs]
......
......@@ -35,6 +35,7 @@ from mercurial import (
registrar,
util,
)
from mercurial.utils import dateutil
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -326,7 +327,7 @@ class journalstorage(object):
newhashes = [newhashes]
entry = journalentry(
util.makedate(), self.user, self.command, namespace, name,
dateutil.makedate(), self.user, self.command, namespace, name,
oldhashes, newhashes)
vfs = self.vfs
......
......@@ -111,6 +111,7 @@ from mercurial import (
templatefilters,
util,
)
from mercurial.utils import dateutil
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -156,21 +157,23 @@ configitem('keywordset', 'svn',
def utcdate(text):
'''Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
'''
return util.datestr((util.parsedate(text)[0], 0), '%Y/%m/%d %H:%M:%S')
dateformat = '%Y/%m/%d %H:%M:%S'
return dateutil.datestr((dateutil.parsedate(text)[0], 0), dateformat)
# date like in svn's $Date
@templatefilter('svnisodate')
def svnisodate(text):
'''Date. Returns a date in this format: "2009-08-18 13:00:13
+0200 (Tue, 18 Aug 2009)".
'''
return util.datestr(text, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
return dateutil.datestr(text, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
# date like in svn's $Id
@templatefilter('svnutcdate')
def svnutcdate(text):
'''Date. Returns a UTC-date in this format: "2009-08-18
11:00:13Z".
'''
return util.datestr((util.parsedate(text)[0], 0), '%Y-%m-%d %H:%M:%SZ')
dateformat = '%Y-%m-%d %H:%M:%SZ'
return dateutil.datestr((dateutil.parsedate(text)[0], 0), dateformat)
# make keyword tools accessible
kwtools = {'hgcmd': ''}
......
......@@ -98,6 +98,7 @@ from mercurial import (
util,
vfs as vfsmod,
)
from mercurial.utils import dateutil
release = lockmod.release
seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
......@@ -1201,7 +1202,7 @@ class queue(object):
user = opts.get('user')
date = opts.get('date')
if date:
date = util.parsedate(date)
date = dateutil.parsedate(date)
diffopts = self.diffopts({'git': opts.get('git')}, plain=True)
if opts.get('checkname', True):
self.checkpatchname(patchfn)
......@@ -1644,7 +1645,7 @@ class queue(object):
newuser = opts.get('user')
newdate = opts.get('date')
if newdate:
newdate = '%d %d' % util.parsedate(newdate)
newdate = '%d %d' % dateutil.parsedate(newdate)
wlock = repo.wlock()
try:
......@@ -2596,7 +2597,7 @@ def setupheaderopts(ui, opts):
if not opts.get('user') and opts.get('currentuser'):
opts['user'] = ui.username()
if not opts.get('date') and opts.get('currentdate'):
opts['date'] = "%d %d" % util.makedate()
opts['date'] = "%d %d" % dateutil.makedate()
@command("^qnew",
[('e', 'edit', None, _('invoke editor on commit messages')),
......
......@@ -149,6 +149,7 @@ from mercurial import (
registrar,
util,
)
from mercurial.utils import dateutil
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
......@@ -360,7 +361,7 @@ class notifier(object):
for k, v in headers:
msg[k] = v
msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
msg['Date'] = dateutil.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
# try to make subject line exist and be useful
if not subject:
......
......@@ -99,6 +99,7 @@ from mercurial import (
templater,
util,
)
from mercurial.utils import dateutil
stringio = util.stringio
cmdtable = {}
......@@ -665,9 +666,9 @@ def email(ui, repo, *revs, **opts):
# start
if date:
start_time = util.parsedate(date)
start_time = dateutil.parsedate(date)
else:
start_time = util.makedate()
start_time = dateutil.makedate()
def genmsgid(id):
return '<%s.%d@%s>' % (id[:20], int(start_time[0]),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment