Skip to content

Commit

Permalink
lib: Add RevsetExpression::filtered().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PhilipMetzger committed May 18, 2024
1 parent 6d211c5 commit d7ea1d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <conflicted commit>` 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);

Expand Down
7 changes: 7 additions & 0 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ impl RevsetExpression {
})
}

/// Filter all commits by `predicate` in `self`.
pub fn filtered(
self: &Rc<RevsetExpression>,
predicate: RevsetFilterPredicate,
) -> 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

0 comments on commit d7ea1d5

Please sign in to comment.