evolve: add a utility fn to check validity of opts passed to `hg evolve`
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 06 Jan 2018 19:07:43 +0530
changeset 3386 2a51107e60cf
parent 3385 823031b51d81
child 3387 b3be4797d3c6
evolve: add a utility fn to check validity of opts passed to `hg evolve`
hgext3rd/evolve/__init__.py
tests/test-issue-5720.t
--- a/hgext3rd/evolve/__init__.py	Sat Jan 06 18:48:15 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Sat Jan 06 19:07:43 2018 +0530
@@ -1517,8 +1517,8 @@
     categories of troubles with the --unstable, --divergent or --bumped flags.
     """
 
+    opts = _checkevolveopts(repo, opts)
     # Options
-    listopt = opts['list']
     contopt = opts['continue']
     anyopt = opts['any']
     allopt = opts['all']
@@ -1527,33 +1527,11 @@
     confirmopt = opts['confirm']
     revopt = opts['rev']
 
-    # Backward compatibility
-    if opts['unstable']:
-        msg = ("'evolve --unstable' is deprecated, "
-               "use 'evolve --orphan'")
-        repo.ui.deprecwarn(msg, '4.4')
-
-        opts['orphan'] = opts['divergent']
-
-    if opts['divergent']:
-        msg = ("'evolve --divergent' is deprecated, "
-               "use 'evolve --content-divergent'")
-        repo.ui.deprecwarn(msg, '4.4')
-
-        opts['content_divergent'] = opts['divergent']
-
-    if opts['bumped']:
-        msg = ("'evolve --bumped' is deprecated, "
-               "use 'evolve --phase-divergent'")
-        repo.ui.deprecwarn(msg, '4.4')
-
-        opts['phase_divergent'] = opts['bumped']
-
     troublecategories = ['phase_divergent', 'content_divergent', 'orphan']
     specifiedcategories = [t.replace('_', '')
                            for t in troublecategories
                            if opts[t]]
-    if listopt:
+    if opts['list']:
         compat.startpager(ui, 'evolve')
         listtroubles(ui, repo, specifiedcategories, **opts)
         return
@@ -1602,10 +1580,6 @@
 
     # Continuation handling
     if contopt:
-        if anyopt:
-            raise error.Abort('cannot specify both "--any" and "--continue"')
-        if allopt:
-            raise error.Abort('cannot specify both "--all" and "--continue"')
         state = _evolvestateread(repo)
         if state is None:
             raise error.Abort('no evolve to continue')
@@ -1632,11 +1606,6 @@
 
     cmdutil.bailifchanged(repo)
 
-    if revopt and allopt:
-        raise error.Abort('cannot specify both "--rev" and "--all"')
-    if revopt and anyopt:
-        raise error.Abort('cannot specify both "--rev" and "--any"')
-
     revs = _selectrevs(repo, allopt, revopt, anyopt, targetcat)
 
     if not revs:
@@ -1655,6 +1624,46 @@
     progresscb()
     _cleanup(ui, repo, startnode, showprogress)
 
+def _checkevolveopts(repo, opts):
+    """ check the options passed to `hg evolve` and warn for deprecation warning
+    if any """
+
+    if opts['continue']:
+        if opts['any']:
+            raise error.Abort('cannot specify both "--any" and "--continue"')
+        if opts['all']:
+            raise error.Abort('cannot specify both "--all" and "--continue"')
+
+    if opts['rev']:
+        if opts['any']:
+            raise error.Abort('cannot specify both "--rev" and "--any"')
+        if opts['all']:
+            raise error.Abort('cannot specify both "--rev" and "--all"')
+
+    # Backward compatibility
+    if opts['unstable']:
+        msg = ("'evolve --unstable' is deprecated, "
+               "use 'evolve --orphan'")
+        repo.ui.deprecwarn(msg, '4.4')
+
+        opts['orphan'] = opts['divergent']
+
+    if opts['divergent']:
+        msg = ("'evolve --divergent' is deprecated, "
+               "use 'evolve --content-divergent'")
+        repo.ui.deprecwarn(msg, '4.4')
+
+        opts['content_divergent'] = opts['divergent']
+
+    if opts['bumped']:
+        msg = ("'evolve --bumped' is deprecated, "
+               "use 'evolve --phase-divergent'")
+        repo.ui.deprecwarn(msg, '4.4')
+
+        opts['phase_divergent'] = opts['bumped']
+
+    return opts
+
 def _possibledestination(repo, rev):
     """return all changesets that may be a new parent for REV"""
     tonode = repo.changelog.node
--- a/tests/test-issue-5720.t	Sat Jan 06 18:48:15 2018 +0530
+++ b/tests/test-issue-5720.t	Sat Jan 06 19:07:43 2018 +0530
@@ -73,7 +73,7 @@
 
 Continue the evolution
   $ hg evolve --continue
-  grafting 2:13833940840c "c"
+  evolving 2:13833940840c "c"
 
 Tip should stay in secret phase
   $ hg log -G -T "{rev}: {phase}"