From ff25e6a6ff8d4ee81df825145a5ea0261bd80f43 Mon Sep 17 00:00:00 2001 From: Philip Metzger Date: Thu, 6 Jul 2023 23:57:24 +0200 Subject: [PATCH] revsets: Add `descendants_at` and `ancestors_at` They are needed for `next` and `prev`. They behave symmetrically for parents and children. --- lib/src/revset.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index b854844f96..d1a0562ac0 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -380,6 +380,15 @@ impl RevsetExpression { }) } + /// Ancestors of `self`, including `self` up to `generation` back. + pub fn ancestors_at(self: &Rc, generation: u64) -> Rc { + Rc::new(RevsetExpression::Ancestors { + heads: self.clone(), + generation: generation..(generation + 1), + is_legacy: false, + }) + } + /// Children of `self`. pub fn children(self: &Rc) -> Rc { Rc::new(RevsetExpression::Descendants { @@ -405,6 +414,15 @@ impl RevsetExpression { }) } + /// Descendants of `self`, including `self` up to `generation` back. + pub fn descendants_at(self: &Rc, generation: u64) -> Rc { + Rc::new(RevsetExpression::Descendants { + roots: self.clone(), + generation: (generation - 1)..generation, + is_legacy: false, + }) + } + /// Commits that are descendants of `self` and ancestors of `heads`, both /// inclusive. pub fn dag_range_to(