From 493cb83fd58428ea3c39e9b7061d63c124b47c0d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 12 Feb 2023 18:06:48 +0900 Subject: [PATCH] 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. --- src/cli_util.rs | 12 ++++++++++++ src/commands/mod.rs | 18 +++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index b94634582..37bb43aa7 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -60,6 +60,7 @@ use crate::config::{AnnotatedValue, CommandNameAndArgs, LayeredConfigs}; use crate::formatter::{Formatter, PlainTextFormatter}; use crate::merge_tools::{ConflictResolveError, DiffEditError}; use crate::template_parser::{self, TemplateParseError}; +use crate::templater::Template; use crate::ui::{ColorChoice, Ui}; #[derive(Clone, Debug)] @@ -795,6 +796,17 @@ impl WorkspaceCommandHelper { } } + pub fn parse_commit_template( + &self, + template_text: &str, + ) -> Result + '_>, TemplateParseError> { + template_parser::parse_commit_template( + self.repo.as_repo_ref(), + self.workspace_id(), + template_text, + ) + } + /// Returns one-line summary of the given `commit`. pub fn format_commit_summary(&self, commit: &Commit) -> String { let mut output = Vec::new(); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index ebbda459b..87cea3ecb 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1296,11 +1296,7 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(), if(description, description, {DESCRIPTION_PLACEHOLDER_TEMPLATE} "\n") "\n""#, ); - let template = crate::template_parser::parse_commit_template( - workspace_command.repo().as_repo_ref(), - workspace_command.workspace_id(), - &template_string, - )?; + let template = workspace_command.parse_commit_template(&template_string)?; ui.request_pager(); let mut formatter = ui.stdout_formatter(); 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(), None => log_template(command.settings()), }; - let template = crate::template_parser::parse_commit_template( - repo.as_repo_ref(), - workspace_id, - &template_string, - )?; + let template = workspace_command.parse_commit_template(&template_string)?; { ui.request_pager(); @@ -1631,11 +1623,7 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result Some(value) => value.to_string(), None => log_template(command.settings()), }; - let template = crate::template_parser::parse_commit_template( - workspace_command.repo().as_repo_ref(), - workspace_id, - &template_string, - )?; + let template = workspace_command.parse_commit_template(&template_string)?; ui.request_pager(); let mut formatter = ui.stdout_formatter();