From 47e6ceb5fa02d8651f38748049e7a6cf003501c4 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 22 Jan 2023 21:16:52 +0900 Subject: [PATCH] templater: display both name and email by author/committer keywords This is an example of labeled output of structured value types. I think "{name} <{email}>" is a good default formatting, but I should note that the signature also contains timestamp field. --- CHANGELOG.md | 3 +++ src/commands/mod.rs | 4 ++-- src/templater.rs | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb1c3cfd6..321aac55a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `jj log` prefixes commit descriptions with "(empty)" when they contain no change compared to their parents. +* The `author`/`committer` templates now display both name and email. Use + `author.name()`/`committer.name()` to extract the name. + ### New features * The default log format now uses the committer timestamp instead of the author diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 8f8f8e233..015c4d5d9 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1233,8 +1233,8 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(), r#" "Commit ID: " commit_id "\n" "Change ID: " change_id "\n" - "Author: " author " <" author.email() "> (" {author_timestamp_template} ")\n" - "Committer: " committer " <" committer.email() "> (" {committer_timestamp_template} ")\n" + "Author: " author " (" {author_timestamp_template} ")\n" + "Committer: " committer " (" {committer_timestamp_template} ")\n" "\n" description "\n""#, diff --git a/src/templater.rs b/src/templater.rs index 68aec5fad..4ca935310 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -33,7 +33,11 @@ pub trait Template { impl Template<()> for Signature { fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> { - formatter.write_str(&self.name) + write!(formatter, "{}", self.name)?; + write!(formatter, " <")?; + write!(formatter.labeled("email"), "{}", self.email)?; + write!(formatter, ">")?; + Ok(()) } }