Patchwork D7633: clone: extract helper for checking mutually exclusive args

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

Comments

phabricator - Dec. 16, 2019, 11:20 p.m.
martinvonz updated this revision to Diff 18759.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7633?vs=18668&id=18759

BRANCH
  default

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

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

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1889,8 +1889,7 @@ 
     Returns 0 on success.
     """
     opts = pycompat.byteskwargs(opts)
-    if opts.get(b'noupdate') and opts.get(b'updaterev'):
-        raise error.Abort(_(b"cannot specify both --noupdate and --updaterev"))
+    cmdutil.check_at_most_one_arg(opts, b'noupdate', b'updaterev')
 
     # --include/--exclude can come from narrow or sparse.
     includepats, excludepats = None, None
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -260,6 +260,18 @@ 
 _linebelow = b"^HG: ------------------------ >8 ------------------------$"
 
 
+def check_at_most_one_arg(opts, *args):
+    """abort if more than one of the arguments are in opts"""
+    previous = None
+    for x in args:
+        if opts.get(x):
+            if previous:
+                raise error.Abort(
+                    _(b'cannot specify both --%s and --%s') % (previous, x)
+                )
+            previous = x
+
+
 def resolvecommitoptions(ui, opts):
     """modify commit options dict to handle related options