diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-04-22 13:28:49 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-04-22 14:18:43 +0000 |
commit | 3159d213c26b2284ace004ee8dbf722b6a46b7b5 (patch) | |
tree | df83cb19ac227eaae644bf93f23443cf5a050be1 /src | |
parent | e6fc6d7329fc3565b93269d7f5bd361a0e048732 (diff) | |
download | pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar.gz pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar.bz2 pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar.lz pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar.xz pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.tar.zst pushmail-3159d213c26b2284ace004ee8dbf722b6a46b7b5.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 23 |
1 files changed, 20 insertions, 3 deletions
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<S: AsRef<OsStr>> Git<S> { 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::<Vec<_>>() + == 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; } |