mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-01 00:50:57 +00:00
cli: add convenient method to intersect user revset with other expression
This pattern is common, and most callers of evaluate_revset() can now be migrated to the wrapper API.
This commit is contained in:
parent
690270670e
commit
784d735ecc
5 changed files with 20 additions and 26 deletions
|
@ -1016,10 +1016,10 @@ impl WorkspaceCommandHelper {
|
||||||
.map(|commit| commit.id().clone())
|
.map(|commit| commit.id().clone())
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
let immutable_revset =
|
let immutable = revset_util::parse_immutable_expression(&self.revset_parse_context())?;
|
||||||
revset_util::parse_immutable_expression(&self.revset_parse_context())?;
|
let mut expression = self.attach_revset_evaluator(immutable)?;
|
||||||
let revset = self.evaluate_revset(to_rewrite_revset.intersection(&immutable_revset))?;
|
expression.intersect_with(&to_rewrite_revset);
|
||||||
if let Some(commit) = revset.iter().commits(self.repo().store()).next() {
|
if let Some(commit) = expression.evaluate_to_commits()?.next() {
|
||||||
let commit = commit?;
|
let commit = commit?;
|
||||||
let error = if commit.id() == self.repo().store().root_commit_id() {
|
let error = if commit.id() == self.repo().store().root_commit_id() {
|
||||||
user_error(format!(
|
user_error(format!(
|
||||||
|
|
|
@ -18,7 +18,6 @@ use std::io::Write as _;
|
||||||
|
|
||||||
use clap::builder::NonEmptyStringValueParser;
|
use clap::builder::NonEmptyStringValueParser;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use jj_lib::backend::CommitId;
|
|
||||||
use jj_lib::git;
|
use jj_lib::git;
|
||||||
use jj_lib::object_id::ObjectId;
|
use jj_lib::object_id::ObjectId;
|
||||||
use jj_lib::op_store::{RefTarget, RemoteRef};
|
use jj_lib::op_store::{RefTarget, RemoteRef};
|
||||||
|
@ -624,15 +623,10 @@ fn cmd_branch_list(
|
||||||
}
|
}
|
||||||
if !args.revisions.is_empty() {
|
if !args.revisions.is_empty() {
|
||||||
// Match against local targets only, which is consistent with "jj git push".
|
// Match against local targets only, which is consistent with "jj git push".
|
||||||
let filter_expression = workspace_command
|
let mut expression = workspace_command.parse_union_revsets(&args.revisions)?;
|
||||||
.parse_union_revsets(&args.revisions)?
|
|
||||||
.expression()
|
|
||||||
.clone();
|
|
||||||
// Intersects with the set of local branch targets to minimize the lookup space.
|
// Intersects with the set of local branch targets to minimize the lookup space.
|
||||||
let revset_expression = RevsetExpression::branches(StringPattern::everything())
|
expression.intersect_with(&RevsetExpression::branches(StringPattern::everything()));
|
||||||
.intersection(&filter_expression);
|
let filtered_targets: HashSet<_> = expression.evaluate_to_commit_ids()?.collect();
|
||||||
let revset = workspace_command.evaluate_revset(revset_expression)?;
|
|
||||||
let filtered_targets: HashSet<CommitId> = revset.iter().collect();
|
|
||||||
branch_names.extend(
|
branch_names.extend(
|
||||||
view.local_branches()
|
view.local_branches()
|
||||||
.filter(|(_, target)| {
|
.filter(|(_, target)| {
|
||||||
|
|
|
@ -1203,12 +1203,9 @@ fn find_branches_targeted_by_revisions<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for rev_str in revisions {
|
for rev_str in revisions {
|
||||||
let expression = workspace_command
|
let mut expression = workspace_command.parse_revset(rev_str)?;
|
||||||
.parse_revset(rev_str)?
|
expression.intersect_with(&RevsetExpression::branches(StringPattern::everything()));
|
||||||
.expression()
|
let mut commit_ids = expression.evaluate_to_commit_ids()?.peekable();
|
||||||
.intersection(&RevsetExpression::branches(StringPattern::everything()));
|
|
||||||
let revset = workspace_command.evaluate_revset(expression)?;
|
|
||||||
let mut commit_ids = revset.iter().peekable();
|
|
||||||
if commit_ids.peek().is_none() {
|
if commit_ids.peek().is_none() {
|
||||||
let rev_str: &str = rev_str;
|
let rev_str: &str = rev_str;
|
||||||
writeln!(
|
writeln!(
|
||||||
|
|
|
@ -81,24 +81,22 @@ pub(crate) fn cmd_log(
|
||||||
workspace_command.parse_revset(&command.settings().default_revset())?
|
workspace_command.parse_revset(&command.settings().default_revset())?
|
||||||
} else {
|
} else {
|
||||||
workspace_command.parse_union_revsets(&args.revisions)?
|
workspace_command.parse_union_revsets(&args.revisions)?
|
||||||
}
|
};
|
||||||
.expression()
|
|
||||||
.clone();
|
|
||||||
if !args.paths.is_empty() {
|
if !args.paths.is_empty() {
|
||||||
let repo_paths: Vec<_> = args
|
let repo_paths: Vec<_> = args
|
||||||
.paths
|
.paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path_arg| workspace_command.parse_file_path(path_arg))
|
.map(|path_arg| workspace_command.parse_file_path(path_arg))
|
||||||
.try_collect()?;
|
.try_collect()?;
|
||||||
expression = expression.intersection(&RevsetExpression::filter(
|
expression.intersect_with(&RevsetExpression::filter(RevsetFilterPredicate::File(
|
||||||
RevsetFilterPredicate::File(Some(repo_paths)),
|
Some(repo_paths),
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
expression
|
expression
|
||||||
};
|
};
|
||||||
let repo = workspace_command.repo();
|
let repo = workspace_command.repo();
|
||||||
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
||||||
let revset = workspace_command.evaluate_revset(revset_expression)?;
|
let revset = revset_expression.evaluate()?;
|
||||||
|
|
||||||
let store = repo.store();
|
let store = repo.store();
|
||||||
let diff_formats =
|
let diff_formats =
|
||||||
|
|
|
@ -67,6 +67,11 @@ impl<'repo> RevsetExpressionEvaluator<'repo> {
|
||||||
&self.expression
|
&self.expression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Intersects the underlying expression with the `other` expression.
|
||||||
|
pub fn intersect_with(&mut self, other: &Rc<RevsetExpression>) {
|
||||||
|
self.expression = self.expression.intersection(other);
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluates the expression.
|
/// Evaluates the expression.
|
||||||
pub fn evaluate(&self) -> Result<Box<dyn Revset + 'repo>, UserRevsetEvaluationError> {
|
pub fn evaluate(&self) -> Result<Box<dyn Revset + 'repo>, UserRevsetEvaluationError> {
|
||||||
let symbol_resolver = default_symbol_resolver(self.repo, self.id_prefix_context);
|
let symbol_resolver = default_symbol_resolver(self.repo, self.id_prefix_context);
|
||||||
|
|
Loading…
Reference in a new issue