comparison mercurial/cmdutil.py @ 36607:c6061cadb400

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
author Boris Feld <boris.feld@octobus.net>
date Thu, 15 Feb 2018 17:18:26 +0100
parents aa3294027936
children 2dce0049176c
comparison
equal deleted inserted replaced
36606:4de15c54e59f 36607:c6061cadb400
45 templatekw, 45 templatekw,
46 templater, 46 templater,
47 util, 47 util,
48 vfs as vfsmod, 48 vfs as vfsmod,
49 ) 49 )
50 from .utils import dateutil
50 stringio = util.stringio 51 stringio = util.stringio
51 52
52 # templates of common command options 53 # templates of common command options
53 54
54 dryrunopts = [ 55 dryrunopts = [
1528 prev = nullid 1529 prev = nullid
1529 1530
1530 write("# HG changeset patch\n") 1531 write("# HG changeset patch\n")
1531 write("# User %s\n" % ctx.user()) 1532 write("# User %s\n" % ctx.user())
1532 write("# Date %d %d\n" % ctx.date()) 1533 write("# Date %d %d\n" % ctx.date())
1533 write("# %s\n" % util.datestr(ctx.date())) 1534 write("# %s\n" % dateutil.datestr(ctx.date()))
1534 if branch and branch != 'default': 1535 if branch and branch != 'default':
1535 write("# Branch %s\n" % branch) 1536 write("# Branch %s\n" % branch)
1536 write("# Node ID %s\n" % hex(node)) 1537 write("# Node ID %s\n" % hex(node))
1537 write("# Parent %s\n" % hex(prev)) 1538 write("# Parent %s\n" % hex(prev))
1538 if len(parents) > 1: 1539 if len(parents) > 1:
1627 fm.plain('\n') 1628 fm.plain('\n')
1628 1629
1629 def finddate(ui, repo, date): 1630 def finddate(ui, repo, date):
1630 """Find the tipmost changeset that matches the given date spec""" 1631 """Find the tipmost changeset that matches the given date spec"""
1631 1632
1632 df = util.matchdate(date) 1633 df = dateutil.matchdate(date)
1633 m = scmutil.matchall(repo) 1634 m = scmutil.matchall(repo)
1634 results = {} 1635 results = {}
1635 1636
1636 def prep(ctx, fns): 1637 def prep(ctx, fns):
1637 d = ctx.date() 1638 d = ctx.date()
1640 1641
1641 for ctx in walkchangerevs(repo, m, {'rev': None}, prep): 1642 for ctx in walkchangerevs(repo, m, {'rev': None}, prep):
1642 rev = ctx.rev() 1643 rev = ctx.rev()
1643 if rev in results: 1644 if rev in results:
1644 ui.status(_("found revision %s from %s\n") % 1645 ui.status(_("found revision %s from %s\n") %
1645 (rev, util.datestr(results[rev]))) 1646 (rev, dateutil.datestr(results[rev])))
1646 return '%d' % rev 1647 return '%d' % rev
1647 1648
1648 raise error.Abort(_("revision matching date not found")) 1649 raise error.Abort(_("revision matching date not found"))
1649 1650
1650 def increasingwindows(windowsize=8, sizelimit=512): 1651 def increasingwindows(windowsize=8, sizelimit=512):
2259 2260
2260 def commit(ui, repo, commitfunc, pats, opts): 2261 def commit(ui, repo, commitfunc, pats, opts):
2261 '''commit the specified files or all outstanding changes''' 2262 '''commit the specified files or all outstanding changes'''
2262 date = opts.get('date') 2263 date = opts.get('date')
2263 if date: 2264 if date:
2264 opts['date'] = util.parsedate(date) 2265 opts['date'] = dateutil.parsedate(date)
2265 message = logmessage(ui, opts) 2266 message = logmessage(ui, opts)
2266 matcher = scmutil.match(repo[None], pats, opts) 2267 matcher = scmutil.match(repo[None], pats, opts)
2267 2268
2268 dsguard = None 2269 dsguard = None
2269 # extract addremove carefully -- this function can be called from a command 2270 # extract addremove carefully -- this function can be called from a command
2324 2325
2325 user = opts.get('user') or old.user() 2326 user = opts.get('user') or old.user()
2326 date = opts.get('date') or old.date() 2327 date = opts.get('date') or old.date()
2327 2328
2328 # Parse the date to allow comparison between date and old.date() 2329 # Parse the date to allow comparison between date and old.date()
2329 date = util.parsedate(date) 2330 date = dateutil.parsedate(date)
2330 2331
2331 if len(old.parents()) > 1: 2332 if len(old.parents()) > 1:
2332 # ctx.files() isn't reliable for merges, so fall back to the 2333 # ctx.files() isn't reliable for merges, so fall back to the
2333 # slower repo.status() method 2334 # slower repo.status() method
2334 files = set([fn for st in repo.status(base, old)[:3] 2335 files = set([fn for st in repo.status(base, old)[:3]