revsets: Add descendants_at and ancestors_at

They are needed for `next` and `prev`.
They behave symmetrically for parents and children.
This commit is contained in:
Philip Metzger 2023-07-06 23:57:24 +02:00 committed by Philip Metzger
parent 57f46a4bb7
commit 8dda7e21e0

View file

@ -444,6 +444,15 @@ impl RevsetExpression {
})
}
/// Ancestors of `self`, including `self` until `generation` back.
pub fn ancestors_at(self: &Rc<RevsetExpression>, generation: u64) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Ancestors {
heads: self.clone(),
generation: generation..(generation + 1),
is_legacy: false,
})
}
/// Children of `self`.
pub fn children(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Descendants {
@ -469,6 +478,15 @@ impl RevsetExpression {
})
}
/// Descendants of `self`, including `self` until `generation` ahead.
pub fn descendants_at(self: &Rc<RevsetExpression>, generation: u64) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Descendants {
roots: self.clone(),
generation: generation..(generation + 1),
is_legacy: false,
})
}
/// Commits that are descendants of `self` and ancestors of `heads`, both
/// inclusive.
pub fn dag_range_to(