##// END OF EJS Templates
ui: add a context manager for silencing the ui (pushbuffer+popbuffer)...
Martin von Zweigbergk -
r48230:7a430116 default
parent child Browse files
Show More
@@ -76,9 +76,8 b' def runperfcommand(reponame, command, *a'
76 76 ui, 'perfext', os.path.join(basedir, 'contrib', 'perf.py')
77 77 )
78 78 cmd = getattr(perfext, command)
79 ui.pushbuffer()
80 cmd(ui, repo, *args, **kwargs)
81 output = ui.popbuffer()
79 with ui.silent():
80 cmd(ui, repo, *args, **kwargs)
82 81 match = outputre.search(output)
83 82 if not match:
84 83 raise ValueError("Invalid output {}".format(output))
@@ -575,9 +575,8 b' class histeditaction(object):'
575 575 parentctx, but does not commit them."""
576 576 repo = self.repo
577 577 rulectx = repo[self.node]
578 repo.ui.pushbuffer()
579 hg.update(repo, self.state.parentctxnode, quietempty=True)
580 repo.ui.popbuffer()
578 with repo.ui.silent():
579 hg.update(repo, self.state.parentctxnode, quietempty=True)
581 580 stats = applychanges(repo.ui, repo, rulectx, {})
582 581 repo.dirstate.setbranch(rulectx.branch())
583 582 if stats.unresolvedcount:
@@ -654,10 +653,9 b' def applychanges(ui, repo, ctx, opts):'
654 653 if ctx.p1().node() == repo.dirstate.p1():
655 654 # edits are "in place" we do not need to make any merge,
656 655 # just applies changes on parent for editing
657 ui.pushbuffer()
658 cmdutil.revert(ui, repo, ctx, all=True)
659 stats = mergemod.updateresult(0, 0, 0, 0)
660 ui.popbuffer()
656 with ui.silent():
657 cmdutil.revert(ui, repo, ctx, all=True)
658 stats = mergemod.updateresult(0, 0, 0, 0)
661 659 else:
662 660 try:
663 661 # ui.forcemerge is an internal variable, do not document
@@ -7241,9 +7241,8 b' def summary(ui, repo, **opts):'
7241 7241 if revs:
7242 7242 revs = [other.lookup(rev) for rev in revs]
7243 7243 ui.debug(b'comparing with %s\n' % urlutil.hidepassword(source))
7244 repo.ui.pushbuffer()
7245 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
7246 repo.ui.popbuffer()
7244 with repo.ui.silent():
7245 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
7247 7246 return source, sbranch, other, commoninc, commoninc[1]
7248 7247
7249 7248 if needsincoming:
@@ -7287,11 +7286,10 b' def summary(ui, repo, **opts):'
7287 7286 common = commoninc
7288 7287 if revs:
7289 7288 revs = [repo.lookup(rev) for rev in revs]
7290 repo.ui.pushbuffer()
7291 outgoing = discovery.findcommonoutgoing(
7292 repo, dother, onlyheads=revs, commoninc=common
7293 )
7294 repo.ui.popbuffer()
7289 with repo.ui.silent():
7290 outgoing = discovery.findcommonoutgoing(
7291 repo, dother, onlyheads=revs, commoninc=common
7292 )
7295 7293 return dest, dbranch, dother, outgoing
7296 7294
7297 7295 if needsoutgoing:
@@ -2754,9 +2754,9 b' def debugpickmergetool(ui, repo, *pats, '
2754 2754 changedelete = opts[b'changedelete']
2755 2755 for path in ctx.walk(m):
2756 2756 fctx = ctx[path]
2757 try:
2758 if not ui.debugflag:
2759 ui.pushbuffer(error=True)
2757 with ui.silent(
2758 error=True
2759 ) if not ui.debugflag else util.nullcontextmanager():
2760 2760 tool, toolpath = filemerge._picktool(
2761 2761 repo,
2762 2762 ui,
@@ -2765,9 +2765,6 b' def debugpickmergetool(ui, repo, *pats, '
2765 2765 b'l' in fctx.flags(),
2766 2766 changedelete,
2767 2767 )
2768 finally:
2769 if not ui.debugflag:
2770 ui.popbuffer()
2771 2768 ui.write(b'%s = %s\n' % (path, tool))
2772 2769
2773 2770
@@ -4580,17 +4577,16 b' def debugwireproto(ui, repo, path=None, '
4580 4577 ui.write(_(b'creating http peer for wire protocol version 2\n'))
4581 4578 # We go through makepeer() because we need an API descriptor for
4582 4579 # the peer instance to be useful.
4583 with ui.configoverride(
4580 maybe_silent = (
4581 ui.silent()
4582 if opts[b'nologhandshake']
4583 else util.nullcontextmanager()
4584 )
4585 with maybe_silent, ui.configoverride(
4584 4586 {(b'experimental', b'httppeer.advertise-v2'): True}
4585 4587 ):
4586 if opts[b'nologhandshake']:
4587 ui.pushbuffer()
4588
4589 4588 peer = httppeer.makepeer(ui, path, opener=opener)
4590 4589
4591 if opts[b'nologhandshake']:
4592 ui.popbuffer()
4593
4594 4590 if not isinstance(peer, httppeer.httpv2peer):
4595 4591 raise error.Abort(
4596 4592 _(
@@ -93,9 +93,8 b' def diff_parent(ctx):'
93 93 },
94 94 b"merge-diff",
95 95 ):
96 repo.ui.pushbuffer()
97 merge.merge(ctx.p2(), wc=wctx)
98 repo.ui.popbuffer()
96 with repo.ui.silent():
97 merge.merge(ctx.p2(), wc=wctx)
99 98 return wctx
100 99 else:
101 100 return ctx.p1()
@@ -28,6 +28,7 b' from . import ('
28 28 pycompat,
29 29 requirements,
30 30 scmutil,
31 util,
31 32 )
32 33 from .utils import (
33 34 hashutil,
@@ -239,19 +240,23 b' def strip(ui, repo, nodelist, backup=Tru'
239 240 ui.note(_(b"adding branch\n"))
240 241 f = vfs.open(tmpbundlefile, b"rb")
241 242 gen = exchange.readbundle(ui, f, tmpbundlefile, vfs)
242 if not repo.ui.verbose:
243 # silence internal shuffling chatter
244 repo.ui.pushbuffer()
245 tmpbundleurl = b'bundle:' + vfs.join(tmpbundlefile)
246 txnname = b'strip'
247 if not isinstance(gen, bundle2.unbundle20):
248 txnname = b"strip\n%s" % urlutil.hidepassword(tmpbundleurl)
249 with repo.transaction(txnname) as tr:
250 bundle2.applybundle(
251 repo, gen, tr, source=b'strip', url=tmpbundleurl
252 )
253 if not repo.ui.verbose:
254 repo.ui.popbuffer()
243 # silence internal shuffling chatter
244 maybe_silent = (
245 repo.ui.silent()
246 if not repo.ui.verbose
247 else util.nullcontextmanager()
248 )
249 with maybe_silent:
250 tmpbundleurl = b'bundle:' + vfs.join(tmpbundlefile)
251 txnname = b'strip'
252 if not isinstance(gen, bundle2.unbundle20):
253 txnname = b"strip\n%s" % urlutil.hidepassword(
254 tmpbundleurl
255 )
256 with repo.transaction(txnname) as tr:
257 bundle2.applybundle(
258 repo, gen, tr, source=b'strip', url=tmpbundleurl
259 )
255 260 f.close()
256 261
257 262 with repo.transaction(b'repair') as tr:
@@ -1872,9 +1872,10 b' def outgoing(repo, subset, x):'
1872 1872 revs = [repo.lookup(rev) for rev in revs]
1873 1873 other = hg.peer(repo, {}, dest)
1874 1874 try:
1875 repo.ui.pushbuffer()
1876 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1877 repo.ui.popbuffer()
1875 with repo.ui.silent():
1876 outgoing = discovery.findcommonoutgoing(
1877 repo, other, onlyheads=revs
1878 )
1878 1879 finally:
1879 1880 other.close()
1880 1881 missing.update(outgoing.missing)
@@ -1146,6 +1146,14 b' class ui(object):'
1146 1146 self._fmsg = f
1147 1147 self._fmsgout, self._fmsgerr = _selectmsgdests(self)
1148 1148
1149 @contextlib.contextmanager
1150 def silent(self, error=False, subproc=False, labeled=False):
1151 self.pushbuffer(error=error, subproc=subproc, labeled=labeled)
1152 try:
1153 yield
1154 finally:
1155 self.popbuffer()
1156
1149 1157 def pushbuffer(self, error=False, subproc=False, labeled=False):
1150 1158 """install a buffer to capture standard output of the ui object
1151 1159
@@ -48,26 +48,25 b' def debugbruterebase(ui, repo, source, d'
48 48 tr = repo.transaction(b'rebase')
49 49 tr._report = lambda x: 0 # hide "transaction abort"
50 50
51 ui.pushbuffer()
52 try:
53 rebase.rebase(ui, repo, dest=dest, rev=[spec])
54 except error.Abort as ex:
55 summary = b'ABORT: %s' % ex.message
56 except Exception as ex:
57 summary = b'CRASH: %s' % ex
58 else:
59 # short summary about new nodes
60 cl = repo.changelog
61 descs = []
62 for rev in xrange(repolen, len(repo)):
63 desc = b'%s:' % getdesc(rev)
64 for prev in cl.parentrevs(rev):
65 if prev > -1:
66 desc += getdesc(prev)
67 descs.append(desc)
68 descs.sort()
69 summary = b' '.join(descs)
70 ui.popbuffer()
51 with ui.silent():
52 try:
53 rebase.rebase(ui, repo, dest=dest, rev=[spec])
54 except error.Abort as ex:
55 summary = b'ABORT: %s' % ex.message
56 except Exception as ex:
57 summary = b'CRASH: %s' % ex
58 else:
59 # short summary about new nodes
60 cl = repo.changelog
61 descs = []
62 for rev in xrange(repolen, len(repo)):
63 desc = b'%s:' % getdesc(rev)
64 for prev in cl.parentrevs(rev):
65 if prev > -1:
66 desc += getdesc(prev)
67 descs.append(desc)
68 descs.sort()
69 summary = b' '.join(descs)
71 70 repo.vfs.tryunlink(b'rebasestate')
72 71
73 72 subsetdesc = b''.join(getdesc(rev) for rev in subset)
General Comments 0
You need to be logged in to leave comments. Login now