diff --git a/src/templater.rs b/src/templater.rs index 5c1e278cb..627700589 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -25,11 +25,36 @@ use jujutsu_lib::revset::RevsetExpression; use jujutsu_lib::rewrite::merge_commit_trees; use crate::formatter::Formatter; +use crate::time_util; pub trait Template { fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()>; } +impl Template<()> for Signature { + fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { + formatter.write_str(&self.name) + } +} + +impl Template<()> for String { + fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { + formatter.write_str(self) + } +} + +impl Template<()> for Timestamp { + fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { + formatter.write_str(&time_util::format_absolute_timestamp(self)) + } +} + +impl Template<()> for bool { + fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { + formatter.write_str(if *self { "true" } else { "false" }) + } +} + pub struct LiteralTemplate(pub String); impl Template for LiteralTemplate { @@ -411,6 +436,12 @@ impl CommitOrChangeId { } } +impl Template<()> for CommitOrChangeId { + fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { + formatter.write_str(&self.hex()) + } +} + fn highlight_shortest_prefix(id: &CommitOrChangeId, total_len: usize, repo: RepoRef) -> String { let prefix_len = repo .base_repo()