feat: add experimental header method

This commit is contained in:
Anna 2023-08-30 14:41:04 -04:00
parent fae049fbb0
commit fae094abf0
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 24 additions and 4 deletions

View File

@ -73,6 +73,10 @@ struct Cli {
///
/// - counter will append an increasing number to the commit message for
/// each attempt
///
/// - header will add an invalid git header line to the commit with an
/// incrementing counter (git ignores additional headers, but this may not
/// be compatible with future header changes)
#[arg(short, long, value_enum, default_value_t = Method::Counter)]
method: Method,
@ -91,6 +95,7 @@ enum Method {
Increment,
Random,
Counter,
Header,
}
fn main() -> Result<()> {
@ -264,6 +269,7 @@ fn main() -> Result<()> {
let mut sha1 = Sha1::default();
let mut buffer = itoa::Buffer::new();
let mut first = true;
loop {
if found.load(Ordering::SeqCst) {
break;
@ -296,11 +302,25 @@ fn main() -> Result<()> {
}
};
author_parts[author_len - 2] = buffer.format(timestamp).to_owned();
committer_parts[committer_len - 2] = buffer.format(timestamp).to_owned();
if matches!(method, Method::Increment | Method::Decrement) {
author_parts[author_len - 2] = buffer.format(timestamp).to_owned();
committer_parts[committer_len - 2] = buffer.format(timestamp).to_owned();
header_lines[author_idx] = author_parts.join(" ");
header_lines[committer_idx] = committer_parts.join(" ");
header_lines[author_idx] = author_parts.join(" ");
header_lines[committer_idx] = committer_parts.join(" ");
}
if method == Method::Header {
let count = counter.fetch_add(1, Ordering::SeqCst) + 1;
let line = format!("xvain {}", buffer.format(count));
if first {
header_lines.insert(committer_idx + 1, line);
} else {
header_lines[committer_idx + 1] = line;
}
first = false;
}
let mut header = header_lines.join("\n");