fastannotate: use progress helper
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 04 Dec 2018 15:59:47 -0800
changeset 53604 dd1006874a5aa49f03955f438fbab7effddecfbf
parent 53603 901f6ef670ca5e1a9ed07f31aed4e1930982688d
child 53605 05afb32e93809d983dbb1e89cec50938a9d59dc0
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
fastannotate: use progress helper Differential Revision: https://phab.mercurial-scm.org/D5374
hgext/fastannotate/context.py
--- a/hgext/fastannotate/context.py
+++ b/hgext/fastannotate/context.py
@@ -393,17 +393,18 @@ class _annotatecontext(object):
                 self.ui.debug('fastannotate: %s: linelog cannot help in '
                               'annotating this revision\n' % self.path)
 
         # prepare annotateresult so we can update linelog incrementally
         self.linelog.annotate(self.linelog.maxrev)
 
         # 3rd DFS does the actual annotate
         visit = initvisit[:]
-        progress = 0
+        progress = self.ui.makeprogress(('building cache'),
+                                        total=len(newmainbranch))
         while visit:
             f = visit[-1]
             if f in hist:
                 visit.pop()
                 continue
 
             ready = True
             pl = pcache[f]
@@ -432,31 +433,27 @@ class _annotatecontext(object):
                     del needed[p]
                 else:
                     needed[p] -= 1
 
             hist[f] = curr
             del pcache[f]
 
             if ismainbranch: # need to write to linelog
-                if not self.ui.quiet:
-                    progress += 1
-                    self.ui.progress(_('building cache'), progress,
-                                     total=len(newmainbranch))
+                progress.increment()
                 bannotated = None
                 if len(pl) == 2 and self.opts.followmerge: # merge
                     bannotated = curr[0]
                 if blocks is None: # no parents, add an empty one
                     blocks = list(self._diffblocks('', curr[1]))
                 self._appendrev(f, blocks, bannotated)
             elif showpath: # not append linelog, but we need to record path
                 self._node2path[f.node()] = f.path()
 
-        if progress: # clean progress bar
-            self.ui.write()
+        progress.complete()
 
         result = [
             ((self.revmap.rev2hsh(fr) if isinstance(fr, int) else fr.node()), l)
             for fr, l in hist[revfctx][0]] # [(node, linenumber)]
         return self._refineannotateresult(result, revfctx, showpath, showlines)
 
     def canannotatedirectly(self, rev):
         """(str) -> bool, fctx or node.