Add cutoff time
This commit is contained in:
parent
5c96beea07
commit
9fda734c7b
1 changed files with 13 additions and 1 deletions
14
src/main.rs
14
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<Oid, Oid>,
|
||||
unrewritten: HashSet<Oid>,
|
||||
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,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue