cli: call RevsetExpression::evaluate() directly if no symbol resolution needed

There should be no problem to evaluate revset against base_repo and collect
commit objects from (mut_)repo, but it seemed a bit odd.

In rebase examples other than the "new --insert-after", we could switch to
tx.repo(). However, I think the use of tx.base_repo() makes it clear that
there's no data dependency on the previous mutation.
This commit is contained in:
Yuya Nishihara 2023-03-22 13:16:05 +09:00
parent c5503cee84
commit 2a87e1f95a

View File

@ -2050,9 +2050,9 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
} }
let new_children = RevsetExpression::commits(target_ids.clone()); let new_children = RevsetExpression::commits(target_ids.clone());
let new_parents = new_children.parents(); let new_parents = new_children.parents();
if let Some(commit_id) = tx if let Some(commit_id) = new_children
.base_workspace_helper() .dag_range_to(&new_parents)
.evaluate_revset(new_children.dag_range_to(&new_parents))? .evaluate(tx.repo())?
.iter() .iter()
.commit_ids() .commit_ids()
.next() .next()
@ -2063,9 +2063,8 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
short_commit_hash(&commit_id), short_commit_hash(&commit_id),
))); )));
} }
let mut new_parents_commits: Vec<Commit> = tx let mut new_parents_commits: Vec<Commit> = new_parents
.base_workspace_helper() .evaluate(tx.repo())?
.evaluate_revset(new_parents)?
.iter() .iter()
.commits(tx.repo().store()) .commits(tx.repo().store())
.try_collect()?; .try_collect()?;
@ -2111,22 +2110,20 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
let old_parents = RevsetExpression::commits(target_ids); let old_parents = RevsetExpression::commits(target_ids);
// Exclude children that are ancestors of the new commit // Exclude children that are ancestors of the new commit
let to_rebase = old_parents.children().minus(&old_parents.ancestors()); let to_rebase = old_parents.children().minus(&old_parents.ancestors());
let commits_to_rebase: Vec<Commit> = tx let commits_to_rebase: Vec<Commit> = to_rebase
.base_workspace_helper() .evaluate(tx.base_repo().as_ref())?
.evaluate_revset(to_rebase)?
.iter() .iter()
.commits(tx.repo().store()) .commits(tx.base_repo().store())
.try_collect()?; .try_collect()?;
num_rebased = commits_to_rebase.len(); num_rebased = commits_to_rebase.len();
for child_commit in commits_to_rebase { for child_commit in commits_to_rebase {
let commit_parents = let commit_parents =
RevsetExpression::commits(child_commit.parent_ids().to_owned()); RevsetExpression::commits(child_commit.parent_ids().to_owned());
let new_parents = commit_parents.minus(&old_parents); let new_parents = commit_parents.minus(&old_parents);
let mut new_parent_commits: Vec<Commit> = tx let mut new_parent_commits: Vec<Commit> = new_parents
.base_workspace_helper() .evaluate(tx.base_repo().as_ref())?
.evaluate_revset(new_parents)?
.iter() .iter()
.commits(tx.repo().store()) .commits(tx.base_repo().store())
.try_collect()?; .try_collect()?;
new_parent_commits.push(new_commit.clone()); new_parent_commits.push(new_commit.clone());
rebase_commit( rebase_commit(
@ -2879,8 +2876,8 @@ fn rebase_branch(
let roots_expression = RevsetExpression::commits(parent_ids) let roots_expression = RevsetExpression::commits(parent_ids)
.range(&RevsetExpression::commits(branch_commit_ids)) .range(&RevsetExpression::commits(branch_commit_ids))
.roots(); .roots();
let root_commits: IndexSet<_> = workspace_command let root_commits: IndexSet<_> = roots_expression
.evaluate_revset(roots_expression) .evaluate(workspace_command.repo().as_ref())
.unwrap() .unwrap()
.iter() .iter()
.commits(workspace_command.repo().store()) .commits(workspace_command.repo().store())
@ -2930,8 +2927,8 @@ fn rebase_revision(
workspace_command.check_rewritable(&old_commit)?; workspace_command.check_rewritable(&old_commit)?;
check_rebase_destinations(workspace_command.repo(), new_parents, &old_commit)?; check_rebase_destinations(workspace_command.repo(), new_parents, &old_commit)?;
let children_expression = RevsetExpression::commit(old_commit.id().clone()).children(); let children_expression = RevsetExpression::commit(old_commit.id().clone()).children();
let child_commits: Vec<_> = workspace_command let child_commits: Vec<_> = children_expression
.evaluate_revset(children_expression) .evaluate(workspace_command.repo().as_ref())
.unwrap() .unwrap()
.iter() .iter()
.commits(workspace_command.repo().store()) .commits(workspace_command.repo().store())
@ -2969,12 +2966,11 @@ fn rebase_revision(
.parents() .parents()
.ancestors(), .ancestors(),
); );
let new_child_parents: Vec<Commit> = tx let new_child_parents: Vec<Commit> = new_child_parents_expression
.base_workspace_helper() .evaluate(tx.base_repo().as_ref())
.evaluate_revset(new_child_parents_expression)
.unwrap() .unwrap()
.iter() .iter()
.commits(tx.repo().store()) .commits(tx.base_repo().store())
.try_collect()?; .try_collect()?;
rebase_commit( rebase_commit(