evolve: extract the logic to solve one change into a method
authorLaurent Charignon <lcharignon@fb.com>
Mon, 04 May 2015 16:56:46 -0700
changeset 1320 b5cd96395867
parent 1319 8376fe35ebda
child 1321 8fa74845eb1f
evolve: extract the logic to solve one change into a method The goal is to later reuse this method to implement the --rev flag for evolve that solves the troubles in a revset.
hgext/evolve.py
--- a/hgext/evolve.py	Mon May 04 16:56:05 2015 -0700
+++ b/hgext/evolve.py	Mon May 04 16:56:46 2015 -0700
@@ -1152,6 +1152,20 @@
         mean = sum(len(x[1]) for x in allpclusters) // nbcluster
         ui.write('        mean length:        %9i\n' % mean)
 
+def _solveone(ui, repo, ctx, dryrun, confirm, progresscb):
+    """Resolve the troubles affecting one revision"""
+    wlock = lock = tr = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction("evolve")
+        result = _evolveany(ui, repo, ctx, dryrun, confirm,
+                            progresscb=progresscb)
+        tr.close()
+        return result
+    finally:
+        lockmod.release(tr, lock, wlock)
+
 def handlenotrouble(ui, repo, startnode, dryrunopt):
     if repo['.'].obsolete():
         displayer = cmdutil.show_changeset(
@@ -1267,26 +1281,17 @@
     if not nexttrouble:
         return handlenotrouble(ui, repo, startnode, dryrunopt)
 
-    while nexttrouble is not None:
-        progresscb()
-        wlock = lock = tr = None
-        try:
-            wlock = repo.wlock()
-            lock = repo.lock()
-            tr = repo.transaction("evolve")
-            result = _evolveany(ui, repo, nexttrouble, dryrunopt, confirmopt,
-                                progresscb=progresscb)
-            tr.close()
-        finally:
-            lockmod.release(tr, lock, wlock)
-        progresscb()
-        seen += 1
-        if not allopt:
-            if repo['.'] != startnode:
-                ui.status(_('working directory is now at %s\n') % repo['.'])
-            return result
-        progresscb()
-        nexttrouble = _picknexttroubled(ui, repo, anyopt or allopt)
+    if allopt:
+        # Resolving all the troubles
+        while nexttrouble:
+            progresscb()
+            _solveone(ui, repo, nexttrouble, dryrunopt, confirmopt, progresscb)
+            seen += 1
+            progresscb()
+            nexttrouble= _picknexttroubled(ui, repo, anyopt or allopt)
+    else:
+        # Resolving a single trouble
+        _solveone(ui, repo, nexttrouble, dryrunopt, confirmopt, progresscb)
 
     # Cleanup
     if showprogress: