cli: add WorkspaceCommandHelper::evaluate_revset(expr)

I'll add more workspace-derived parameters to RevsetExpression::evaluate().
This commit is contained in:
Yuya Nishihara 2022-10-23 12:55:09 +09:00
parent 977cfd3d4a
commit 0e1f098376
2 changed files with 23 additions and 26 deletions

View file

@ -33,7 +33,7 @@ use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, WorkspaceId};
use jujutsu_lib::operation::Operation;
use jujutsu_lib::repo::{BackendFactories, MutableRepo, ReadonlyRepo, RepoRef, RewriteRootCommit};
use jujutsu_lib::repo_path::{FsPathParseError, RepoPath};
use jujutsu_lib::revset::{RevsetError, RevsetParseError};
use jujutsu_lib::revset::{Revset, RevsetError, RevsetExpression, RevsetParseError};
use jujutsu_lib::settings::UserSettings;
use jujutsu_lib::transaction::Transaction;
use jujutsu_lib::tree::{Tree, TreeMergeError};
@ -553,8 +553,7 @@ impl WorkspaceCommandHelper {
pub fn resolve_single_rev(&self, revision_str: &str) -> Result<Commit, CommandError> {
let revset_expression = revset::parse(revision_str)?;
let revset =
revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.workspace_id()))?;
let revset = self.evaluate_revset(&revset_expression)?;
let mut iter = revset.iter().commits(self.repo.store());
match iter.next() {
None => Err(CommandError::UserError(format!(
@ -576,8 +575,7 @@ impl WorkspaceCommandHelper {
pub fn resolve_revset(&self, revision_str: &str) -> Result<Vec<Commit>, CommandError> {
let revset_expression = revset::parse(revision_str)?;
let revset =
revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.workspace_id()))?;
let revset = self.evaluate_revset(&revset_expression)?;
Ok(revset
.iter()
.commits(self.repo.store())
@ -585,6 +583,13 @@ impl WorkspaceCommandHelper {
.collect())
}
pub fn evaluate_revset<'repo>(
&'repo self,
revset_expression: &RevsetExpression,
) -> Result<Box<dyn Revset<'repo> + 'repo>, RevsetError> {
revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.workspace_id()))
}
pub fn check_rewriteable(&self, commit: &Commit) -> Result<(), CommandError> {
if commit.id() == self.repo.store().root_commit_id() {
return Err(CommandError::UserError(

View file

@ -2073,7 +2073,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let workspace_id = workspace_command.workspace_id();
let checkout_id = repo.view().get_wc_commit_id(&workspace_id);
let matcher = workspace_command.matcher_from_values(&args.paths)?;
let mut revset = revset_expression.evaluate(repo.as_repo_ref(), Some(&workspace_id))?;
let mut revset = workspace_command.evaluate_revset(&revset_expression)?;
if !args.paths.is_empty() {
revset = revset::filter_by_diff(repo.as_repo_ref(), matcher.as_ref(), revset);
}
@ -3095,11 +3095,8 @@ fn rebase_branch(
.roots();
let mut num_rebased = 0;
let store = workspace_command.repo().store();
for root_result in roots_expression
.evaluate(
workspace_command.repo().as_repo_ref(),
Some(&workspace_command.workspace_id()),
)
for root_result in workspace_command
.evaluate_revset(&roots_expression)
.unwrap()
.iter()
.commits(store)
@ -3154,11 +3151,8 @@ fn rebase_revision(
let mut num_rebased_descendants = 0;
let store = workspace_command.repo().store();
for child_commit in children_expression
.evaluate(
workspace_command.repo().as_repo_ref(),
Some(&workspace_command.workspace_id()),
)
for child_commit in workspace_command
.evaluate_revset(&children_expression)
.unwrap()
.iter()
.commits(store)
@ -3182,20 +3176,18 @@ fn rebase_revision(
// Some of the new parents may be ancestors of others as in
// `test_rebase_single_revision`.
let new_child_parents: Result<Vec<Commit>, BackendError> = RevsetExpression::Difference(
let new_child_parents_expression = RevsetExpression::Difference(
RevsetExpression::commits(new_child_parent_ids.clone()),
RevsetExpression::commits(new_child_parent_ids.clone())
.parents()
.ancestors(),
)
.evaluate(
workspace_command.repo().as_repo_ref(),
Some(&workspace_command.workspace_id()),
)
.unwrap()
.iter()
.commits(store)
.collect();
);
let new_child_parents: Result<Vec<Commit>, BackendError> = workspace_command
.evaluate_revset(&new_child_parents_expression)
.unwrap()
.iter()
.commits(store)
.collect();
rebase_commit(
ui.settings(),