rewind: move revision selection into its own function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 17 Jun 2018 03:07:53 +0200
changeset 3869 bbfbaf46f7b0
parent 3868 1742254d1190
child 3870 e0bf44befd6e
rewind: move revision selection into its own function This will help making the logic more advanced.
hgext3rd/evolve/rewind.py
--- a/hgext3rd/evolve/rewind.py	Sun Jun 17 02:32:29 2018 +0200
+++ b/hgext3rd/evolve/rewind.py	Sun Jun 17 03:07:53 2018 +0200
@@ -56,18 +56,12 @@
     """
     unfi = repo.unfiltered()
 
-    if not opts.get('to'):
-        raise error.Abort('no revision to rewind to')
-
     successorsmap = collections.defaultdict(set)
     rewindmap = {}
     sscache = {}
     with repo.wlock(), repo.lock():
 
-        rewinded = scmutil.revrange(repo, opts.get('to'))
-
-        if not opts['exact']:
-            rewinded = repo.revs('obsolete() and ::%ld', rewinded)
+        rewinded = _select_rewinded(repo, opts)
 
         if not opts['as_divergence']:
             for rev in rewinded:
@@ -107,6 +101,19 @@
     if update_target is not None:
         ui.status(_('working directory is now at %s\n') % repo['.'])
 
+def _select_rewinded(repo, opts):
+    """select the revision we shoudl rewind to
+    """
+    if not opts.get('to'):
+        raise error.Abort('no revision to rewind to')
+
+    rewinded = scmutil.revrange(repo, opts.get('to'))
+
+    if not opts['exact']:
+        rewinded = repo.revs('obsolete() and ::%ld', rewinded)
+
+    return rewinded
+
 def _revive_revision(unfi, rev, rewindmap):
     """rewind a single revision rev.
     """