# HG changeset patch # User Anton Shestakov # Date 1621018684 -28800 # Node ID e682bbe66e37eca245794e64f583818374d51b84 # Parent 51ee9809d90d13c3d4c48ad45841d2c9149b70fb compat: add check_at_most_one_arg() and check_incompatible_arguments() diff -r 51ee9809d90d -r e682bbe66e37 hgext3rd/evolve/compat.py --- a/hgext3rd/evolve/compat.py Sun May 09 20:02:01 2021 +0800 +++ b/hgext3rd/evolve/compat.py Sat May 15 02:58:04 2021 +0800 @@ -8,14 +8,17 @@ import contextlib +from mercurial.i18n import _ from mercurial import ( cmdutil, context, copies, + error, hg, logcmdutil, merge as mergemod, obsolete, + pycompat, registrar, repair, scmutil, @@ -432,3 +435,35 @@ def format_changeset_summary_fn(ui, repo, command, default_spec): return logcmdutil.changesetdisplayer(ui, repo, {b'template': default_spec}).show + +if util.safehasattr(cmdutil, 'check_at_most_one_arg'): + def check_at_most_one_arg(opts, *args): + return cmdutil.check_at_most_one_arg(opts, *args) +else: + # hg <= 5.2 (d587937600be) + def check_at_most_one_arg(opts, *args): + def to_display(name): + return pycompat.sysbytes(name).replace(b'_', b'-') + + if util.safehasattr(error, 'InputError'): + err = error.InputError + else: + # hg <= 5.6 (8d72e29ad1e0) + err = error.Abort + previous = None + for x in args: + if opts.get(x): + if previous: + raise err(_(b'cannot specify both --%s and --%s') + % (to_display(previous), to_display(x))) + previous = x + return previous + +if util.safehasattr(cmdutil, 'check_incompatible_arguments'): + def check_incompatible_arguments(opts, first, others): + return cmdutil.check_incompatible_arguments(opts, first, others) +else: + # hg <= 5.2 (023ad45e2fd2) + def check_incompatible_arguments(opts, first, others): + for other in others: + check_at_most_one_arg(opts, first, other)