revset: add ancestors_range() method

This commit is contained in:
James Sully 2023-09-07 16:24:40 +10:00
parent 233b31fdf2
commit 6ea10906a8

View file

@ -524,11 +524,7 @@ impl RevsetExpression {
/// Ancestors of `self`, including `self`. /// Ancestors of `self`, including `self`.
pub fn ancestors(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> { pub fn ancestors(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Ancestors { self.ancestors_range(GENERATION_RANGE_FULL)
heads: self.clone(),
generation: GENERATION_RANGE_FULL,
is_legacy: false,
})
} }
fn legacy_ancestors(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> { fn legacy_ancestors(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Ancestors { Rc::new(RevsetExpression::Ancestors {
@ -540,9 +536,17 @@ impl RevsetExpression {
/// Ancestors of `self`, including `self` until `generation` back. /// Ancestors of `self`, including `self` until `generation` back.
pub fn ancestors_at(self: &Rc<RevsetExpression>, generation: u64) -> Rc<RevsetExpression> { pub fn ancestors_at(self: &Rc<RevsetExpression>, generation: u64) -> Rc<RevsetExpression> {
self.ancestors_range(generation..(generation + 1))
}
/// Ancestors of `self` in the given range.
pub fn ancestors_range(
self: &Rc<RevsetExpression>,
generation_range: Range<u64>,
) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Ancestors { Rc::new(RevsetExpression::Ancestors {
heads: self.clone(), heads: self.clone(),
generation: generation..(generation + 1), generation: generation_range,
is_legacy: false, is_legacy: false,
}) })
} }