comparison mercurial/ui.py @ 14076:924c82157d46

url: move URL parsing functions into util to improve startup time The introduction of the new URL parsing code has created a startup time regression. This is mainly due to the use of url.hasscheme() in the ui class. It ends up importing many libraries that the url module requires. This fix helps marginally, but if we can get rid of the urllib import in the URL parser all together, startup time will go back to normal. perfstartup time before the URL refactoring (8796fb6af67e): ! wall 0.050692 comb 0.000000 user 0.000000 sys 0.000000 (best of 100) current startup time (139fb11210bb): ! wall 0.070685 comb 0.000000 user 0.000000 sys 0.000000 (best of 100) after this change: ! wall 0.064667 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
author Brodie Rao <brodie@bitheap.org>
date Sat, 30 Apr 2011 09:43:20 -0700
parents af60153b5e3b
children fa2b596db182
comparison
equal deleted inserted replaced
14075:bc101902a68d 14076:924c82157d46
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 import errno, getpass, os, socket, sys, tempfile, traceback 9 import errno, getpass, os, socket, sys, tempfile, traceback
10 import config, scmutil, util, error, url 10 import config, scmutil, util, error
11 11
12 class ui(object): 12 class ui(object):
13 def __init__(self, src=None): 13 def __init__(self, src=None):
14 self._buffers = [] 14 self._buffers = []
15 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False 15 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
109 if '%%' in p: 109 if '%%' in p:
110 self.warn(_("(deprecated '%%' in path %s=%s from %s)\n") 110 self.warn(_("(deprecated '%%' in path %s=%s from %s)\n")
111 % (n, p, self.configsource('paths', n))) 111 % (n, p, self.configsource('paths', n)))
112 p = p.replace('%%', '%') 112 p = p.replace('%%', '%')
113 p = util.expandpath(p) 113 p = util.expandpath(p)
114 if not url.hasscheme(p) and not os.path.isabs(p): 114 if not util.hasscheme(p) and not os.path.isabs(p):
115 p = os.path.normpath(os.path.join(root, p)) 115 p = os.path.normpath(os.path.join(root, p))
116 c.set("paths", n, p) 116 c.set("paths", n, p)
117 117
118 if section in (None, 'ui'): 118 if section in (None, 'ui'):
119 # update ui options 119 # update ui options
330 user = util.shortuser(user) 330 user = util.shortuser(user)
331 return user 331 return user
332 332
333 def expandpath(self, loc, default=None): 333 def expandpath(self, loc, default=None):
334 """Return repository location relative to cwd or from [paths]""" 334 """Return repository location relative to cwd or from [paths]"""
335 if url.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')): 335 if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
336 return loc 336 return loc
337 337
338 path = self.config('paths', loc) 338 path = self.config('paths', loc)
339 if not path and default is not None: 339 if not path and default is not None:
340 path = self.config('paths', default) 340 path = self.config('paths', default)