mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-09 22:16:32 +00:00
cli: add WorkspaceCommandHelper::evaluate_revset(expr)
I'll add more workspace-derived parameters to RevsetExpression::evaluate().
This commit is contained in:
parent
977cfd3d4a
commit
0e1f098376
2 changed files with 23 additions and 26 deletions
|
@ -33,7 +33,7 @@ use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, WorkspaceId};
|
||||||
use jujutsu_lib::operation::Operation;
|
use jujutsu_lib::operation::Operation;
|
||||||
use jujutsu_lib::repo::{BackendFactories, MutableRepo, ReadonlyRepo, RepoRef, RewriteRootCommit};
|
use jujutsu_lib::repo::{BackendFactories, MutableRepo, ReadonlyRepo, RepoRef, RewriteRootCommit};
|
||||||
use jujutsu_lib::repo_path::{FsPathParseError, RepoPath};
|
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::settings::UserSettings;
|
||||||
use jujutsu_lib::transaction::Transaction;
|
use jujutsu_lib::transaction::Transaction;
|
||||||
use jujutsu_lib::tree::{Tree, TreeMergeError};
|
use jujutsu_lib::tree::{Tree, TreeMergeError};
|
||||||
|
@ -553,8 +553,7 @@ impl WorkspaceCommandHelper {
|
||||||
|
|
||||||
pub fn resolve_single_rev(&self, revision_str: &str) -> Result<Commit, CommandError> {
|
pub fn resolve_single_rev(&self, revision_str: &str) -> Result<Commit, CommandError> {
|
||||||
let revset_expression = revset::parse(revision_str)?;
|
let revset_expression = revset::parse(revision_str)?;
|
||||||
let revset =
|
let revset = self.evaluate_revset(&revset_expression)?;
|
||||||
revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.workspace_id()))?;
|
|
||||||
let mut iter = revset.iter().commits(self.repo.store());
|
let mut iter = revset.iter().commits(self.repo.store());
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
None => Err(CommandError::UserError(format!(
|
None => Err(CommandError::UserError(format!(
|
||||||
|
@ -576,8 +575,7 @@ impl WorkspaceCommandHelper {
|
||||||
|
|
||||||
pub fn resolve_revset(&self, revision_str: &str) -> Result<Vec<Commit>, CommandError> {
|
pub fn resolve_revset(&self, revision_str: &str) -> Result<Vec<Commit>, CommandError> {
|
||||||
let revset_expression = revset::parse(revision_str)?;
|
let revset_expression = revset::parse(revision_str)?;
|
||||||
let revset =
|
let revset = self.evaluate_revset(&revset_expression)?;
|
||||||
revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.workspace_id()))?;
|
|
||||||
Ok(revset
|
Ok(revset
|
||||||
.iter()
|
.iter()
|
||||||
.commits(self.repo.store())
|
.commits(self.repo.store())
|
||||||
|
@ -585,6 +583,13 @@ impl WorkspaceCommandHelper {
|
||||||
.collect())
|
.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> {
|
pub fn check_rewriteable(&self, commit: &Commit) -> Result<(), CommandError> {
|
||||||
if commit.id() == self.repo.store().root_commit_id() {
|
if commit.id() == self.repo.store().root_commit_id() {
|
||||||
return Err(CommandError::UserError(
|
return Err(CommandError::UserError(
|
||||||
|
|
|
@ -2073,7 +2073,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
|
||||||
let workspace_id = workspace_command.workspace_id();
|
let workspace_id = workspace_command.workspace_id();
|
||||||
let checkout_id = repo.view().get_wc_commit_id(&workspace_id);
|
let checkout_id = repo.view().get_wc_commit_id(&workspace_id);
|
||||||
let matcher = workspace_command.matcher_from_values(&args.paths)?;
|
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() {
|
if !args.paths.is_empty() {
|
||||||
revset = revset::filter_by_diff(repo.as_repo_ref(), matcher.as_ref(), revset);
|
revset = revset::filter_by_diff(repo.as_repo_ref(), matcher.as_ref(), revset);
|
||||||
}
|
}
|
||||||
|
@ -3095,11 +3095,8 @@ fn rebase_branch(
|
||||||
.roots();
|
.roots();
|
||||||
let mut num_rebased = 0;
|
let mut num_rebased = 0;
|
||||||
let store = workspace_command.repo().store();
|
let store = workspace_command.repo().store();
|
||||||
for root_result in roots_expression
|
for root_result in workspace_command
|
||||||
.evaluate(
|
.evaluate_revset(&roots_expression)
|
||||||
workspace_command.repo().as_repo_ref(),
|
|
||||||
Some(&workspace_command.workspace_id()),
|
|
||||||
)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.commits(store)
|
.commits(store)
|
||||||
|
@ -3154,11 +3151,8 @@ fn rebase_revision(
|
||||||
let mut num_rebased_descendants = 0;
|
let mut num_rebased_descendants = 0;
|
||||||
let store = workspace_command.repo().store();
|
let store = workspace_command.repo().store();
|
||||||
|
|
||||||
for child_commit in children_expression
|
for child_commit in workspace_command
|
||||||
.evaluate(
|
.evaluate_revset(&children_expression)
|
||||||
workspace_command.repo().as_repo_ref(),
|
|
||||||
Some(&workspace_command.workspace_id()),
|
|
||||||
)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.commits(store)
|
.commits(store)
|
||||||
|
@ -3182,20 +3176,18 @@ fn rebase_revision(
|
||||||
|
|
||||||
// Some of the new parents may be ancestors of others as in
|
// Some of the new parents may be ancestors of others as in
|
||||||
// `test_rebase_single_revision`.
|
// `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()),
|
||||||
RevsetExpression::commits(new_child_parent_ids.clone())
|
RevsetExpression::commits(new_child_parent_ids.clone())
|
||||||
.parents()
|
.parents()
|
||||||
.ancestors(),
|
.ancestors(),
|
||||||
)
|
);
|
||||||
.evaluate(
|
let new_child_parents: Result<Vec<Commit>, BackendError> = workspace_command
|
||||||
workspace_command.repo().as_repo_ref(),
|
.evaluate_revset(&new_child_parents_expression)
|
||||||
Some(&workspace_command.workspace_id()),
|
.unwrap()
|
||||||
)
|
.iter()
|
||||||
.unwrap()
|
.commits(store)
|
||||||
.iter()
|
.collect();
|
||||||
.commits(store)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
rebase_commit(
|
rebase_commit(
|
||||||
ui.settings(),
|
ui.settings(),
|
||||||
|
|
Loading…
Reference in a new issue