about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-04-22 13:28:49 +0000
committerAlyssa Ross <hi@alyssa.is>2020-04-22 14:18:43 +0000
commit3159d213c26b2284ace004ee8dbf722b6a46b7b5 (patch)
treedf83cb19ac227eaae644bf93f23443cf5a050be1
parente6fc6d7329fc3565b93269d7f5bd361a0e048732 (diff)
downloadpushmail-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.
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs23
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<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;
         }