# HG changeset patch # User Martin von Zweigbergk # Date 2019-12-12 23:16:13 # Node ID d587937600be6b550cfa1c956087b048492787d1 # Parent 7eb6a2680ae6f6b0c41ff461288c3b0de8ec7e60 clone: extract helper for checking mutually exclusive args We have some duplicated code for aborting if the user provided mutually exclusive arguments. Extensions surely have more such code. We also have duplicated translations and inconsistent output in this area. This patch introduces a simpler helper for checking if more than one option among a given set was given on the command line. I've made the clone code call the function to show that it works. The function has no good way of checking arguments with hyphens in them. I'll add that later if necessary. The function still won't be applicable in all cases, but I think it's still better than nothing. Differential Revision: https://phab.mercurial-scm.org/D7633 diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -260,6 +260,18 @@ debugrevlogopts = [ _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 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1889,8 +1889,7 @@ def clone(ui, source, dest=None, **opts) 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