changeset 30785:1a200975eb28 draft

wip
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sat, 18 Jun 2016 20:58:17 -0400
parents b19c2679289c
children
files hgext/churn.py mercurial/cmdutil.py
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -88,11 +88,10 @@
             rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)]
 
         state['count'] += 1
-        ui.progress(_('analyzing'), state['count'], total=len(repo),
-                    unit=_('revisions'))
 
-    for ctx in cmdutil.walkchangerevs(repo, m, opts, prep):
-        continue
+    for ctx in cmdutil.walkchangerevs(repo, m, opts, prep,
+                                      topic=_("analyzing"), ui=None):
+        pass
 
     ui.progress(_('analyzing'), None)
 
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1797,7 +1797,7 @@
 
         return False
 
-def walkchangerevs(repo, match, opts, prepare):
+def walkchangerevs(repo, match, opts, prepare, topic=None, ui=None):
     '''Iterate over files and the revs in which they changed.
 
     Callers most commonly need to iterate backwards over the history
@@ -1810,7 +1810,12 @@
 
     This function returns an iterator yielding contexts. Before
     yielding each context, the iterator will first call the prepare
-    function on each context in the window in forward order.'''
+    function on each context in the window in forward order.
+
+    The topic and ui arguments are about showing a progress bar. If
+    present, a progress bar will be shown in units of revisions.
+
+    '''
 
     follow = opts.get('follow') or opts.get('follow_first')
     revs = _logrevs(repo, opts)
@@ -1898,6 +1903,13 @@
     # Now that wanted is correctly initialized, we can iterate over the
     # revision range, yielding only revisions in wanted.
     def iterate():
+        if topic and ui:
+            # This has to evaluate the full revset in order to compute
+            # its size.
+            total = len(revs)
+            count = 0
+            unit = _('revisions')
+
         if follow and match.always():
             ff = _followfilter(repo, onlyfirst=opts.get('follow_first'))
             def want(rev):
@@ -1927,6 +1939,14 @@
                                 yield f
                     fns = fns_generator()
                 prepare(ctx, fns)
+
+                # We consider the prepare to do most of the work, so
+                # we advance the progress bar here. An alternative
+                # would be to advance it when yielding, 
+                if topic and ui:
+                    count += 1
+                    ui.progress(topic, count, total=total, unit=unit)
+
             for rev in nrevs:
                 yield change(rev)