From 9fda734c7b7a8dbb244e6b98e77543cd05bb5423 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Thu, 2 May 2024 18:26:20 +0000 Subject: [PATCH] Add cutoff time --- src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9f33336..a787acb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use clap::Parser; -use git2::{Oid, Repository, Signature}; +use git2::{Oid, Repository, Signature, Time}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -21,12 +21,17 @@ struct Args { #[arg(short, long)] /// The author/committer email to replace the old one with. new_email: String, + + #[arg(short, long)] + /// A timestamp (in seconds since the epoch) at which point commits should be considered unchanged, even if it or its parents have aforementioned email. + cutoff: String, } struct State { repo: git2::Repository, rewritten: HashMap, unrewritten: HashSet, + cutoff_time: Time, args: Args, } @@ -42,6 +47,11 @@ impl State { } let mut commit = self.repo.find_commit(oid).unwrap(); + if commit.committer().when() < self.cutoff_time { + self.unrewritten.insert(oid); + return oid; + } + // If the email address matches, we will have to rewrite this commit either way, even if parent IDs match. let rewrite_author = commit.author().email().unwrap() == &self.args.rewrite_email; @@ -195,11 +205,13 @@ impl State { fn main() { let args = Args::parse(); let repo = args.repo.clone(); + let cutoff = Time::new(i64::from_str_radix(&args.cutoff, 10).unwrap(), 0); let mut state = State { repo: Repository::open_bare(repo).unwrap(), rewritten: HashMap::new(), unrewritten: HashSet::new(), + cutoff_time: cutoff, args, };