Skip to content

Commit

Permalink
lib: Add RevsetExpression::is_empty(), which filters out empty comm…
Browse files Browse the repository at this point in the history
…its.

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.
  • Loading branch information
PhilipMetzger committed May 15, 2024
1 parent f66eb1c commit 987b294
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ impl RevsetExpression {
Rc::new(RevsetExpression::Filter(predicate))
}

/// Find any empty commits.
pub fn is_empty() -> Rc<RevsetExpression> {
Self::filter(RevsetFilterPredicate::File(FilesetExpression::all())).negated()
}

/// Commits in `self` that don't have descendants in `self`.
pub fn heads(self: &Rc<RevsetExpression>) -> Rc<RevsetExpression> {
Rc::new(RevsetExpression::Heads(self.clone()))
Expand Down Expand Up @@ -363,6 +368,7 @@ impl RevsetExpression {
) -> Rc<RevsetExpression> {
self.intersection(&RevsetExpression::filter(predicate))
}

/// Commits that are descendants of `self` and ancestors of `heads`, both
/// inclusive.
pub fn dag_range_to(
Expand Down Expand Up @@ -751,10 +757,7 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, RevsetFunction>> = 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();
Expand Down

0 comments on commit 987b294

Please sign in to comment.