cli: replace committer email by author timestamp in log template

I've often missed not having the timestamp there. It gets too long
with both email and timestamp for both author and committer, so I
removed the committer email to make room for the author timestamp.
This commit is contained in:
Martin von Zweigbergk 2021-04-26 14:54:35 -07:00
parent a04e145f06
commit ba4ac44719
3 changed files with 21 additions and 3 deletions

View File

@ -979,8 +979,8 @@ fn log_template(settings: &UserSettings) -> String {
label(if(open, "open"), label(if(open, "open"),
"commit: " commit_id "\n" "commit: " commit_id "\n"
"change: " change_id "\n" "change: " change_id "\n"
"author: " author.name() " <" author.email() ">\n" "author: " author.name() " <" author.email() "> " author.timestamp() "\n"
"committer: " committer.name() " <" committer.email() ">\n" "committer: " committer.name() " <" committer.email() "> " committer.timestamp() "\n"
"git refs: " git_refs "\n" "git refs: " git_refs "\n"
"open: " open "\n" "open: " open "\n"
"pruned: " pruned "\n" "pruned: " pruned "\n"
@ -1005,7 +1005,7 @@ fn graph_log_template(settings: &UserSettings) -> String {
commit_id.short() commit_id.short()
" " change_id.short() " " change_id.short()
" " author.email() " " author.email()
" " committer.email() " " label("timestamp", author.timestamp())
" " git_refs " " git_refs
if(pruned, label("pruned", " pruned")) if(pruned, label("pruned", " pruned"))
if(obsolete, label("obsolete", " obsolete")) if(obsolete, label("obsolete", " obsolete"))

View File

@ -85,7 +85,9 @@ fn config_colors(user_settings: &UserSettings) -> HashMap<String, String> {
result.insert(String::from("commit_id open"), String::from("green")); result.insert(String::from("commit_id open"), String::from("green"));
result.insert(String::from("change_id"), String::from("magenta")); result.insert(String::from("change_id"), String::from("magenta"));
result.insert(String::from("author"), String::from("yellow")); result.insert(String::from("author"), String::from("yellow"));
result.insert(String::from("author timestamp"), String::from("cyan"));
result.insert(String::from("committer"), String::from("yellow")); result.insert(String::from("committer"), String::from("yellow"));
result.insert(String::from("committer timestamp"), String::from("cyan"));
result.insert(String::from("git_refs"), String::from("magenta")); result.insert(String::from("git_refs"), String::from("magenta"));
result.insert(String::from("pruned"), String::from("red")); result.insert(String::from("pruned"), String::from("red"));
result.insert(String::from("obsolete"), String::from("red")); result.insert(String::from("obsolete"), String::from("red"));

View File

@ -14,6 +14,7 @@
extern crate pest; extern crate pest;
use chrono::{FixedOffset, TimeZone, Utc};
use jujube_lib::commit::Commit; use jujube_lib::commit::Commit;
use jujube_lib::repo::RepoRef; use jujube_lib::repo::RepoRef;
use jujube_lib::store::{CommitId, Signature}; use jujube_lib::store::{CommitId, Signature};
@ -93,6 +94,20 @@ impl TemplateProperty<Signature, String> for SignatureEmail {
} }
} }
struct SignatureTimestamp;
impl TemplateProperty<Signature, String> for SignatureTimestamp {
fn extract(&self, context: &Signature) -> String {
let utc = Utc
.timestamp(
context.timestamp.timestamp.0 as i64 / 1000,
(context.timestamp.timestamp.0 % 1000) as u32 * 1000000,
)
.with_timezone(&FixedOffset::east(context.timestamp.tz_offset * 60));
utc.format("%Y-%m-%d %H:%M:%S.%3f %:z").to_string()
}
}
fn parse_method_chain<'a, I: 'a>( fn parse_method_chain<'a, I: 'a>(
pair: Pair<Rule>, pair: Pair<Rule>,
input_property: Property<'a, I>, input_property: Property<'a, I>,
@ -177,6 +192,7 @@ fn parse_signature_method<'a>(method: Pair<Rule>) -> Property<'a, Signature> {
// `author % (name "<" email ">")`)? // `author % (name "<" email ">")`)?
"name" => Property::String(Box::new(SignatureName)), "name" => Property::String(Box::new(SignatureName)),
"email" => Property::String(Box::new(SignatureEmail)), "email" => Property::String(Box::new(SignatureEmail)),
"timestamp" => Property::String(Box::new(SignatureTimestamp)),
name => panic!("no such commit id method: {}", name), name => panic!("no such commit id method: {}", name),
}; };
let chain_method = inner.last().unwrap(); let chain_method = inner.last().unwrap();