Compare commits
2 commits
5c96beea07
...
31902a9df3
Author | SHA1 | Date | |
---|---|---|---|
puck | 31902a9df3 | ||
puck | 9fda734c7b |
15
src/main.rs
15
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use git2::{Oid, Repository, Signature};
|
use git2::{Oid, Repository, Signature, Time};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
|
@ -21,12 +21,17 @@ struct Args {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// The author/committer email to replace the old one with.
|
/// The author/committer email to replace the old one with.
|
||||||
new_email: String,
|
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 {
|
struct State {
|
||||||
repo: git2::Repository,
|
repo: git2::Repository,
|
||||||
rewritten: HashMap<Oid, Oid>,
|
rewritten: HashMap<Oid, Oid>,
|
||||||
unrewritten: HashSet<Oid>,
|
unrewritten: HashSet<Oid>,
|
||||||
|
cutoff_time: Time,
|
||||||
args: Args,
|
args: Args,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +47,16 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut commit = self.repo.find_commit(oid).unwrap();
|
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.
|
// 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 rewrite_author = commit.author().email().unwrap() == &self.args.rewrite_email;
|
||||||
|
|
||||||
let parent_ids: Vec<_> = commit.parent_ids().collect();
|
let parent_ids: Vec<_> = commit.parent_ids().collect();
|
||||||
|
// This is to deal with lifetime weirdness.
|
||||||
drop(commit);
|
drop(commit);
|
||||||
|
|
||||||
let mut new_parent_ids = Vec::new();
|
let mut new_parent_ids = Vec::new();
|
||||||
|
@ -195,11 +206,13 @@ impl State {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let repo = args.repo.clone();
|
let repo = args.repo.clone();
|
||||||
|
let cutoff = Time::new(i64::from_str_radix(&args.cutoff, 10).unwrap(), 0);
|
||||||
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
repo: Repository::open_bare(repo).unwrap(),
|
repo: Repository::open_bare(repo).unwrap(),
|
||||||
rewritten: HashMap::new(),
|
rewritten: HashMap::new(),
|
||||||
unrewritten: HashSet::new(),
|
unrewritten: HashSet::new(),
|
||||||
|
cutoff_time: cutoff,
|
||||||
args,
|
args,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue