Mercurial > evolve
diff hgext3rd/topic/compat.py @ 6320:0c780d972350
topic: use check_incompatible_arguments() for --list with --clear or --rev
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Thu, 07 Apr 2022 20:42:56 +0300 |
parents | 3e488afe62f5 |
children | 58b856416d2e |
line wrap: on
line diff
--- a/hgext3rd/topic/compat.py Thu Apr 07 20:28:11 2022 +0300 +++ b/hgext3rd/topic/compat.py Thu Apr 07 20:42:56 2022 +0300 @@ -7,6 +7,7 @@ """ from __future__ import absolute_import +from mercurial.i18n import _ from mercurial import ( cmdutil, error, @@ -56,3 +57,36 @@ else: # hg <= 5.6 (8d72e29ad1e0) InputError = error.Abort + +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'-') + + previous = None + for x in args: + if opts.get(x): + if previous: + raise InputError(_(b'cannot specify both --%s and --%s') + % (to_display(previous), to_display(x))) + previous = x + return previous + +if util.safehasattr(cmdutil, 'check_incompatible_arguments'): + code = cmdutil.check_incompatible_arguments.__code__ + if r'others' in code.co_varnames[:code.co_argcount]: + def check_incompatible_arguments(opts, first, others): + return cmdutil.check_incompatible_arguments(opts, first, others) + else: + # hg <= 5.3 (d4c1501225c4) + 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)