From f6570486e0941769b184fda057622547089d2c0d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 19 Apr 2023 19:31:06 +0900 Subject: [PATCH] revset: add descendants node to expression, resolve it later I'll add a substitution rule that folds (x+)+, and 'Descendants { roots }' is easier to process than 'DagRange { roots, heads }'. --- lib/src/revset.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 7c0feec9e..a50ac2b7a 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -237,6 +237,9 @@ pub enum RevsetExpression { heads: Rc, generation: Range, }, + Descendants { + roots: Rc, + }, // Commits that are ancestors of "heads" but not ancestors of "roots" Range { roots: Rc, @@ -360,7 +363,9 @@ impl RevsetExpression { /// Descendants of `self`, including `self`. pub fn descendants(self: &Rc) -> Rc { - self.dag_range_to(&RevsetExpression::visible_heads()) + Rc::new(RevsetExpression::Descendants { + roots: self.clone(), + }) } /// Commits that are descendants of `self` and ancestors of `heads`, both @@ -1243,6 +1248,8 @@ fn try_transform_expression( heads, generation: generation.clone(), }), + RevsetExpression::Descendants { roots } => transform_rec(roots, pre, post)? + .map(|roots| RevsetExpression::Descendants { roots }), RevsetExpression::Range { roots, heads, @@ -1834,6 +1841,10 @@ impl VisibilityResolutionContext<'_> { heads: self.resolve(heads).into(), generation: generation.clone(), }, + RevsetExpression::Descendants { roots } => ResolvedExpression::DagRange { + roots: self.resolve(roots).into(), + heads: self.resolve_visible_heads().into(), + }, RevsetExpression::Range { roots, heads, @@ -1929,6 +1940,7 @@ impl VisibilityResolutionContext<'_> { | RevsetExpression::CommitRef(_) | RevsetExpression::Children(_) | RevsetExpression::Ancestors { .. } + | RevsetExpression::Descendants { .. } | RevsetExpression::Range { .. } | RevsetExpression::DagRange { .. } | RevsetExpression::Heads(_) @@ -2185,9 +2197,8 @@ mod tests { ); assert_eq!( foo_symbol.descendants(), - Rc::new(RevsetExpression::DagRange { + Rc::new(RevsetExpression::Descendants { roots: foo_symbol.clone(), - heads: RevsetExpression::visible_heads(), }) ); assert_eq!(