Compare commits

...

2 commits

Author SHA1 Message Date
puck 31902a9df3 Add lifetime comment 2024-05-02 18:27:14 +00:00
puck 9fda734c7b Add cutoff time 2024-05-02 18:27:14 +00:00

View file

@ -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<Oid, Oid>,
unrewritten: HashSet<Oid>,
cutoff_time: Time,
args: Args,
}
@ -42,10 +47,16 @@ 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;
let parent_ids: Vec<_> = commit.parent_ids().collect();
// This is to deal with lifetime weirdness.
drop(commit);
let mut new_parent_ids = Vec::new();
@ -195,11 +206,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,
};