[PATCH 1 of 5 evolve-ext-V2] evolve: extract the logic to solve one change into a method

Laurent Charignon lcharignon at fb.com
Wed May 6 00:42:32 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1430783806 25200
#      Mon May 04 16:56:46 2015 -0700
# Node ID 1dd10a7e485b881c472ead204407e85e9b64fa54
# Parent  8376fe35ebdacf0368509fedef2a9fb97770ddc9
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.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -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:


More information about the Mercurial-devel mailing list