##// END OF EJS Templates
ui: factor out ui.load() to create a ui without loading configs (API)...
Yuya Nishihara -
r30559:d83ca854 default
parent child Browse files
Show More
@@ -50,7 +50,7 b" outputre = re.compile((r'! wall (\\d+.\\d+"
50
50
51 def runperfcommand(reponame, command, *args, **kwargs):
51 def runperfcommand(reponame, command, *args, **kwargs):
52 os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "")
52 os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "")
53 ui = uimod.ui()
53 ui = uimod.ui.load()
54 repo = hg.repository(ui, os.path.join(reposdir, reponame))
54 repo = hg.repository(ui, os.path.join(reposdir, reponame))
55 perfext = extensions.load(ui, 'perfext',
55 perfext = extensions.load(ui, 'perfext',
56 os.path.join(basedir, 'contrib', 'perf.py'))
56 os.path.join(basedir, 'contrib', 'perf.py'))
@@ -54,7 +54,7 b' try:'
54 sys.exit(0)
54 sys.exit(0)
55 if len(args) != 3:
55 if len(args) != 3:
56 raise ParseError(_('wrong number of arguments'))
56 raise ParseError(_('wrong number of arguments'))
57 sys.exit(simplemerge.simplemerge(ui.ui(), *args, **opts))
57 sys.exit(simplemerge.simplemerge(ui.ui.load(), *args, **opts))
58 except ParseError as e:
58 except ParseError as e:
59 sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
59 sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
60 showhelp()
60 showhelp()
@@ -158,7 +158,7 b' option.'
158
158
159 (options, args) = optparser.parse_args()
159 (options, args) = optparser.parse_args()
160
160
161 ui = uimod.ui()
161 ui = uimod.ui.load()
162 ui.setconfig('ui', 'verbose', options.verbose, '--verbose')
162 ui.setconfig('ui', 'verbose', options.verbose, '--verbose')
163 ui.setconfig('ui', 'debug', options.debug, '--debug')
163 ui.setconfig('ui', 'debug', options.debug, '--debug')
164
164
@@ -217,7 +217,7 b' if __name__ == "__main__":'
217 if len(sys.argv) > 1:
217 if len(sys.argv) > 1:
218 doc = sys.argv[1]
218 doc = sys.argv[1]
219
219
220 ui = uimod.ui()
220 ui = uimod.ui.load()
221 if doc == 'hg.1.gendoc':
221 if doc == 'hg.1.gendoc':
222 showdoc(ui)
222 showdoc(ui)
223 else:
223 else:
@@ -101,7 +101,7 b' def dispatch(req):'
101
101
102 try:
102 try:
103 if not req.ui:
103 if not req.ui:
104 req.ui = uimod.ui()
104 req.ui = uimod.ui.load()
105 if '--traceback' in req.args:
105 if '--traceback' in req.args:
106 req.ui.setconfig('ui', 'traceback', 'on', '--traceback')
106 req.ui.setconfig('ui', 'traceback', 'on', '--traceback')
107
107
@@ -224,7 +224,7 b' class hgweb(object):'
224 if baseui:
224 if baseui:
225 u = baseui.copy()
225 u = baseui.copy()
226 else:
226 else:
227 u = uimod.ui()
227 u = uimod.ui.load()
228 r = hg.repository(u, repo)
228 r = hg.repository(u, repo)
229 else:
229 else:
230 # we trust caller to give us a private copy
230 # we trust caller to give us a private copy
@@ -467,4 +467,3 b' def getwebview(repo):'
467 return repo.filtered(viewconfig)
467 return repo.filtered(viewconfig)
468 else:
468 else:
469 return repo.filtered('served')
469 return repo.filtered('served')
470
@@ -136,7 +136,7 b' class hgwebdir(object):'
136 if self.baseui:
136 if self.baseui:
137 u = self.baseui.copy()
137 u = self.baseui.copy()
138 else:
138 else:
139 u = uimod.ui()
139 u = uimod.ui.load()
140 u.setconfig('ui', 'report_untrusted', 'off', 'hgwebdir')
140 u.setconfig('ui', 'report_untrusted', 'off', 'hgwebdir')
141 u.setconfig('ui', 'nontty', 'true', 'hgwebdir')
141 u.setconfig('ui', 'nontty', 'true', 'hgwebdir')
142 # displaying bundling progress bar while serving feels wrong and may
142 # displaying bundling progress bar while serving feels wrong and may
@@ -1302,7 +1302,7 b' def help(web, req, tmpl):'
1302 return tmpl('helptopics', topics=topics, title=topicname,
1302 return tmpl('helptopics', topics=topics, title=topicname,
1303 subindex=True)
1303 subindex=True)
1304
1304
1305 u = webutil.wsgiui()
1305 u = webutil.wsgiui.load()
1306 u.verbose = True
1306 u.verbose = True
1307
1307
1308 # Render a page from a sub-topic.
1308 # Render a page from a sub-topic.
@@ -96,6 +96,12 b' default = %s'
96
96
97 class ui(object):
97 class ui(object):
98 def __init__(self, src=None):
98 def __init__(self, src=None):
99 """Create a fresh new ui object if no src given
100
101 Use uimod.ui.load() to create a ui which knows global and user configs.
102 In most cases, you should use ui.copy() to create a copy of an existing
103 ui object.
104 """
99 # _buffers: used for temporary capture of output
105 # _buffers: used for temporary capture of output
100 self._buffers = []
106 self._buffers = []
101 # 3-tuple describing how each buffer in the stack behaves.
107 # 3-tuple describing how each buffer in the stack behaves.
@@ -138,12 +144,18 b' class ui(object):'
138
144
139 # shared read-only environment
145 # shared read-only environment
140 self.environ = os.environ
146 self.environ = os.environ
141 # we always trust global config files
142 for f in scmutil.rcpath():
143 self.readconfig(f, trust=True)
144
147
145 self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
148 self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
146
149
150 @classmethod
151 def load(cls):
152 """Create a ui and load global and user configs"""
153 u = cls()
154 # we always trust global config files
155 for f in scmutil.rcpath():
156 u.readconfig(f, trust=True)
157 return u
158
147 def copy(self):
159 def copy(self):
148 return self.__class__(self)
160 return self.__class__(self)
149
161
@@ -37,7 +37,7 b' class dummysmtpsecureserver(dummysmtpser'
37 if not pair:
37 if not pair:
38 return
38 return
39 conn, addr = pair
39 conn, addr = pair
40 ui = uimod.ui()
40 ui = uimod.ui.load()
41 try:
41 try:
42 # wrap_socket() would block, but we don't care
42 # wrap_socket() would block, but we don't care
43 conn = sslutil.wrapserversocket(conn, ui, certfile=self._certfile)
43 conn = sslutil.wrapserversocket(conn, ui, certfile=self._certfile)
@@ -449,7 +449,7 b' def has_sslcontext():'
449 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
449 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
450 def has_defaultcacerts():
450 def has_defaultcacerts():
451 from mercurial import sslutil, ui as uimod
451 from mercurial import sslutil, ui as uimod
452 ui = uimod.ui()
452 ui = uimod.ui.load()
453 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
453 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
454
454
455 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
455 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
@@ -462,7 +462,7 b' def has_defaultcacertsloaded():'
462 if not has_sslcontext():
462 if not has_sslcontext():
463 return False
463 return False
464
464
465 ui = uimod.ui()
465 ui = uimod.ui.load()
466 cafile = sslutil._defaultcacerts(ui)
466 cafile = sslutil._defaultcacerts(ui)
467 ctx = ssl.create_default_context()
467 ctx = ssl.create_default_context()
468 if cafile:
468 if cafile:
@@ -218,7 +218,7 b' dagtests = ['
218 '+3*3/*2*2/*4*4/*4/2*4/2*2',
218 '+3*3/*2*2/*4*4/*4/2*4/2*2',
219 ]
219 ]
220 def test_gca():
220 def test_gca():
221 u = uimod.ui()
221 u = uimod.ui.load()
222 for i, dag in enumerate(dagtests):
222 for i, dag in enumerate(dagtests):
223 repo = hg.repository(u, 'gca%d' % i, create=1)
223 repo = hg.repository(u, 'gca%d' % i, create=1)
224 cl = repo.changelog
224 cl = repo.changelog
@@ -34,7 +34,7 b' Verify that updating to revision 0 via c'
34
34
35 $ cat <<EOF > update_to_rev0.py
35 $ cat <<EOF > update_to_rev0.py
36 > from mercurial import ui, hg, commands
36 > from mercurial import ui, hg, commands
37 > myui = ui.ui()
37 > myui = ui.ui.load()
38 > repo = hg.repository(myui, path='.')
38 > repo = hg.repository(myui, path='.')
39 > commands.update(myui, repo, rev=0)
39 > commands.update(myui, repo, rev=0)
40 > EOF
40 > EOF
@@ -456,7 +456,7 b' test bisecting command'
456 > #!/usr/bin/env python
456 > #!/usr/bin/env python
457 > import sys
457 > import sys
458 > from mercurial import ui, hg
458 > from mercurial import ui, hg
459 > repo = hg.repository(ui.ui(), '.')
459 > repo = hg.repository(ui.ui.load(), '.')
460 > if repo['.'].rev() < 6:
460 > if repo['.'].rev() < 6:
461 > sys.exit(1)
461 > sys.exit(1)
462 > EOF
462 > EOF
@@ -515,7 +515,7 b' iterable in addbranchrevs()'
515
515
516 $ cat <<EOF > simpleclone.py
516 $ cat <<EOF > simpleclone.py
517 > from mercurial import ui, hg
517 > from mercurial import ui, hg
518 > myui = ui.ui()
518 > myui = ui.ui.load()
519 > repo = hg.repository(myui, 'a')
519 > repo = hg.repository(myui, 'a')
520 > hg.clone(myui, {}, repo, dest="ua")
520 > hg.clone(myui, {}, repo, dest="ua")
521 > EOF
521 > EOF
@@ -528,7 +528,7 b' iterable in addbranchrevs()'
528
528
529 $ cat <<EOF > branchclone.py
529 $ cat <<EOF > branchclone.py
530 > from mercurial import ui, hg, extensions
530 > from mercurial import ui, hg, extensions
531 > myui = ui.ui()
531 > myui = ui.ui.load()
532 > extensions.loadall(myui)
532 > extensions.loadall(myui)
533 > repo = hg.repository(myui, 'a')
533 > repo = hg.repository(myui, 'a')
534 > hg.clone(myui, {}, repo, dest="ua", branch=["stable",])
534 > hg.clone(myui, {}, repo, dest="ua", branch=["stable",])
@@ -325,7 +325,7 b' The default interface is text'
325 $ chunkselectorinterface() {
325 $ chunkselectorinterface() {
326 > python <<EOF
326 > python <<EOF
327 > from mercurial import hg, ui, parsers;\
327 > from mercurial import hg, ui, parsers;\
328 > repo = hg.repository(ui.ui(), ".");\
328 > repo = hg.repository(ui.ui.load(), ".");\
329 > print repo.ui.interface("chunkselector")
329 > print repo.ui.interface("chunkselector")
330 > EOF
330 > EOF
331 > }
331 > }
@@ -92,7 +92,7 b' now test that we fixed the bug for all s'
92 > def printfiles(repo, rev):
92 > def printfiles(repo, rev):
93 > print "revision %s files: %s" % (rev, repo[rev].files())
93 > print "revision %s files: %s" % (rev, repo[rev].files())
94 >
94 >
95 > repo = hg.repository(ui.ui(), '.')
95 > repo = hg.repository(ui.ui.load(), '.')
96 > assert len(repo) == 6, \
96 > assert len(repo) == 6, \
97 > "initial: len(repo): %d, expected: 6" % len(repo)
97 > "initial: len(repo): %d, expected: 6" % len(repo)
98 >
98 >
@@ -609,7 +609,7 b' verify pathauditor blocks evil filepaths'
609 $ cat > evil-commit.py <<EOF
609 $ cat > evil-commit.py <<EOF
610 > from mercurial import ui, hg, context, node
610 > from mercurial import ui, hg, context, node
611 > notrc = u".h\u200cg".encode('utf-8') + '/hgrc'
611 > notrc = u".h\u200cg".encode('utf-8') + '/hgrc'
612 > u = ui.ui()
612 > u = ui.ui.load()
613 > r = hg.repository(u, '.')
613 > r = hg.repository(u, '.')
614 > def filectxfn(repo, memctx, path):
614 > def filectxfn(repo, memctx, path):
615 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
615 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
@@ -633,7 +633,7 b' verify pathauditor blocks evil filepaths'
633 $ cat > evil-commit.py <<EOF
633 $ cat > evil-commit.py <<EOF
634 > from mercurial import ui, hg, context, node
634 > from mercurial import ui, hg, context, node
635 > notrc = "HG~1/hgrc"
635 > notrc = "HG~1/hgrc"
636 > u = ui.ui()
636 > u = ui.ui.load()
637 > r = hg.repository(u, '.')
637 > r = hg.repository(u, '.')
638 > def filectxfn(repo, memctx, path):
638 > def filectxfn(repo, memctx, path):
639 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
639 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
@@ -651,7 +651,7 b' verify pathauditor blocks evil filepaths'
651 $ cat > evil-commit.py <<EOF
651 $ cat > evil-commit.py <<EOF
652 > from mercurial import ui, hg, context, node
652 > from mercurial import ui, hg, context, node
653 > notrc = "HG8B6C~2/hgrc"
653 > notrc = "HG8B6C~2/hgrc"
654 > u = ui.ui()
654 > u = ui.ui.load()
655 > r = hg.repository(u, '.')
655 > r = hg.repository(u, '.')
656 > def filectxfn(repo, memctx, path):
656 > def filectxfn(repo, memctx, path):
657 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
657 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
@@ -7,7 +7,7 b' from mercurial import ('
7 ui as uimod,
7 ui as uimod,
8 )
8 )
9
9
10 u = uimod.ui()
10 u = uimod.ui.load()
11
11
12 repo = hg.repository(u, 'test1', create=1)
12 repo = hg.repository(u, 'test1', create=1)
13 os.chdir('test1')
13 os.chdir('test1')
@@ -21,7 +21,7 b' for ext in disabled:'
21
21
22 hgrc.close()
22 hgrc.close()
23
23
24 u = uimod.ui()
24 u = uimod.ui.load()
25 extensions.loadall(u)
25 extensions.loadall(u)
26
26
27 globalshort = set()
27 globalshort = set()
@@ -141,7 +141,7 b' def fakeuncacheable():'
141 def test_filecache_synced():
141 def test_filecache_synced():
142 # test old behavior that caused filecached properties to go out of sync
142 # test old behavior that caused filecached properties to go out of sync
143 os.system('hg init && echo a >> a && hg ci -qAm.')
143 os.system('hg init && echo a >> a && hg ci -qAm.')
144 repo = hg.repository(uimod.ui())
144 repo = hg.repository(uimod.ui.load())
145 # first rollback clears the filecache, but changelog to stays in __dict__
145 # first rollback clears the filecache, but changelog to stays in __dict__
146 repo.rollback()
146 repo.rollback()
147 repo.commit('.')
147 repo.commit('.')
@@ -13,7 +13,7 b' from mercurial import ('
13 ui as uimod,
13 ui as uimod,
14 )
14 )
15
15
16 myui = uimod.ui()
16 myui = uimod.ui.load()
17 repo = hg.repository(myui, path='.', create=True)
17 repo = hg.repository(myui, path='.', create=True)
18
18
19 fl = repo.file('foobar')
19 fl = repo.file('foobar')
@@ -15,7 +15,7 b' class myui(uimod.ui):'
15 def interactive(self):
15 def interactive(self):
16 return False
16 return False
17
17
18 origui = myui()
18 origui = myui.load()
19
19
20 def writeauth(items):
20 def writeauth(items):
21 ui = origui.copy()
21 ui = origui.copy()
@@ -15,7 +15,7 b" os.chdir('webdir')"
15
15
16 webdir = os.path.realpath('.')
16 webdir = os.path.realpath('.')
17
17
18 u = uimod.ui()
18 u = uimod.ui.load()
19 hg.repository(u, 'a', create=1)
19 hg.repository(u, 'a', create=1)
20 hg.repository(u, 'b', create=1)
20 hg.repository(u, 'b', create=1)
21 os.chdir('b')
21 os.chdir('b')
@@ -81,7 +81,7 b' verify 7e7d56fe4833 (encoding fallback i'
81 > sys.stdout = StdoutWrapper(sys.stdout)
81 > sys.stdout = StdoutWrapper(sys.stdout)
82 > sys.stderr = StdoutWrapper(sys.stderr)
82 > sys.stderr = StdoutWrapper(sys.stderr)
83 >
83 >
84 > myui = ui.ui()
84 > myui = ui.ui.load()
85 > repo = hg.repository(myui, 'a')
85 > repo = hg.repository(myui, 'a')
86 > commands.serve(myui, repo, stdio=True, cmdserver=False)
86 > commands.serve(myui, repo, stdio=True, cmdserver=False)
87 > EOF
87 > EOF
@@ -46,7 +46,7 b' localrepo.localrepository.testcachedunfi'
46 # these tests on the real object to detect regression.
46 # these tests on the real object to detect regression.
47 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
47 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
48 assert subprocess.call(['hg', 'init', repopath]) == 0
48 assert subprocess.call(['hg', 'init', repopath]) == 0
49 ui = uimod.ui()
49 ui = uimod.ui.load()
50 repo = hg.repository(ui, path=repopath).unfiltered()
50 repo = hg.repository(ui, path=repopath).unfiltered()
51
51
52
52
@@ -6,7 +6,7 b' from mercurial import ('
6 ui as uimod,
6 ui as uimod,
7 )
7 )
8
8
9 u = uimod.ui()
9 u = uimod.ui.load()
10
10
11 repo = hg.repository(u, 'test1', create=1)
11 repo = hg.repository(u, 'test1', create=1)
12 os.chdir('test1')
12 os.chdir('test1')
@@ -7,7 +7,7 b' from mercurial import ('
7 ui as uimod,
7 ui as uimod,
8 )
8 )
9
9
10 u = uimod.ui()
10 u = uimod.ui.load()
11
11
12 print('% creating repo')
12 print('% creating repo')
13 repo = localrepo.localrepository(u, '.', create=True)
13 repo = localrepo.localrepository(u, '.', create=True)
@@ -66,7 +66,7 b" def testui(user='foo', group='bar', tuse"
66 print('# %s user, %s group%s' % (kind[user == cuser], kind[group == cgroup],
66 print('# %s user, %s group%s' % (kind[user == cuser], kind[group == cgroup],
67 trusted))
67 trusted))
68
68
69 u = uimod.ui()
69 u = uimod.ui.load()
70 u.setconfig('ui', 'debug', str(bool(debug)))
70 u.setconfig('ui', 'debug', str(bool(debug)))
71 u.setconfig('ui', 'report_untrusted', str(bool(report)))
71 u.setconfig('ui', 'report_untrusted', str(bool(report)))
72 u.readconfig('.hg/hgrc')
72 u.readconfig('.hg/hgrc')
@@ -156,7 +156,7 b" print(u.config('foobar', 'baz'))"
156
156
157 print()
157 print()
158 print("# read trusted, untrusted, new ui, trusted")
158 print("# read trusted, untrusted, new ui, trusted")
159 u = uimod.ui()
159 u = uimod.ui.load()
160 u.setconfig('ui', 'debug', 'on')
160 u.setconfig('ui', 'debug', 'on')
161 u.readconfig(filename)
161 u.readconfig(filename)
162 u2 = u.copy()
162 u2 = u.copy()
@@ -23,7 +23,7 b" hgrc.write('[extensions]\\n')"
23 hgrc.write('color=\n')
23 hgrc.write('color=\n')
24 hgrc.close()
24 hgrc.close()
25
25
26 ui_ = uimod.ui()
26 ui_ = uimod.ui.load()
27 ui_.setconfig('ui', 'formatted', 'True')
27 ui_.setconfig('ui', 'formatted', 'True')
28
28
29 # we're not interested in the output, so write that to devnull
29 # we're not interested in the output, so write that to devnull
@@ -5,7 +5,7 b' from mercurial import ('
5 ui as uimod,
5 ui as uimod,
6 )
6 )
7
7
8 testui = uimod.ui()
8 testui = uimod.ui.load()
9 parsed = dispatch._parseconfig(testui, [
9 parsed = dispatch._parseconfig(testui, [
10 'values.string=string value',
10 'values.string=string value',
11 'values.bool1=true',
11 'values.bool1=true',
@@ -32,7 +32,7 b' for i in xrange(64):'
32 f.write('debug = True\n')
32 f.write('debug = True\n')
33 f.close()
33 f.close()
34
34
35 u = uimod.ui()
35 u = uimod.ui.load()
36 if cmd_quiet or cmd_debug or cmd_verbose:
36 if cmd_quiet or cmd_debug or cmd_verbose:
37 u.setconfig('ui', 'quiet', str(bool(cmd_quiet)))
37 u.setconfig('ui', 'quiet', str(bool(cmd_quiet)))
38 u.setconfig('ui', 'verbose', str(bool(cmd_verbose)))
38 u.setconfig('ui', 'verbose', str(bool(cmd_verbose)))
@@ -16,7 +16,7 b' pjoin = os.path.join'
16 walkrepos = scmutil.walkrepos
16 walkrepos = scmutil.walkrepos
17 checklink = util.checklink
17 checklink = util.checklink
18
18
19 u = uimod.ui()
19 u = uimod.ui.load()
20 sym = checklink('.')
20 sym = checklink('.')
21
21
22 hg.repository(u, 'top1', create=1)
22 hg.repository(u, 'top1', create=1)
General Comments 0
You need to be logged in to leave comments. Login now