Mercurial > hg
comparison mercurial/logcmdutil.py @ 47437: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 | d55b71393907 |
children | 0dc4cc654d96 |
comparison
equal
deleted
inserted
replaced
47436:6ecd0980d7f9 | 47437:7a430116f639 |
---|---|
91 b"forcemerge", | 91 b"forcemerge", |
92 ): b"internal:merge3-lie-about-conflicts", | 92 ): b"internal:merge3-lie-about-conflicts", |
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() |
102 | 101 |
103 | 102 |