From 987b294e428192cb97ac6a3e96044770ee19beec Mon Sep 17 00:00:00 2001 From: Philip Metzger Date: Sun, 12 May 2024 17:03:00 +0200 Subject: [PATCH] lib: Add `RevsetExpression::is_empty()`, which filters out empty commits. This is also needed for `prev/next --conflict` with the `--edit` flag passed, as without it we may resolve the `RevsetExpression` multiple commits. A future cleanup should use this in the actual revset resolution code. --- lib/src/revset.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index dbbdb22dc8..54abdaf3b8 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -291,6 +291,11 @@ impl RevsetExpression { Rc::new(RevsetExpression::Filter(predicate)) } + /// Find any empty commits. + pub fn is_empty() -> Rc { + Self::filter(RevsetFilterPredicate::File(FilesetExpression::all())).negated() + } + /// Commits in `self` that don't have descendants in `self`. pub fn heads(self: &Rc) -> Rc { Rc::new(RevsetExpression::Heads(self.clone())) @@ -363,6 +368,7 @@ impl RevsetExpression { ) -> Rc { self.intersection(&RevsetExpression::filter(predicate)) } + /// Commits that are descendants of `self` and ancestors of `heads`, both /// inclusive. pub fn dag_range_to( @@ -751,10 +757,7 @@ static BUILTIN_FUNCTION_MAP: Lazy> = Lazy: }); map.insert("empty", |name, arguments_pair, _state| { expect_no_arguments(name, arguments_pair)?; - Ok( - RevsetExpression::filter(RevsetFilterPredicate::File(FilesetExpression::all())) - .negated(), - ) + Ok(RevsetExpression::is_empty()) }); map.insert("file", |name, arguments_pair, state| { let arguments_span = arguments_pair.as_span();