Skip to content

Commit

Permalink
revsets: Add descendants_at and ancestors_at
Browse files Browse the repository at this point in the history
They are needed for `next` and `prev`.
They behave symmetrically for parents and children.
  • Loading branch information
PhilipMetzger committed Aug 3, 2023
1 parent bf2af12 commit 32297f1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ impl RevsetExpression {
})
}

/// Ancestors of `self`, including `self` up to `generations` back.
pub fn ancestors_at(self: &Rc<RevsetExpression>, generations: u64) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Ancestors {
heads: self.clone(),
generation: (generations - 1)..generations,
is_legacy: false,
})
}

/// Children of `self`.
pub fn children(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Descendants {
Expand All @@ -405,6 +414,15 @@ impl RevsetExpression {
})
}

/// Descendants of `self`, including `self` up to `generations` back.
pub fn descendants_at(self: &Rc<RevsetExpression>, generations: u64) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Descendants {
roots: self.clone(),
generation: (generations - 1)..generations,
is_legacy: false,
})
}

/// Commits that are descendants of `self` and ancestors of `heads`, both
/// inclusive.
pub fn dag_range_to(
Expand Down

0 comments on commit 32297f1

Please sign in to comment.