evolve: show progress
authorDan Villiom Podlaski Christiansen <dan@cabo.dk>
Tue, 22 Oct 2013 11:16:55 +0200
changeset 762 942aabaa8a8e
parent 761 60a2fad03650
child 763 966e2659e989
evolve: show progress The total count may be too low on occasion. Not sure why. gaved up at testing this, can't get stable result.
README
hgext/evolve.py
--- a/README	Tue Jan 07 16:07:43 2014 -0800
+++ b/README	Tue Oct 22 11:16:55 2013 +0200
@@ -48,6 +48,7 @@
   This should help people until evolve is able to to it itself.
 - removed the qsync extension. The only user I knew about (logilab) is not
   using it anymore. It not compatible with coming Mercurial version 2.9.
+- add progress indicator for long evolve command
 
 3.2.0 -- 2013-11-15
 
--- a/hgext/evolve.py	Tue Jan 07 16:07:43 2014 -0800
+++ b/hgext/evolve.py	Tue Oct 22 11:16:55 2013 +0200
@@ -925,31 +925,53 @@
             ui.write_err(_('no troubled changesets\n'))
             return 1
 
+    def progresscb():
+        if allopt:
+            ui.progress('evolve', seen, unit='changesets', total=count)
+    seen = 1
+    count = allopt and _counttroubled(ui, repo) or 1
+
     while tr is not None:
-        result = _evolveany(ui, repo, tr, dryrunopt)
+        progresscb()
+        result = _evolveany(ui, repo, tr, dryrunopt, progresscb=progresscb)
+        progresscb()
+        seen += 1
         if not allopt:
             return result
+        progresscb()
         tr = _picknexttroubled(ui, repo, anyopt or allopt)
 
+    if allopt:
+        ui.progress('evolve', None)
 
-def _evolveany(ui, repo, tr, dryrunopt):
+
+def _evolveany(ui, repo, tr, dryrunopt, progresscb):
     repo = repo.unfiltered()
     tr = repo[tr.rev()]
     cmdutil.bailifchanged(repo)
     troubles = tr.troubles()
     if 'unstable' in troubles:
-        return _solveunstable(ui, repo, tr, dryrunopt)
+        return _solveunstable(ui, repo, tr, dryrunopt, progresscb)
     elif 'bumped' in troubles:
-        return _solvebumped(ui, repo, tr, dryrunopt)
+        return _solvebumped(ui, repo, tr, dryrunopt, progresscb)
     elif 'divergent' in troubles:
         repo = repo.unfiltered()
         tr = repo[tr.rev()]
-        return _solvedivergent(ui, repo, tr, dryrunopt)
+        return _solvedivergent(ui, repo, tr, dryrunopt, progresscb)
     else:
         assert False  # WHAT? unknown troubles
 
-def _picknexttroubled(ui, repo, pickany=False):
+def _counttroubled(ui, repo):
+    """Count the amount of troubled changesets"""
+    troubled = set()
+    troubled.update(getrevs(repo, 'unstable'))
+    troubled.update(getrevs(repo, 'bumped'))
+    troubled.update(getrevs(repo, 'divergent'))
+    return len(troubled)
+
+def _picknexttroubled(ui, repo, pickany=False, progresscb=None):
     """Pick a the next trouble changeset to solve"""
+    if progresscb: progresscb()
     tr = _stabilizableunstable(repo, repo['.'])
     if tr is None:
         wdp = repo['.']
@@ -988,7 +1010,7 @@
                 return child
     return None
 
-def _solveunstable(ui, repo, orig, dryrun=False):
+def _solveunstable(ui, repo, orig, dryrun=False, progresscb=None):
     """Stabilize a unstable changeset"""
     obs = orig.parents()[0]
     if not obs.obsolete():
@@ -1019,11 +1041,13 @@
     repo.ui.status(_('atop:'))
     if not ui.quiet:
         displayer.show(target)
+    if progresscb: progresscb()
     todo = 'hg rebase -r %s -d %s\n' % (orig, target)
     if dryrun:
         repo.ui.write(todo)
     else:
         repo.ui.note(todo)
+        if progresscb: progresscb()
         lock = repo.lock()
         try:
             relocate(repo, orig, target)
@@ -1035,7 +1059,7 @@
         finally:
             lock.release()
 
-def _solvebumped(ui, repo, bumped, dryrun=False):
+def _solvebumped(ui, repo, bumped, dryrun=False, progresscb=None):
     """Stabilize a bumped changeset"""
     # For now we deny bumped merge
     if len(bumped.parents()) > 1:
@@ -1061,6 +1085,7 @@
         repo.ui.write('hg revert --all --rev %s;\n' % bumped)
         repo.ui.write('hg commit --msg "bumped update to %s"')
         return 0
+    if progresscb: progresscb()
     wlock = repo.wlock()
     try:
         newid = tmpctx = None
@@ -1137,7 +1162,7 @@
     finally:
         wlock.release()
 
-def _solvedivergent(ui, repo, divergent, dryrun=False):
+def _solvedivergent(ui, repo, divergent, dryrun=False, progresscb=None):
     base, others = divergentdata(divergent)
     if len(others) > 1:
         othersstr = "[%s]" % (','.join([str(i) for i in others]))
@@ -1200,6 +1225,7 @@
             repo.ui.status(_('updating to "local" conflict\n'))
             hg.update(repo, divergent.rev())
         repo.ui.note(_('merging divergent changeset\n'))
+        if progresscb: progresscb()
         stats = merge.update(repo,
                              other.node(),
                              branchmerge=True,
@@ -1220,6 +1246,7 @@
 /!\ * hg ci -m "same message as the amended changeset" => new cset Y
 /!\ * hg kill -n Y W Z
 """)
+        if progresscb: progresscb()
         tr = repo.transaction('stabilize-divergent')
         try:
             repo.dirstate.setparents(divergent.node(), node.nullid)