# HG changeset patch # User Anton Shestakov # Date 1649353376 -10800 # Node ID 0c780d972350cd4267a1a8089f6781ebbd848a07 # Parent 8c664ed9c1032bc399a0f278bdd65d79eb298967 topic: use check_incompatible_arguments() for --list with --clear or --rev diff -r 8c664ed9c103 -r 0c780d972350 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Thu Apr 07 20:28:11 2022 +0300 +++ b/hgext3rd/topic/__init__.py Thu Apr 07 20:42:56 2022 +0300 @@ -895,6 +895,8 @@ if age and topic: raise compat.InputError(_(b"cannot use --age while setting a topic")) + compat.check_incompatible_arguments(opts, 'list', ('clear', 'rev')) + touchedrevs = set() if rev: touchedrevs = scmutil.revrange(repo, rev) @@ -920,8 +922,6 @@ if list: ui.pager(b'topics') - if clear or rev: - raise error.Abort(_(b"cannot use --clear or --rev with --list")) if not topic: topic = repo.currenttopic if not topic: diff -r 8c664ed9c103 -r 0c780d972350 hgext3rd/topic/compat.py --- 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) diff -r 8c664ed9c103 -r 0c780d972350 tests/test-topic.t --- a/tests/test-topic.t Thu Apr 07 20:28:11 2022 +0300 +++ b/tests/test-topic.t Thu Apr 07 20:42:56 2022 +0300 @@ -261,6 +261,9 @@ $ hg topics --clear somerandomtopic abort: cannot use --clear when setting a topic [10] + $ hg topics --list --clear + abort: cannot specify both --list and --clear + [10] Trying some invalid topicnames