Mercurial > hg
changeset 30559:d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
This allows us to write doctests depending on a ui object, but not on global
configs.
ui.load() is a class method so we can do wsgiui.load(). All ui() calls but
for doctests are replaced with ui.load(). Some of them could be changed to
not load configs later.
line wrap: on
line diff
--- a/contrib/benchmarks/__init__.py Wed Nov 30 19:23:04 2016 +0000 +++ b/contrib/benchmarks/__init__.py Sat Oct 22 14:35:10 2016 +0900 @@ -50,7 +50,7 @@ def runperfcommand(reponame, command, *args, **kwargs): os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "") - ui = uimod.ui() + ui = uimod.ui.load() repo = hg.repository(ui, os.path.join(reposdir, reponame)) perfext = extensions.load(ui, 'perfext', os.path.join(basedir, 'contrib', 'perf.py'))
--- a/contrib/simplemerge Wed Nov 30 19:23:04 2016 +0000 +++ b/contrib/simplemerge Sat Oct 22 14:35:10 2016 +0900 @@ -54,7 +54,7 @@ sys.exit(0) if len(args) != 3: raise ParseError(_('wrong number of arguments')) - sys.exit(simplemerge.simplemerge(ui.ui(), *args, **opts)) + sys.exit(simplemerge.simplemerge(ui.ui.load(), *args, **opts)) except ParseError as e: sys.stdout.write("%s: %s\n" % (sys.argv[0], e)) showhelp()
--- a/doc/check-seclevel.py Wed Nov 30 19:23:04 2016 +0000 +++ b/doc/check-seclevel.py Sat Oct 22 14:35:10 2016 +0900 @@ -158,7 +158,7 @@ (options, args) = optparser.parse_args() - ui = uimod.ui() + ui = uimod.ui.load() ui.setconfig('ui', 'verbose', options.verbose, '--verbose') ui.setconfig('ui', 'debug', options.debug, '--debug')
--- a/doc/gendoc.py Wed Nov 30 19:23:04 2016 +0000 +++ b/doc/gendoc.py Sat Oct 22 14:35:10 2016 +0900 @@ -217,7 +217,7 @@ if len(sys.argv) > 1: doc = sys.argv[1] - ui = uimod.ui() + ui = uimod.ui.load() if doc == 'hg.1.gendoc': showdoc(ui) else:
--- a/mercurial/dispatch.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/dispatch.py Sat Oct 22 14:35:10 2016 +0900 @@ -101,7 +101,7 @@ try: if not req.ui: - req.ui = uimod.ui() + req.ui = uimod.ui.load() if '--traceback' in req.args: req.ui.setconfig('ui', 'traceback', 'on', '--traceback')
--- a/mercurial/hgweb/hgweb_mod.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/hgweb/hgweb_mod.py Sat Oct 22 14:35:10 2016 +0900 @@ -224,7 +224,7 @@ if baseui: u = baseui.copy() else: - u = uimod.ui() + u = uimod.ui.load() r = hg.repository(u, repo) else: # we trust caller to give us a private copy @@ -467,4 +467,3 @@ return repo.filtered(viewconfig) else: return repo.filtered('served') -
--- a/mercurial/hgweb/hgwebdir_mod.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Oct 22 14:35:10 2016 +0900 @@ -136,7 +136,7 @@ if self.baseui: u = self.baseui.copy() else: - u = uimod.ui() + u = uimod.ui.load() u.setconfig('ui', 'report_untrusted', 'off', 'hgwebdir') u.setconfig('ui', 'nontty', 'true', 'hgwebdir') # displaying bundling progress bar while serving feels wrong and may
--- a/mercurial/hgweb/webcommands.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/hgweb/webcommands.py Sat Oct 22 14:35:10 2016 +0900 @@ -1302,7 +1302,7 @@ return tmpl('helptopics', topics=topics, title=topicname, subindex=True) - u = webutil.wsgiui() + u = webutil.wsgiui.load() u.verbose = True # Render a page from a sub-topic.
--- a/mercurial/ui.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/ui.py Sat Oct 22 14:35:10 2016 +0900 @@ -96,6 +96,12 @@ class ui(object): def __init__(self, src=None): + """Create a fresh new ui object if no src given + + Use uimod.ui.load() to create a ui which knows global and user configs. + In most cases, you should use ui.copy() to create a copy of an existing + ui object. + """ # _buffers: used for temporary capture of output self._buffers = [] # 3-tuple describing how each buffer in the stack behaves. @@ -138,12 +144,18 @@ # shared read-only environment self.environ = os.environ - # we always trust global config files - for f in scmutil.rcpath(): - self.readconfig(f, trust=True) self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm() + @classmethod + def load(cls): + """Create a ui and load global and user configs""" + u = cls() + # we always trust global config files + for f in scmutil.rcpath(): + u.readconfig(f, trust=True) + return u + def copy(self): return self.__class__(self)
--- a/tests/dummysmtpd.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/dummysmtpd.py Sat Oct 22 14:35:10 2016 +0900 @@ -37,7 +37,7 @@ if not pair: return conn, addr = pair - ui = uimod.ui() + ui = uimod.ui.load() try: # wrap_socket() would block, but we don't care conn = sslutil.wrapserversocket(conn, ui, certfile=self._certfile)
--- a/tests/hghave.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/hghave.py Sat Oct 22 14:35:10 2016 +0900 @@ -449,7 +449,7 @@ @check("defaultcacerts", "can verify SSL certs by system's CA certs store") def has_defaultcacerts(): from mercurial import sslutil, ui as uimod - ui = uimod.ui() + ui = uimod.ui.load() return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts @check("defaultcacertsloaded", "detected presence of loaded system CA certs") @@ -462,7 +462,7 @@ if not has_sslcontext(): return False - ui = uimod.ui() + ui = uimod.ui.load() cafile = sslutil._defaultcacerts(ui) ctx = ssl.create_default_context() if cafile:
--- a/tests/test-ancestor.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-ancestor.py Sat Oct 22 14:35:10 2016 +0900 @@ -218,7 +218,7 @@ '+3*3/*2*2/*4*4/*4/2*4/2*2', ] def test_gca(): - u = uimod.ui() + u = uimod.ui.load() for i, dag in enumerate(dagtests): repo = hg.repository(u, 'gca%d' % i, create=1) cl = repo.changelog
--- a/tests/test-basic.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-basic.t Sat Oct 22 14:35:10 2016 +0900 @@ -34,7 +34,7 @@ $ cat <<EOF > update_to_rev0.py > from mercurial import ui, hg, commands - > myui = ui.ui() + > myui = ui.ui.load() > repo = hg.repository(myui, path='.') > commands.update(myui, repo, rev=0) > EOF
--- a/tests/test-bisect.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-bisect.t Sat Oct 22 14:35:10 2016 +0900 @@ -456,7 +456,7 @@ > #!/usr/bin/env python > import sys > from mercurial import ui, hg - > repo = hg.repository(ui.ui(), '.') + > repo = hg.repository(ui.ui.load(), '.') > if repo['.'].rev() < 6: > sys.exit(1) > EOF
--- a/tests/test-clone.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-clone.t Sat Oct 22 14:35:10 2016 +0900 @@ -515,7 +515,7 @@ $ cat <<EOF > simpleclone.py > from mercurial import ui, hg - > myui = ui.ui() + > myui = ui.ui.load() > repo = hg.repository(myui, 'a') > hg.clone(myui, {}, repo, dest="ua") > EOF @@ -528,7 +528,7 @@ $ cat <<EOF > branchclone.py > from mercurial import ui, hg, extensions - > myui = ui.ui() + > myui = ui.ui.load() > extensions.loadall(myui) > repo = hg.repository(myui, 'a') > hg.clone(myui, {}, repo, dest="ua", branch=["stable",])
--- a/tests/test-commit-interactive-curses.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-commit-interactive-curses.t Sat Oct 22 14:35:10 2016 +0900 @@ -325,7 +325,7 @@ $ chunkselectorinterface() { > python <<EOF > from mercurial import hg, ui, parsers;\ - > repo = hg.repository(ui.ui(), ".");\ + > repo = hg.repository(ui.ui.load(), ".");\ > print repo.ui.interface("chunkselector") > EOF > }
--- a/tests/test-commit-multiple.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-commit-multiple.t Sat Oct 22 14:35:10 2016 +0900 @@ -92,7 +92,7 @@ > def printfiles(repo, rev): > print "revision %s files: %s" % (rev, repo[rev].files()) > - > repo = hg.repository(ui.ui(), '.') + > repo = hg.repository(ui.ui.load(), '.') > assert len(repo) == 6, \ > "initial: len(repo): %d, expected: 6" % len(repo) >
--- a/tests/test-commit.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-commit.t Sat Oct 22 14:35:10 2016 +0900 @@ -609,7 +609,7 @@ $ cat > evil-commit.py <<EOF > from mercurial import ui, hg, context, node > notrc = u".h\u200cg".encode('utf-8') + '/hgrc' - > u = ui.ui() + > u = ui.ui.load() > r = hg.repository(u, '.') > def filectxfn(repo, memctx, path): > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned') @@ -633,7 +633,7 @@ $ cat > evil-commit.py <<EOF > from mercurial import ui, hg, context, node > notrc = "HG~1/hgrc" - > u = ui.ui() + > u = ui.ui.load() > r = hg.repository(u, '.') > def filectxfn(repo, memctx, path): > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned') @@ -651,7 +651,7 @@ $ cat > evil-commit.py <<EOF > from mercurial import ui, hg, context, node > notrc = "HG8B6C~2/hgrc" - > u = ui.ui() + > u = ui.ui.load() > r = hg.repository(u, '.') > def filectxfn(repo, memctx, path): > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
--- a/tests/test-context.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-context.py Sat Oct 22 14:35:10 2016 +0900 @@ -7,7 +7,7 @@ ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() repo = hg.repository(u, 'test1', create=1) os.chdir('test1')
--- a/tests/test-duplicateoptions.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-duplicateoptions.py Sat Oct 22 14:35:10 2016 +0900 @@ -21,7 +21,7 @@ hgrc.close() -u = uimod.ui() +u = uimod.ui.load() extensions.loadall(u) globalshort = set()
--- a/tests/test-filecache.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-filecache.py Sat Oct 22 14:35:10 2016 +0900 @@ -141,7 +141,7 @@ def test_filecache_synced(): # test old behavior that caused filecached properties to go out of sync os.system('hg init && echo a >> a && hg ci -qAm.') - repo = hg.repository(uimod.ui()) + repo = hg.repository(uimod.ui.load()) # first rollback clears the filecache, but changelog to stays in __dict__ repo.rollback() repo.commit('.')
--- a/tests/test-filelog.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-filelog.py Sat Oct 22 14:35:10 2016 +0900 @@ -13,7 +13,7 @@ ui as uimod, ) -myui = uimod.ui() +myui = uimod.ui.load() repo = hg.repository(myui, path='.', create=True) fl = repo.file('foobar')
--- a/tests/test-hgweb-auth.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-hgweb-auth.py Sat Oct 22 14:35:10 2016 +0900 @@ -15,7 +15,7 @@ def interactive(self): return False -origui = myui() +origui = myui.load() def writeauth(items): ui = origui.copy()
--- a/tests/test-hgwebdir-paths.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-hgwebdir-paths.py Sat Oct 22 14:35:10 2016 +0900 @@ -15,7 +15,7 @@ webdir = os.path.realpath('.') -u = uimod.ui() +u = uimod.ui.load() hg.repository(u, 'a', create=1) hg.repository(u, 'b', create=1) os.chdir('b')
--- a/tests/test-http-branchmap.t Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-http-branchmap.t Sat Oct 22 14:35:10 2016 +0900 @@ -81,7 +81,7 @@ > sys.stdout = StdoutWrapper(sys.stdout) > sys.stderr = StdoutWrapper(sys.stderr) > - > myui = ui.ui() + > myui = ui.ui.load() > repo = hg.repository(myui, 'a') > commands.serve(myui, repo, stdio=True, cmdserver=False) > EOF
--- a/tests/test-propertycache.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-propertycache.py Sat Oct 22 14:35:10 2016 +0900 @@ -46,7 +46,7 @@ # these tests on the real object to detect regression. repopath = os.path.join(os.environ['TESTTMP'], 'repo') assert subprocess.call(['hg', 'init', repopath]) == 0 -ui = uimod.ui() +ui = uimod.ui.load() repo = hg.repository(ui, path=repopath).unfiltered()
--- a/tests/test-revlog-ancestry.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-revlog-ancestry.py Sat Oct 22 14:35:10 2016 +0900 @@ -6,7 +6,7 @@ ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() repo = hg.repository(u, 'test1', create=1) os.chdir('test1')
--- a/tests/test-status-inprocess.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-status-inprocess.py Sat Oct 22 14:35:10 2016 +0900 @@ -7,7 +7,7 @@ ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() print('% creating repo') repo = localrepo.localrepository(u, '.', create=True)
--- a/tests/test-symlink-os-yes-fs-no.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-symlink-os-yes-fs-no.py Sat Oct 22 14:35:10 2016 +0900 @@ -17,7 +17,7 @@ if not getattr(os, "symlink", False): sys.exit(80) # SKIPPED_STATUS defined in run-tests.py -u = uimod.ui() +u = uimod.ui.load() # hide outer repo hg.peer(u, {}, '.', create=True) @@ -48,10 +48,10 @@ fp.close() # reload repository -u = uimod.ui() +u = uimod.ui.load() repo = hg.repository(u, 'test0') commands.status(u, repo) # try cloning a repo which contains symlinks -u = uimod.ui() +u = uimod.ui.load() hg.clone(u, {}, BUNDLEPATH, 'test1')
--- a/tests/test-trusted.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-trusted.py Sat Oct 22 14:35:10 2016 +0900 @@ -66,7 +66,7 @@ print('# %s user, %s group%s' % (kind[user == cuser], kind[group == cgroup], trusted)) - u = uimod.ui() + u = uimod.ui.load() u.setconfig('ui', 'debug', str(bool(debug))) u.setconfig('ui', 'report_untrusted', str(bool(report))) u.readconfig('.hg/hgrc') @@ -156,7 +156,7 @@ print() print("# read trusted, untrusted, new ui, trusted") -u = uimod.ui() +u = uimod.ui.load() u.setconfig('ui', 'debug', 'on') u.readconfig(filename) u2 = u.copy()
--- a/tests/test-ui-color.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-ui-color.py Sat Oct 22 14:35:10 2016 +0900 @@ -23,7 +23,7 @@ hgrc.write('color=\n') hgrc.close() -ui_ = uimod.ui() +ui_ = uimod.ui.load() ui_.setconfig('ui', 'formatted', 'True') # we're not interested in the output, so write that to devnull
--- a/tests/test-ui-config.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-ui-config.py Sat Oct 22 14:35:10 2016 +0900 @@ -5,7 +5,7 @@ ui as uimod, ) -testui = uimod.ui() +testui = uimod.ui.load() parsed = dispatch._parseconfig(testui, [ 'values.string=string value', 'values.bool1=true',
--- a/tests/test-ui-verbosity.py Wed Nov 30 19:23:04 2016 +0000 +++ b/tests/test-ui-verbosity.py Sat Oct 22 14:35:10 2016 +0900 @@ -32,7 +32,7 @@ f.write('debug = True\n') f.close() - u = uimod.ui() + u = uimod.ui.load() if cmd_quiet or cmd_debug or cmd_verbose: u.setconfig('ui', 'quiet', str(bool(cmd_quiet))) u.setconfig('ui', 'verbose', str(bool(cmd_verbose)))