Patchwork D7639: releasenotes: extract helper for checking for incompatible arguments

login
register
mail settings
Submitter phabricator
Date Dec. 13, 2019, 10:57 p.m.
Message ID <1b6f5f79698e7af9d27797a5cdffcf31@localhost.localdomain>
Download mbox | patch
Permalink /patch/43818/
State Not Applicable
Headers show

Comments

phabricator - Dec. 13, 2019, 10:57 p.m.
martinvonz edited the summary of this revision.
martinvonz retitled this revision from "releasenotes: use cmdutil.check_unique_argument()" to "releasenotes: extract helper for checking for incompatible arguments".
martinvonz updated this revision to Diff 18708.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7639?vs=18674&id=18708

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7639/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7639

AFFECTED FILES
  hgext/releasenotes.py
  mercurial/cmdutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -272,6 +272,16 @@ 
             previous = x
 
 
+def check_incompatible_arguments(opts, first, *others):
+    """abort if the first argument is given along with any of the others
+
+    Unlike check_unique_argument(), `others` are not mutually exclusive
+    among themselves.
+    """
+    for other in others:
+        check_unique_argument(opts, first, other)
+
+
 def resolvecommitoptions(ui, opts):
     """modify commit options dict to handle related options
 
diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py
--- a/hgext/releasenotes.py
+++ b/hgext/releasenotes.py
@@ -20,6 +20,7 @@ 
 from mercurial.i18n import _
 from mercurial.pycompat import open
 from mercurial import (
+    cmdutil,
     config,
     error,
     minirst,
@@ -653,14 +654,9 @@ 
     opts = pycompat.byteskwargs(opts)
     sections = releasenotessections(ui, repo)
 
-    listflag = opts.get(b'list')
+    cmdutil.check_incompatible_arguments(opts, b'list', b'rev', b'check')
 
-    if listflag and opts.get(b'rev'):
-        raise error.Abort(_(b'cannot use both \'--list\' and \'--rev\''))
-    if listflag and opts.get(b'check'):
-        raise error.Abort(_(b'cannot use both \'--list\' and \'--check\''))
-
-    if listflag:
+    if opts.get(b'list'):
         return _getadmonitionlist(ui, sections)
 
     rev = opts.get(b'rev')