Patchwork D8394: revset: implement a simple 'foo#generations' expression

login
register
mail settings
Submitter phabricator
Date April 15, 2020, 3:18 p.m.
Message ID <3c05bbc073da1b41fb482001d5ddf07c@localhost.localdomain>
Download mbox | patch
Permalink /patch/46129/
State Not Applicable
Headers show

Comments

phabricator - April 15, 2020, 3:18 p.m.
Closed by commit rHGeca82eb9d777: revset: implement a simple &#039;foo#generations&#039; expression (authored by av6).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8394?vs=21028&id=21101

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

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

AFFECTED FILES
  mercurial/revset.py
  tests/test-revset.t

CHANGE DETAILS




To: av6, yuja, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1274,6 +1274,36 @@ 
   5
   7
 
+test ancestors/descendants relation:
+
+  $ log 'tip#generations'
+  0
+  1
+  2
+  4
+  8
+  9
+
+  $ log '3#g'
+  0
+  1
+  3
+  5
+  6
+  7
+
+  $ hg debugrevspec -p parsed 'tip#g'
+  * parsed:
+  (relation
+    (symbol 'tip')
+    (symbol 'g'))
+  0
+  1
+  2
+  4
+  8
+  9
+
 test ancestors/descendants relation subscript:
 
   $ log 'tip#generations[0]'
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -247,7 +247,15 @@ 
 
 
 def relationset(repo, subset, x, y, order):
-    raise error.ParseError(_(b"can't use a relation in this context"))
+    # this is pretty basic implementation of 'x#y' operator, still
+    # experimental so undocumented. see the wiki for further ideas.
+    # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
+    rel = getsymbol(y)
+    if rel in relations:
+        return relations[rel](repo, subset, x, rel, order)
+
+    relnames = [r for r in relations.keys() if len(r) > 1]
+    raise error.UnknownIdentifier(rel, relnames)
 
 
 def _splitrange(a, b):
@@ -281,6 +289,11 @@ 
     return ancdepths, descdepths
 
 
+def generationsrel(repo, subset, x, rel, order):
+    z = (b'rangeall', None)
+    return generationssubrel(repo, subset, x, rel, z, order)
+
+
 def generationssubrel(repo, subset, x, rel, z, order):
     # TODO: rewrite tests, and drop startdepth argument from ancestors() and
     # descendants() predicates
@@ -2649,6 +2662,11 @@ 
     b"smartset": rawsmartset,
 }
 
+relations = {
+    b"g": generationsrel,
+    b"generations": generationsrel,
+}
+
 subscriptrelations = {
     b"g": generationssubrel,
     b"generations": generationssubrel,