revset: evaluate optimized expression

This commit is contained in:
Yuya Nishihara 2022-10-25 22:01:41 +09:00
parent 4d5936983a
commit f48675ad90
3 changed files with 8 additions and 6 deletions

View File

@ -21,7 +21,7 @@ use jujutsu_lib::op_store::{RefTarget, WorkspaceId};
use jujutsu_lib::repo::RepoRef; use jujutsu_lib::repo::RepoRef;
use jujutsu_lib::repo_path::RepoPath; use jujutsu_lib::repo_path::RepoPath;
use jujutsu_lib::revset::{ use jujutsu_lib::revset::{
self, parse, resolve_symbol, RevsetError, RevsetExpression, RevsetWorkspaceContext, self, optimize, parse, resolve_symbol, RevsetError, RevsetExpression, RevsetWorkspaceContext,
}; };
use jujutsu_lib::testutils::{CommitGraphBuilder, TestRepo, TestWorkspace}; use jujutsu_lib::testutils::{CommitGraphBuilder, TestRepo, TestWorkspace};
use jujutsu_lib::workspace::Workspace; use jujutsu_lib::workspace::Workspace;
@ -423,7 +423,7 @@ fn test_resolve_symbol_git_refs() {
} }
fn resolve_commit_ids(repo: RepoRef, revset_str: &str) -> Vec<CommitId> { fn resolve_commit_ids(repo: RepoRef, revset_str: &str) -> Vec<CommitId> {
let expression = parse(revset_str).unwrap(); let expression = optimize(parse(revset_str).unwrap());
expression expression
.evaluate(repo, None) .evaluate(repo, None)
.unwrap() .unwrap()
@ -438,7 +438,7 @@ fn resolve_commit_ids_in_workspace(
workspace: &Workspace, workspace: &Workspace,
cwd: Option<&Path>, cwd: Option<&Path>,
) -> Vec<CommitId> { ) -> Vec<CommitId> {
let expression = parse(revset_str).unwrap(); let expression = optimize(parse(revset_str).unwrap());
let workspace_ctx = RevsetWorkspaceContext { let workspace_ctx = RevsetWorkspaceContext {
cwd: cwd.unwrap_or_else(|| workspace.workspace_root()), cwd: cwd.unwrap_or_else(|| workspace.workspace_root()),
workspace_id: workspace.workspace_id(), workspace_id: workspace.workspace_id(),

View File

@ -554,7 +554,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::optimize(revset::parse(revision_str)?);
let revset = self.evaluate_revset(&revset_expression)?; let revset = self.evaluate_revset(&revset_expression)?;
let mut iter = revset.iter().commits(self.repo.store()); let mut iter = revset.iter().commits(self.repo.store());
match iter.next() { match iter.next() {
@ -576,7 +576,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::optimize(revset::parse(revision_str)?);
let revset = self.evaluate_revset(&revset_expression)?; let revset = self.evaluate_revset(&revset_expression)?;
Ok(revset Ok(revset
.iter() .iter()

View File

@ -2070,7 +2070,9 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let workspace_command = command.workspace_helper(ui)?; let workspace_command = command.workspace_helper(ui)?;
let default_revset = ui.settings().default_revset(); let default_revset = ui.settings().default_revset();
let revset_expression = revset::parse(args.revisions.as_ref().unwrap_or(&default_revset))?; let revset_expression = revset::optimize(revset::parse(
args.revisions.as_ref().unwrap_or(&default_revset),
)?);
let repo = workspace_command.repo(); let repo = workspace_command.repo();
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);