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