fix: completely ignore method if signing is enabled
This commit is contained in:
parent
fae067bd5d
commit
fae0a19576
72
src/main.rs
72
src/main.rs
|
@ -1,6 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
use std::io::{ErrorKind, Write};
|
||||
use std::mem::MaybeUninit;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicUsize, Ordering};
|
||||
|
@ -378,6 +379,10 @@ fn main() -> Result<()> {
|
|||
seq_key = Some(unlock_key_file(path, true, false).context("could not get keypair")?.0);
|
||||
}
|
||||
|
||||
if (key_id.is_some() || seq_key.is_some()) && args.method.is_some() {
|
||||
eprintln!("warn: method specified will be ignored: commit signing is enabled (try with --no-sign)");
|
||||
}
|
||||
|
||||
// first open the repo and find the commit pointed to by HEAD
|
||||
let repo = Repository::open(".")
|
||||
.context("no git repository in this directory")?;
|
||||
|
@ -491,6 +496,7 @@ fn main() -> Result<()> {
|
|||
None => None,
|
||||
};
|
||||
|
||||
let signing = gpg.is_some() || seq_key.is_some();
|
||||
let mut sha1 = Sha1::default();
|
||||
let mut buffer = itoa::Buffer::new();
|
||||
let mut count_buffer = itoa::Buffer::new();
|
||||
|
@ -498,10 +504,10 @@ fn main() -> Result<()> {
|
|||
let mut random_hex = [0; 32];
|
||||
let mut first = true;
|
||||
while !found.load(Ordering::SeqCst) {
|
||||
let append = if gpg.is_some() || seq_key.is_some() {
|
||||
None
|
||||
} else {
|
||||
match method {
|
||||
let mut append = None;
|
||||
let mut header = MaybeUninit::uninit();
|
||||
if !signing {
|
||||
append = match method {
|
||||
Method::Random => {
|
||||
rand::thread_rng().fill(&mut random_bytes);
|
||||
data_encoding::HEXLOWER.encode_mut(&random_bytes, &mut random_hex);
|
||||
|
@ -516,42 +522,44 @@ fn main() -> Result<()> {
|
|||
Some(Cow::from(count_buffer.format(count)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
||||
if matches!(method, Method::Increment | Method::Decrement) {
|
||||
let timestamp = match method {
|
||||
Method::Decrement => timestamp.fetch_sub(1, Ordering::SeqCst) - 1,
|
||||
Method::Increment => timestamp.fetch_add(1, Ordering::SeqCst) + 1,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
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) {
|
||||
let timestamp = match method {
|
||||
Method::Decrement => timestamp.fetch_sub(1, Ordering::SeqCst) - 1,
|
||||
Method::Increment => timestamp.fetch_add(1, Ordering::SeqCst) + 1,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
header_lines[author_idx] = author_parts.join(" ");
|
||||
header_lines[committer_idx] = committer_parts.join(" ");
|
||||
}
|
||||
author_parts[author_len - 2] = buffer.format(timestamp).to_owned();
|
||||
committer_parts[committer_len - 2] = buffer.format(timestamp).to_owned();
|
||||
|
||||
if method == Method::Header {
|
||||
let count = counter.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
if first {
|
||||
header_lines.insert(committer_idx + 1, String::with_capacity(16));
|
||||
first = false;
|
||||
header_lines[author_idx] = author_parts.join(" ");
|
||||
header_lines[committer_idx] = committer_parts.join(" ");
|
||||
}
|
||||
|
||||
let line = &mut header_lines[committer_idx + 1];
|
||||
line.clear();
|
||||
line.push_str("xvain ");
|
||||
line.push_str(buffer.format(count));
|
||||
if method == Method::Header {
|
||||
let count = counter.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
if first {
|
||||
header_lines.insert(committer_idx + 1, String::with_capacity(16));
|
||||
first = false;
|
||||
}
|
||||
|
||||
let line = &mut header_lines[committer_idx + 1];
|
||||
line.clear();
|
||||
line.push_str("xvain ");
|
||||
line.push_str(buffer.format(count));
|
||||
}
|
||||
|
||||
header.write(match method {
|
||||
Method::Counter | Method::Random => Cow::from(&stripped_header),
|
||||
_ => Cow::from(header_lines.join("\n")),
|
||||
});
|
||||
} else {
|
||||
header.write(Cow::from(&stripped_header));
|
||||
}
|
||||
|
||||
let mut header = match method {
|
||||
// counter and random don't mutate the header, so don't
|
||||
// allocate for it
|
||||
Method::Counter | Method::Random => Cow::from(&stripped_header),
|
||||
_ => Cow::from(header_lines.join("\n")),
|
||||
};
|
||||
let mut header = unsafe { header.assume_init() };
|
||||
|
||||
// NOTE: don't need to handle append here, since we'll never be
|
||||
// both appending *and* signing
|
||||
|
|
Loading…
Reference in New Issue