From 3159d213c26b2284ace004ee8dbf722b6a46b7b5 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 22 Apr 2020 13:28:49 +0000 Subject: Don't use author date as email date This can be months in the past, and means people who sort their messages by date won't see commits. Ideally, we'd set this to the time of the push, but since that information isn't exposed, the best we can do is the time when we saw it. Author and committer dates are now both included in the message header. --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 23 ++++++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71b2e02..21b3539 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,6 +507,7 @@ dependencies = [ name = "pushmail" version = "0.1.0" dependencies = [ + "chrono", "clap", "failure", "graphql_client", diff --git a/Cargo.toml b/Cargo.toml index 900838a..2f8740e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,3 +54,4 @@ failure = "0.1.6" isahc = { version = "0.8.2", features = ["json"] } libc = "0.2.68" clap = "2.33.0" +chrono = "0.4.11" diff --git a/src/main.rs b/src/main.rs index e2587f8..4120c0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,7 @@ mod util; +use chrono::prelude::*; use clap::clap_app; use failure::{err_msg, format_err, Error}; use isahc::prelude::*; @@ -151,7 +152,7 @@ impl> Git { argv.extend_from_slice(&c_global_args); argv.push(b"show\0" as *const _); argv.push(b"--no-patch\0" as *const _); - argv.push(b"--format=Committer: %cn <%ce>\0" as *const _); + argv.push(b"--format=Date: %aD%nCommit: %cn <%ce>%nCommitDate: %cD\0" as *const _); argv.push(range.as_ptr()); argv.push(null()); @@ -380,6 +381,7 @@ impl<'a> Run<'a> { for line in patch { let line = line?; + let mut write = true; let new_state = match (state, line.as_slice()) { (Header, b"") => MessageHeader, @@ -390,6 +392,19 @@ impl<'a> Run<'a> { }; match (state, new_state) { + (Header, Header) => { + if line + .iter() + .map(u8::to_ascii_lowercase) + .take(5) + .collect::>() + == b"date:" + { + write!(sendmail_in, "Date: {}\n", Local::now().to_rfc2822())?; + write = false; + } + } + (MessageHeader, Message) => { self.git .git_print_user_info(sendmail_in, OsStr::new(commit))?; @@ -402,8 +417,10 @@ impl<'a> Run<'a> { _ => {} } - sendmail_in.write_all(&line)?; - sendmail_in.write_all(b"\n")?; + if write { + sendmail_in.write_all(&line)?; + sendmail_in.write_all(b"\n")?; + } state = new_state; } -- cgit 1.4.1