comparison mercurial/commands.py @ 47443:7a430116f639

ui: add a context manager for silencing the ui (pushbuffer+popbuffer) We often silence the ui by calling `ui.pushbuffer()` followed (a later in the code) by `ui.popbuffer()`. These places can be identified by the fact that they ignore the output returned from `ui.popbuffer()`. Let's create a context manager for these cases, to avoid repetition, and to avoid accidentally leaving the ui silent on exceptions. I deliberately called the new function `silent()` instead of `buffered()`, because it's just an implementation detail that it uses `pushbuffer()` and `popbuffer()`. We could later optimize it to not buffer the output. Differential Revision: https://phab.mercurial-scm.org/D10884
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 18 Jun 2021 15:48:51 -0700
parents fc8e29ffc380
children f89d3050dcd5
comparison
equal deleted inserted replaced
47442:6ecd0980d7f9 47443:7a430116f639
7239 return source, sbranch, None, None, None 7239 return source, sbranch, None, None, None
7240 revs, checkout = hg.addbranchrevs(repo, other, branches, None) 7240 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
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:
7250 source, sbranch, sother, commoninc, incoming = getincoming() 7249 source, sbranch, sother, commoninc, incoming = getincoming()
7251 else: 7250 else:
7285 common = None 7284 common = None
7286 else: 7285 else:
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:
7298 dest, dbranch, dother, outgoing = getoutgoing() 7296 dest, dbranch, dother, outgoing = getoutgoing()
7299 else: 7297 else: