forked from mirrors/jj
cli: add helper to set up op template environment for the current repo state
We'll add a few more callers.
This commit is contained in:
parent
0c0e1b61e3
commit
9dc2cf802c
2 changed files with 15 additions and 11 deletions
|
@ -156,6 +156,7 @@ use crate::git_util::print_git_import_stats;
|
||||||
use crate::merge_tools::DiffEditor;
|
use crate::merge_tools::DiffEditor;
|
||||||
use crate::merge_tools::MergeEditor;
|
use crate::merge_tools::MergeEditor;
|
||||||
use crate::merge_tools::MergeToolConfigError;
|
use crate::merge_tools::MergeToolConfigError;
|
||||||
|
use crate::operation_templater::OperationTemplateLanguage;
|
||||||
use crate::operation_templater::OperationTemplateLanguageExtension;
|
use crate::operation_templater::OperationTemplateLanguageExtension;
|
||||||
use crate::revset_util;
|
use crate::revset_util;
|
||||||
use crate::revset_util::RevsetExpressionEvaluator;
|
use crate::revset_util::RevsetExpressionEvaluator;
|
||||||
|
@ -1293,6 +1294,15 @@ impl WorkspaceCommandHelper {
|
||||||
.commit_template_language(self.repo().as_ref(), self.id_prefix_context())
|
.commit_template_language(self.repo().as_ref(), self.id_prefix_context())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates operation template language environment for this workspace.
|
||||||
|
pub fn operation_template_language(&self) -> OperationTemplateLanguage {
|
||||||
|
OperationTemplateLanguage::new(
|
||||||
|
self.repo().op_store().root_operation_id(),
|
||||||
|
Some(self.repo().op_id()),
|
||||||
|
self.env.operation_template_extensions(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Template for one-line summary of a commit.
|
/// Template for one-line summary of a commit.
|
||||||
pub fn commit_summary_template(&self) -> TemplateRenderer<'_, Commit> {
|
pub fn commit_summary_template(&self) -> TemplateRenderer<'_, Commit> {
|
||||||
self.parse_commit_template(&self.commit_summary_template_text)
|
self.parse_commit_template(&self.commit_summary_template_text)
|
||||||
|
|
|
@ -54,7 +54,6 @@ pub fn cmd_op_show(
|
||||||
let workspace_command = command.workspace_helper(ui)?;
|
let workspace_command = command.workspace_helper(ui)?;
|
||||||
let workspace_env = workspace_command.env();
|
let workspace_env = workspace_command.env();
|
||||||
let repo = workspace_command.repo();
|
let repo = workspace_command.repo();
|
||||||
let current_op_id = repo.operation().id();
|
|
||||||
let repo_loader = &repo.loader();
|
let repo_loader = &repo.loader();
|
||||||
let op = workspace_command.resolve_single_op(&args.operation)?;
|
let op = workspace_command.resolve_single_op(&args.operation)?;
|
||||||
let parents: Vec<_> = op.parents().try_collect()?;
|
let parents: Vec<_> = op.parents().try_collect()?;
|
||||||
|
@ -81,18 +80,13 @@ pub fn cmd_op_show(
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Should we make this customizable via clap arg?
|
// TODO: Should we make this customizable via clap arg?
|
||||||
let template;
|
let template = {
|
||||||
{
|
let language = workspace_command.operation_template_language();
|
||||||
let language = OperationTemplateLanguage::new(
|
|
||||||
repo_loader.op_store().root_operation_id(),
|
|
||||||
Some(current_op_id),
|
|
||||||
workspace_env.operation_template_extensions(),
|
|
||||||
);
|
|
||||||
let text = command.settings().config().get_string("templates.op_log")?;
|
let text = command.settings().config().get_string("templates.op_log")?;
|
||||||
template = workspace_command
|
workspace_command
|
||||||
.parse_template(&language, &text, OperationTemplateLanguage::wrap_operation)?
|
.parse_template(&language, &text, OperationTemplateLanguage::wrap_operation)?
|
||||||
.labeled("op_log");
|
.labeled("op_log")
|
||||||
}
|
};
|
||||||
|
|
||||||
ui.request_pager();
|
ui.request_pager();
|
||||||
let mut formatter = ui.stdout_formatter();
|
let mut formatter = ui.stdout_formatter();
|
||||||
|
|
Loading…
Reference in a new issue