about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs23
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;
         }