Mercurial > evolve
changeset 5913:e682bbe66e37
compat: add check_at_most_one_arg() and check_incompatible_arguments()
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sat, 15 May 2021 02:58:04 +0800 |
parents | 51ee9809d90d |
children | e8cc899a085a |
files | hgext3rd/evolve/compat.py |
diffstat | 1 files changed, 35 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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)