diff --git a/contrib/benchmarks/__init__.py b/contrib/benchmarks/__init__.py index 8f5bf6ad67..8670fc0625 100644 --- a/contrib/benchmarks/__init__.py +++ b/contrib/benchmarks/__init__.py @@ -50,7 +50,7 @@ outputre = re.compile((r'! wall (\d+.\d+) comb \d+.\d+ user \d+.\d+ sys ' 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')) diff --git a/contrib/simplemerge b/contrib/simplemerge index 53916737c5..1303cfc658 100755 --- a/contrib/simplemerge +++ b/contrib/simplemerge @@ -54,7 +54,7 @@ try: 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() diff --git a/doc/check-seclevel.py b/doc/check-seclevel.py index cbff7d3a0c..9417bb5659 100755 --- a/doc/check-seclevel.py +++ b/doc/check-seclevel.py @@ -158,7 +158,7 @@ option. (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') diff --git a/doc/gendoc.py b/doc/gendoc.py index 414fc0773c..7a72386ba1 100755 --- a/doc/gendoc.py +++ b/doc/gendoc.py @@ -217,7 +217,7 @@ if __name__ == "__main__": if len(sys.argv) > 1: doc = sys.argv[1] - ui = uimod.ui() + ui = uimod.ui.load() if doc == 'hg.1.gendoc': showdoc(ui) else: diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py index f8208daafd..556713b8b5 100644 --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -101,7 +101,7 @@ def dispatch(req): 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') diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py index 8e15dfa69c..51c93c3ee5 100644 --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -224,7 +224,7 @@ class hgweb(object): 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 @@ def getwebview(repo): return repo.filtered(viewconfig) else: return repo.filtered('served') - diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py index 568aa248ab..3982a33451 100644 --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -136,7 +136,7 @@ class hgwebdir(object): 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 diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py index b9ca6262ed..c60a3efff3 100644 --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -1302,7 +1302,7 @@ def help(web, req, tmpl): 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. diff --git a/mercurial/ui.py b/mercurial/ui.py index cdbd6ba7e0..5777d4887d 100644 --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -96,6 +96,12 @@ default = %s 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 @@ class ui(object): # 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) diff --git a/tests/dummysmtpd.py b/tests/dummysmtpd.py index 42b9112170..60b9fd4c1c 100755 --- a/tests/dummysmtpd.py +++ b/tests/dummysmtpd.py @@ -37,7 +37,7 @@ class dummysmtpsecureserver(dummysmtpserver): 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) diff --git a/tests/hghave.py b/tests/hghave.py index cd330848fd..f3ded3d7e5 100644 --- a/tests/hghave.py +++ b/tests/hghave.py @@ -449,7 +449,7 @@ def has_sslcontext(): @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 @@ def has_defaultcacertsloaded(): if not has_sslcontext(): return False - ui = uimod.ui() + ui = uimod.ui.load() cafile = sslutil._defaultcacerts(ui) ctx = ssl.create_default_context() if cafile: diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py index 7746f9d957..fdb1950c60 100644 --- a/tests/test-ancestor.py +++ b/tests/test-ancestor.py @@ -218,7 +218,7 @@ dagtests = [ '+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 diff --git a/tests/test-basic.t b/tests/test-basic.t index f5f62dbb1f..8cc81db8da 100644 --- a/tests/test-basic.t +++ b/tests/test-basic.t @@ -34,7 +34,7 @@ Verify that updating to revision 0 via commands.update() works properly $ cat < 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 diff --git a/tests/test-bisect.t b/tests/test-bisect.t index 4c4ecf5fc5..c3d23378af 100644 --- a/tests/test-bisect.t +++ b/tests/test-bisect.t @@ -456,7 +456,7 @@ test bisecting command > #!/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 diff --git a/tests/test-clone.t b/tests/test-clone.t index 3aaf43fd0e..b2d11bbc25 100644 --- a/tests/test-clone.t +++ b/tests/test-clone.t @@ -515,7 +515,7 @@ iterable in addbranchrevs() $ cat < 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 @@ iterable in addbranchrevs() $ cat < 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",]) diff --git a/tests/test-commit-interactive-curses.t b/tests/test-commit-interactive-curses.t index aeaf86e114..b8307dcf82 100644 --- a/tests/test-commit-interactive-curses.t +++ b/tests/test-commit-interactive-curses.t @@ -325,7 +325,7 @@ The default interface is text $ chunkselectorinterface() { > python < from mercurial import hg, ui, parsers;\ - > repo = hg.repository(ui.ui(), ".");\ + > repo = hg.repository(ui.ui.load(), ".");\ > print repo.ui.interface("chunkselector") > EOF > } diff --git a/tests/test-commit-multiple.t b/tests/test-commit-multiple.t index 4b91769602..61363b9976 100644 --- a/tests/test-commit-multiple.t +++ b/tests/test-commit-multiple.t @@ -92,7 +92,7 @@ now test that we fixed the bug for all scripts/extensions > 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) > diff --git a/tests/test-commit.t b/tests/test-commit.t index ad78ba246d..96ff6b811e 100644 --- a/tests/test-commit.t +++ b/tests/test-commit.t @@ -609,7 +609,7 @@ verify pathauditor blocks evil filepaths $ cat > evil-commit.py < 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 @@ verify pathauditor blocks evil filepaths $ cat > evil-commit.py < 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 @@ verify pathauditor blocks evil filepaths $ cat > evil-commit.py < 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') diff --git a/tests/test-context.py b/tests/test-context.py index ef6fb2c987..4273e703bc 100644 --- a/tests/test-context.py +++ b/tests/test-context.py @@ -7,7 +7,7 @@ from mercurial import ( ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() repo = hg.repository(u, 'test1', create=1) os.chdir('test1') diff --git a/tests/test-duplicateoptions.py b/tests/test-duplicateoptions.py index 30471ee8e2..9158975167 100644 --- a/tests/test-duplicateoptions.py +++ b/tests/test-duplicateoptions.py @@ -21,7 +21,7 @@ for ext in disabled: hgrc.close() -u = uimod.ui() +u = uimod.ui.load() extensions.loadall(u) globalshort = set() diff --git a/tests/test-filecache.py b/tests/test-filecache.py index a4af664d2f..f871a8b874 100644 --- a/tests/test-filecache.py +++ b/tests/test-filecache.py @@ -141,7 +141,7 @@ def fakeuncacheable(): 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('.') diff --git a/tests/test-filelog.py b/tests/test-filelog.py index 8caaac5d39..f870dbaa8f 100755 --- a/tests/test-filelog.py +++ b/tests/test-filelog.py @@ -13,7 +13,7 @@ from mercurial import ( ui as uimod, ) -myui = uimod.ui() +myui = uimod.ui.load() repo = hg.repository(myui, path='.', create=True) fl = repo.file('foobar') diff --git a/tests/test-hgweb-auth.py b/tests/test-hgweb-auth.py index a2b928044a..a39e954379 100644 --- a/tests/test-hgweb-auth.py +++ b/tests/test-hgweb-auth.py @@ -15,7 +15,7 @@ class myui(uimod.ui): def interactive(self): return False -origui = myui() +origui = myui.load() def writeauth(items): ui = origui.copy() diff --git a/tests/test-hgwebdir-paths.py b/tests/test-hgwebdir-paths.py index 44d4539e0c..5cba2139ef 100644 --- a/tests/test-hgwebdir-paths.py +++ b/tests/test-hgwebdir-paths.py @@ -15,7 +15,7 @@ os.chdir('webdir') 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') diff --git a/tests/test-http-branchmap.t b/tests/test-http-branchmap.t index 9798b279e3..2988e8acab 100644 --- a/tests/test-http-branchmap.t +++ b/tests/test-http-branchmap.t @@ -81,7 +81,7 @@ verify 7e7d56fe4833 (encoding fallback in branchmap to maintain compatibility wi > 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 diff --git a/tests/test-propertycache.py b/tests/test-propertycache.py index a654cd4ba2..f61192b7fe 100644 --- a/tests/test-propertycache.py +++ b/tests/test-propertycache.py @@ -46,7 +46,7 @@ localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar # 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() diff --git a/tests/test-revlog-ancestry.py b/tests/test-revlog-ancestry.py index 7af6679a51..e8d11cf09b 100644 --- a/tests/test-revlog-ancestry.py +++ b/tests/test-revlog-ancestry.py @@ -6,7 +6,7 @@ from mercurial import ( ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() repo = hg.repository(u, 'test1', create=1) os.chdir('test1') diff --git a/tests/test-status-inprocess.py b/tests/test-status-inprocess.py index ff60105fe1..362689aa08 100755 --- a/tests/test-status-inprocess.py +++ b/tests/test-status-inprocess.py @@ -7,7 +7,7 @@ from mercurial import ( ui as uimod, ) -u = uimod.ui() +u = uimod.ui.load() print('% creating repo') repo = localrepo.localrepository(u, '.', create=True) diff --git a/tests/test-symlink-os-yes-fs-no.py b/tests/test-symlink-os-yes-fs-no.py index 195181f840..84c64db266 100644 --- a/tests/test-symlink-os-yes-fs-no.py +++ b/tests/test-symlink-os-yes-fs-no.py @@ -17,7 +17,7 @@ BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg') 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 @@ for f in 'test0/a.lnk', 'test0/d/b.lnk': 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') diff --git a/tests/test-trusted.py b/tests/test-trusted.py index f32ec4a319..0ab638e212 100644 --- a/tests/test-trusted.py +++ b/tests/test-trusted.py @@ -66,7 +66,7 @@ def testui(user='foo', group='bar', tusers=(), tgroups=(), 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(u.config('foobar', 'baz')) 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() diff --git a/tests/test-ui-color.py b/tests/test-ui-color.py index cfcd0accc2..d2ad194af4 100644 --- a/tests/test-ui-color.py +++ b/tests/test-ui-color.py @@ -23,7 +23,7 @@ hgrc.write('[extensions]\n') 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 diff --git a/tests/test-ui-config.py b/tests/test-ui-config.py index dbc9e63551..d00589a6af 100644 --- a/tests/test-ui-config.py +++ b/tests/test-ui-config.py @@ -5,7 +5,7 @@ from mercurial import ( ui as uimod, ) -testui = uimod.ui() +testui = uimod.ui.load() parsed = dispatch._parseconfig(testui, [ 'values.string=string value', 'values.bool1=true', diff --git a/tests/test-ui-verbosity.py b/tests/test-ui-verbosity.py index da83ec1343..d7fe527f37 100644 --- a/tests/test-ui-verbosity.py +++ b/tests/test-ui-verbosity.py @@ -32,7 +32,7 @@ for i in xrange(64): 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))) diff --git a/tests/test-walkrepo.py b/tests/test-walkrepo.py index 3fc489a5b2..a21fdc0b82 100644 --- a/tests/test-walkrepo.py +++ b/tests/test-walkrepo.py @@ -16,7 +16,7 @@ pjoin = os.path.join walkrepos = scmutil.walkrepos checklink = util.checklink -u = uimod.ui() +u = uimod.ui.load() sym = checklink('.') hg.repository(u, 'top1', create=1)