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, 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]'