From 9475ab61bb2bee242cac9d86bfe4a4bd3dd20d27 Mon Sep 17 00:00:00 2001 From: Philip Metzger Date: Sun, 18 Feb 2024 18:57:55 +0100 Subject: [PATCH] lib: Add `RevsetExpression::filtered()`. This allows users to easily filter a commit range by conflicts, which will be needed for `next/prev` further down in the next commit. Users which benefit from it were also migrated. --- cli/src/cli_util.rs | 5 ++--- cli/src/commands/status.rs | 6 ++++-- lib/src/revset.rs | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 18aad423fc..d7ef071108 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1418,9 +1418,8 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin // are millions of commits added to the repo, assuming the revset engine can // efficiently skip non-conflicting commits. Filter out empty commits mostly so // `jj new ` doesn't result in a message about new conflicts. - let conflicts = RevsetExpression::filter(RevsetFilterPredicate::HasConflict).intersection( - &RevsetExpression::filter(RevsetFilterPredicate::File(FilesetExpression::all())), - ); + let conflicts = RevsetExpression::filter(RevsetFilterPredicate::HasConflict) + .filtered(RevsetFilterPredicate::File(FilesetExpression::all())); let removed_conflicts_expr = new_heads.range(&old_heads).intersection(&conflicts); let added_conflicts_expr = old_heads.range(&new_heads).intersection(&conflicts); diff --git a/cli/src/commands/status.rs b/cli/src/commands/status.rs index 788cd5b640..7eb3eb4f3d 100644 --- a/cli/src/commands/status.rs +++ b/cli/src/commands/status.rs @@ -95,8 +95,10 @@ pub(crate) fn cmd_status( // Ancestors with conflicts, excluding the current working copy commit. let ancestors_conflicts = workspace_command .attach_revset_evaluator( - RevsetExpression::filter(RevsetFilterPredicate::HasConflict) - .intersection(&wc_revset.parents().ancestors()) + wc_revset + .parents() + .ancestors() + .filtered(RevsetFilterPredicate::HasConflict) .minus(&revset_util::parse_immutable_expression( &workspace_command.revset_parse_context(), )?), diff --git a/lib/src/revset.rs b/lib/src/revset.rs index ff5d86a997..dbbdb22dc8 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -356,6 +356,13 @@ impl RevsetExpression { }) } + /// Filter all commits by `predicate` in `self`. + pub fn filtered( + self: &Rc, + predicate: RevsetFilterPredicate, + ) -> Rc { + self.intersection(&RevsetExpression::filter(predicate)) + } /// Commits that are descendants of `self` and ancestors of `heads`, both /// inclusive. pub fn dag_range_to(