Patchwork D7640: rebase: use cmdutil.check_at_most_one_arg() for action

login
register
mail settings
Submitter phabricator
Date Dec. 16, 2019, 11:20 p.m.
Message ID <86b4b3e381a95de5fb4565040049b74e@localhost.localdomain>
Download mbox | patch
Permalink /patch/43880/
State Not Applicable
Headers show

Comments

phabricator - Dec. 16, 2019, 11:20 p.m.
martinvonz retitled this revision from "rebase: use cmdutil.check_unique_argument() for action" to "rebase: use cmdutil.check_at_most_one_arg() for action".
martinvonz updated this revision to Diff 18766.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7640?vs=18709&id=18766

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7640/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7640

AFFECTED FILES
  hgext/rebase.py
  mercurial/cmdutil.py
  tests/test-rebase-obsolete.t
  tests/test-rebase-parameters.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-rebase-parameters.t b/tests/test-rebase-parameters.t
--- a/tests/test-rebase-parameters.t
+++ b/tests/test-rebase-parameters.t
@@ -61,7 +61,7 @@ 
   [1]
 
   $ hg rebase --continue --abort
-  abort: cannot use --abort with --continue
+  abort: cannot specify both --abort and --continue
   [255]
 
   $ hg rebase --continue --collapse
diff --git a/tests/test-rebase-obsolete.t b/tests/test-rebase-obsolete.t
--- a/tests/test-rebase-obsolete.t
+++ b/tests/test-rebase-obsolete.t
@@ -2062,7 +2062,7 @@ 
   (use 'hg rebase --continue' or 'hg rebase --abort')
   [255]
   $ hg rebase --stop --continue
-  abort: cannot use --stop with --continue
+  abort: cannot specify both --stop and --continue
   [255]
 
 Test --stop moves bookmarks of original revisions to new rebased nodes:
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -261,7 +261,10 @@ 
 
 
 def check_at_most_one_arg(opts, *args):
-    """abort if more than one of the arguments are in opts"""
+    """abort if more than one of the arguments are in opts
+
+    Returns the unique argument or None if none of them were specified.
+    """
     previous = None
     for x in args:
         if opts.get(x):
@@ -270,6 +273,7 @@ 
                     _(b'cannot specify both --%s and --%s') % (previous, x)
                 )
             previous = x
+    return previous
 
 
 def check_incompatible_arguments(opts, first, *others):
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1021,12 +1021,7 @@ 
     inmemory = ui.configbool(b'rebase', b'experimental.inmemory')
     dryrun = opts.get(b'dry_run')
     confirm = opts.get(b'confirm')
-    selactions = [k for k in [b'abort', b'stop', b'continue'] if opts.get(k)]
-    if len(selactions) > 1:
-        raise error.Abort(
-            _(b'cannot use --%s with --%s') % tuple(selactions[:2])
-        )
-    action = selactions[0] if selactions else None
+    action = cmdutil.check_at_most_one_arg(opts, b'abort', b'stop', b'continue')
     if dryrun and action:
         raise error.Abort(_(b'cannot specify both --dry-run and --%s') % action)
     if confirm and action: