ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: proxy parse_commit_template() through WorkspaceCommandHelper

I'll add an alias table there. Since this function borrows self, it can't
always be used in between mutable operations. For log-like commands, this
should just work fine.
This commit is contained in:
Yuya Nishihara 2023-02-12 18:06:48 +09:00
parent bc7a086192
commit 493cb83fd5
2 changed files with 15 additions and 15 deletions

View file

@ -60,6 +60,7 @@ use crate::config::{AnnotatedValue, CommandNameAndArgs, LayeredConfigs};
use crate::formatter::{Formatter, PlainTextFormatter}; use crate::formatter::{Formatter, PlainTextFormatter};
use crate::merge_tools::{ConflictResolveError, DiffEditError}; use crate::merge_tools::{ConflictResolveError, DiffEditError};
use crate::template_parser::{self, TemplateParseError}; use crate::template_parser::{self, TemplateParseError};
use crate::templater::Template;
use crate::ui::{ColorChoice, Ui}; use crate::ui::{ColorChoice, Ui};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -795,6 +796,17 @@ impl WorkspaceCommandHelper {
} }
} }
pub fn parse_commit_template(
&self,
template_text: &str,
) -> Result<Box<dyn Template<Commit> + '_>, TemplateParseError> {
template_parser::parse_commit_template(
self.repo.as_repo_ref(),
self.workspace_id(),
template_text,
)
}
/// Returns one-line summary of the given `commit`. /// Returns one-line summary of the given `commit`.
pub fn format_commit_summary(&self, commit: &Commit) -> String { pub fn format_commit_summary(&self, commit: &Commit) -> String {
let mut output = Vec::new(); let mut output = Vec::new();

View file

@ -1296,11 +1296,7 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(),
if(description, description, {DESCRIPTION_PLACEHOLDER_TEMPLATE} "\n") if(description, description, {DESCRIPTION_PLACEHOLDER_TEMPLATE} "\n")
"\n""#, "\n""#,
); );
let template = crate::template_parser::parse_commit_template( let template = workspace_command.parse_commit_template(&template_string)?;
workspace_command.repo().as_repo_ref(),
workspace_command.workspace_id(),
&template_string,
)?;
ui.request_pager(); ui.request_pager();
let mut formatter = ui.stdout_formatter(); let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut(); let formatter = formatter.as_mut();
@ -1494,11 +1490,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
Some(value) => value.to_string(), Some(value) => value.to_string(),
None => log_template(command.settings()), None => log_template(command.settings()),
}; };
let template = crate::template_parser::parse_commit_template( let template = workspace_command.parse_commit_template(&template_string)?;
repo.as_repo_ref(),
workspace_id,
&template_string,
)?;
{ {
ui.request_pager(); ui.request_pager();
@ -1631,11 +1623,7 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result
Some(value) => value.to_string(), Some(value) => value.to_string(),
None => log_template(command.settings()), None => log_template(command.settings()),
}; };
let template = crate::template_parser::parse_commit_template( let template = workspace_command.parse_commit_template(&template_string)?;
workspace_command.repo().as_repo_ref(),
workspace_id,
&template_string,
)?;
ui.request_pager(); ui.request_pager();
let mut formatter = ui.stdout_formatter(); let mut formatter = ui.stdout_formatter();