Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templater: remove unused context parameter from Template<C> #3355

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ use crate::git_util::{
};
use crate::merge_tools::{DiffEditor, MergeEditor, MergeToolConfigError};
use crate::operation_templater::OperationTemplateLanguageExtension;
use crate::template_builder::{RootTemplate, TemplateLanguage};
use crate::template_builder::TemplateLanguage;
use crate::template_parser::TemplateAliasesMap;
use crate::templater::{PropertyPlaceholder, Template};
use crate::templater::{PropertyPlaceholder, TemplateRenderer};
use crate::ui::{ColorChoice, Ui};
use crate::{revset_util, template_builder, text_util};

Expand Down Expand Up @@ -251,7 +251,7 @@ impl CommandHelper {
language: &L,
template_text: &str,
wrap_self: impl Fn(PropertyPlaceholder<C>) -> L::Property,
) -> Result<RootTemplate<'a, C>, CommandError> {
) -> Result<TemplateRenderer<'a, C>, CommandError> {
let aliases = self.load_template_aliases(ui)?;
Ok(template_builder::parse(
language,
Expand Down Expand Up @@ -915,7 +915,7 @@ It resolved to these revisions:
language: &L,
template_text: &str,
wrap_self: impl Fn(PropertyPlaceholder<C>) -> L::Property,
) -> Result<RootTemplate<'a, C>, CommandError> {
) -> Result<TemplateRenderer<'a, C>, CommandError> {
let aliases = &self.template_aliases_map;
Ok(template_builder::parse(
language,
Expand All @@ -929,7 +929,7 @@ It resolved to these revisions:
pub fn parse_commit_template(
&self,
template_text: &str,
) -> Result<RootTemplate<'_, Commit>, CommandError> {
) -> Result<TemplateRenderer<'_, Commit>, CommandError> {
let language = self.commit_template_language()?;
self.parse_template(
&language,
Expand All @@ -950,7 +950,7 @@ It resolved to these revisions:
}

/// Template for one-line summary of a commit.
pub fn commit_summary_template(&self) -> RootTemplate<'_, Commit> {
pub fn commit_summary_template(&self) -> TemplateRenderer<'_, Commit> {
self.parse_commit_template(&self.commit_summary_template_text)
.expect("parse error should be confined by WorkspaceCommandHelper::new()")
}
Expand Down Expand Up @@ -2348,7 +2348,7 @@ pub fn parse_args(
Ok((matches, args))
}

pub fn format_template<T>(ui: &Ui, arg: &T, template: &dyn Template<T>) -> String {
pub fn format_template<C: Clone>(ui: &Ui, arg: &C, template: &TemplateRenderer<C>) -> String {
let mut output = vec![];
template
.format(arg, ui.new_formatter(&mut output).as_mut())
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use tracing::instrument;

use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::CommandError;
use crate::templater::Template as _;
use crate::ui::Ui;

/// Abandon a revision
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::cli_util::{
};
use crate::command_error::{user_error, user_error_with_hint, CommandError};
use crate::formatter::Formatter;
use crate::templater::Template as _;
use crate::ui::Ui;

/// Manage branches.
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::command_error::{config_error, user_error, CommandError};
use crate::config::{AnnotatedValue, ConfigSource};
use crate::generic_templater::GenericTemplateLanguage;
use crate::template_builder::TemplateLanguage as _;
use crate::templater::{Template as _, TemplatePropertyExt as _};
use crate::templater::TemplatePropertyExt as _;
use crate::ui::Ui;

#[derive(clap::Args, Clone, Debug)]
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::command_error::CommandError;
use crate::commit_templater::CommitTemplateLanguage;
use crate::diff_util::{self, DiffFormatArgs};
use crate::graphlog::{get_graphlog, Edge};
use crate::templater::Template as _;
use crate::ui::Ui;

/// Show revision history
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use jj_lib::revset::{RevsetExpression, RevsetIteratorExt};

use crate::cli_util::{short_commit_hash, CommandHelper, WorkspaceCommandHelper};
use crate::command_error::{user_error, CommandError};
use crate::templater::Template as _;
use crate::ui::Ui;

/// Move the working-copy commit to the child revision
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::commit_templater::CommitTemplateLanguage;
use crate::diff_util::{self, DiffFormat, DiffFormatArgs};
use crate::formatter::Formatter;
use crate::graphlog::{get_graphlog, Edge};
use crate::templater::Template as _;
use crate::ui::Ui;

/// Show how a change has evolved
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::cli_util::{format_template, short_operation_hash, CommandHelper, LogC
use crate::command_error::{user_error, user_error_with_hint, CommandError};
use crate::graphlog::{get_graphlog, Edge};
use crate::operation_templater::OperationTemplateLanguage;
use crate::templater::Template as _;
use crate::ui::Ui;

/// Commands for working with the operation log
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use tracing::instrument;
use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::CommandError;
use crate::diff_util::{self, DiffFormatArgs};
use crate::templater::Template as _;
use crate::ui::Ui;

/// Show commit description and changes in a revision
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use super::resolve;
use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::diff_util;
use crate::templater::Template as _;
use crate::ui::Ui;

/// Show high-level repo status
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::cli_util::{
RevisionArg, WorkingCopyFreshness, WorkspaceCommandHelper,
};
use crate::command_error::{internal_error_with_message, user_error, CommandError};
use crate::templater::Template as _;
use crate::ui::Ui;

/// Commands for working with workspaces
Expand Down
20 changes: 10 additions & 10 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'repo> IntoTemplateProperty<'repo> for CommitTemplatePropertyKind<'repo> {
}
}

fn try_into_template(self) -> Option<Box<dyn Template<()> + 'repo>> {
fn try_into_template(self) -> Option<Box<dyn Template + 'repo>> {
match self {
CommitTemplatePropertyKind::Core(property) => property.try_into_template(),
CommitTemplatePropertyKind::Commit(_) => None,
Expand Down Expand Up @@ -651,8 +651,8 @@ impl RefName {
}
}

impl Template<()> for RefName {
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
impl Template for RefName {
fn format(&self, formatter: &mut dyn Formatter) -> io::Result<()> {
write!(formatter.labeled("name"), "{}", self.name)?;
if let Some(remote) = &self.remote {
write!(formatter, "@")?;
Expand All @@ -669,9 +669,9 @@ impl Template<()> for RefName {
}
}

impl Template<()> for Vec<RefName> {
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
templater::format_joined(&(), formatter, self, " ")
impl Template for Vec<RefName> {
fn format(&self, formatter: &mut dyn Formatter) -> io::Result<()> {
templater::format_joined(formatter, self, " ")
}
}

Expand Down Expand Up @@ -823,8 +823,8 @@ impl CommitOrChangeId {
}
}

impl Template<()> for CommitOrChangeId {
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
impl Template for CommitOrChangeId {
fn format(&self, formatter: &mut dyn Formatter) -> io::Result<()> {
write!(formatter, "{}", self.hex())
}
}
Expand Down Expand Up @@ -865,8 +865,8 @@ pub struct ShortestIdPrefix {
pub rest: String,
}

impl Template<()> for ShortestIdPrefix {
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
impl Template for ShortestIdPrefix {
fn format(&self, formatter: &mut dyn Formatter) -> io::Result<()> {
write!(formatter.labeled("prefix"), "{}", self.prefix)?;
write!(formatter.labeled("rest"), "{}", self.rest)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion cli/src/generic_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a, C: 'a> IntoTemplateProperty<'a> for GenericTemplatePropertyKind<'a, C>
}
}

fn try_into_template(self) -> Option<Box<dyn Template<()> + 'a>> {
fn try_into_template(self) -> Option<Box<dyn Template + 'a>> {
match self {
GenericTemplatePropertyKind::Core(property) => property.try_into_template(),
GenericTemplatePropertyKind::Self_(_) => None,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/operation_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl IntoTemplateProperty<'static> for OperationTemplatePropertyKind {
}
}

fn try_into_template(self) -> Option<Box<dyn Template<()>>> {
fn try_into_template(self) -> Option<Box<dyn Template>> {
match self {
OperationTemplatePropertyKind::Core(property) => property.try_into_template(),
OperationTemplatePropertyKind::Operation(_) => None,
Expand Down Expand Up @@ -275,8 +275,8 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap<Operation> {
map
}

impl Template<()> for OperationId {
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
impl Template for OperationId {
fn format(&self, formatter: &mut dyn Formatter) -> io::Result<()> {
write!(formatter, "{}", self.hex())
}
}
Expand Down
Loading