Patchwork [3,of,3] revset: add support of keyword arguments to ancestors() and descendants()

login
register
mail settings
Submitter Yuya Nishihara
Date June 19, 2017, 2:43 p.m.
Message ID <9049776fffd7d3008326.1497883417@mimosa>
Download mbox | patch
Permalink /patch/21505/
State Accepted
Headers show

Comments

Yuya Nishihara - June 19, 2017, 2:43 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1497755182 -32400
#      Sun Jun 18 12:06:22 2017 +0900
# Node ID 9049776fffd7d3008326151a5372de84fdd5b399
# Parent  870d869fd996ee5d8838d378d866ae34d43739a6
revset: add support of keyword arguments to ancestors() and descendants()

Prepares for adding depth parameter.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -250,7 +250,11 @@  def ancestors(repo, subset, x):
     """Changesets that are ancestors of changesets in set, including the
     given changesets themselves.
     """
-    return _ancestors(repo, subset, x)
+    args = getargsdict(x, 'ancestors', 'set')
+    if 'set' not in args:
+        # i18n: "ancestors" is a keyword
+        raise error.ParseError(_('ancestors takes at least 1 argument'))
+    return _ancestors(repo, subset, args['set'])
 
 @predicate('_firstancestors', safe=True)
 def _firstancestors(repo, subset, x):
@@ -596,7 +600,11 @@  def descendants(repo, subset, x):
     """Changesets which are descendants of changesets in set, including the
     given changesets themselves.
     """
-    return _descendants(repo, subset, x)
+    args = getargsdict(x, 'descendants', 'set')
+    if 'set' not in args:
+        # i18n: "descendants" is a keyword
+        raise error.ParseError(_('descendants takes at least 1 argument'))
+    return _descendants(repo, subset, args['set'])
 
 @predicate('_firstdescendants', safe=True)
 def _firstdescendants(repo, subset, x):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -2996,8 +2996,7 @@  optimization to only() works only if anc
         ('symbol', '1'))
       any)
     define)
-  hg: parse error: can't use a list in this context
-  (see hg help "revsets.x or y")
+  hg: parse error: ancestors takes at most 1 positional arguments
   [255]
   $ hg debugrevspec -p optimized 'ancestors(6, 1) - ancestors(4)'
   * optimized:
@@ -3013,8 +3012,7 @@  optimization to only() works only if anc
       ('symbol', '4')
       any)
     define)
-  hg: parse error: can't use a list in this context
-  (see hg help "revsets.x or y")
+  hg: parse error: ancestors takes at most 1 positional arguments
   [255]
 
 optimization disabled if keyword arguments passed (because we're too lazy
@@ -3036,8 +3034,9 @@  to support it)
         ('symbol', '4'))
       any)
     define)
-  hg: parse error: can't use a key-value pair in this context
-  [255]
+  3
+  5
+  6
 
 invalid function call should not be optimized to only()