ui: check for progress singleton when clearing progress bar (
issue5684)
A combination of wrapping `ui` and progress bars interrupted by exceptions can
lead to the progress bar not being cleared when the exception error is printed.
This results in corrupted-looking output like this:
```
updating [===============================> ] 1/2u
nresolved conflicts (see hg resolve, then hg rebase --continue)
```
This is because in `ui._progclear`, we only check the local reference to the
progress bar, not whether or not there is an instance of the singleton. When a
progress bar is interrupted by an exception, the exception printing in
`scmutil.callcatch` uses the original instance of the `ui` object, not the
wrapped copy that has `_progbar` set.
When consider whether or not to clear the progress bar, check for the existence
of the singleton, rather than just whether or not we have a local reference to
it.
Differential Revision: https://phab.mercurial-scm.org/D743
--- a/mercurial/ui.py Mon Sep 18 11:53:54 2017 -0400
+++ b/mercurial/ui.py Wed Sep 20 09:55:52 2017 -0700
@@ -1481,7 +1481,7 @@
def _progclear(self):
"""clear progress bar output if any. use it before any output"""
- if '_progbar' not in vars(self): # nothing loaded yet
+ if not haveprogbar(): # nothing loaded yet
return
if self._progbar is not None and self._progbar.printed:
self._progbar.clear()
@@ -1785,3 +1785,6 @@
# this is how the extension used to work but feel free to rework it.
_progresssingleton = progress.progbar(ui)
return _progresssingleton
+
+def haveprogbar():
+ return _progresssingleton is not None
--- a/tests/test-subrepo-deep-nested-change.t Mon Sep 18 11:53:54 2017 -0400
+++ b/tests/test-subrepo-deep-nested-change.t Wed Sep 20 09:55:52 2017 -0700
@@ -63,6 +63,14 @@
\r (no-eol) (esc)
\r (no-eol) (esc)
updating [===========================================>] 3/3\r (no-eol) (esc)
+ \r (no-eol) (esc)
+ \r (no-eol) (esc)
+ linking [ <=> ] 1\r (no-eol) (esc)
+ linking [ <=> ] 2\r (no-eol) (esc)
+ linking [ <=> ] 3\r (no-eol) (esc)
+ linking [ <=> ] 4\r (no-eol) (esc)
+ linking [ <=> ] 5\r (no-eol) (esc)
+ linking [ <=> ] 6\r (no-eol) (esc)
updating [===========================================>] 1/1\r (no-eol) (esc)
\r (no-eol) (esc)
updating to branch default
@@ -154,7 +162,25 @@
\r (no-eol) (esc)
\r (no-eol) (esc)
updating [===========================================>] 3/3\r (no-eol) (esc)
+ \r (no-eol) (esc)
+ \r (no-eol) (esc)
+ linking [ <=> ] 1\r (no-eol) (esc)
+ linking [ <=> ] 2\r (no-eol) (esc)
+ linking [ <=> ] 3\r (no-eol) (esc)
+ linking [ <=> ] 4\r (no-eol) (esc)
+ linking [ <=> ] 5\r (no-eol) (esc)
+ linking [ <=> ] 6\r (no-eol) (esc)
+ linking [ <=> ] 7\r (no-eol) (esc)
+ linking [ <=> ] 8\r (no-eol) (esc)
updating [===========================================>] 3/3\r (no-eol) (esc)
+ \r (no-eol) (esc)
+ \r (no-eol) (esc)
+ linking [ <=> ] 1\r (no-eol) (esc)
+ linking [ <=> ] 2\r (no-eol) (esc)
+ linking [ <=> ] 3\r (no-eol) (esc)
+ linking [ <=> ] 4\r (no-eol) (esc)
+ linking [ <=> ] 5\r (no-eol) (esc)
+ linking [ <=> ] 6\r (no-eol) (esc)
updating [===========================================>] 1/1\r (no-eol) (esc)
\r (no-eol) (esc)
updating to branch default