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

login
register
mail settings
Submitter phabricator
Date April 10, 2020, 5:02 p.m.
Message ID <differential-rev-PHID-DREV-ojkzopepd5utnbreg6je-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46059/
State Superseded
Headers show

Comments

phabricator - April 10, 2020, 5:02 p.m.
av6 created this revision.
av6 added a reviewer: yuja.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The result of this expression is equivalent to 'foo#g[:]': all reachable
  ancestors and descendants of a revset foo.
  
  While not very useful functionality on its own, its implementation can be
  tested and revset.relations dict can be easily used by extensions to add other
  non-subscript relations.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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
@@ -2633,6 +2646,11 @@ 
     b"smartset": rawsmartset,
 }
 
+relations = {
+    b"g": generationsrel,
+    b"generations": generationsrel,
+}
+
 subscriptrelations = {
     b"g": generationssubrel,
     b"generations": generationssubrel,