refactor: only get timestamp if necessary

This commit is contained in:
Anna 2023-08-30 21:38:45 -04:00
parent fae0549aa9
commit fae04bd975
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 7 additions and 11 deletions

View File

@ -209,7 +209,7 @@ fn unlock_key_file(path: &str, check_secrets: bool, return_password: bool) -> Re
Err(keyring::Error::NoEntry) => {}
Err(e) => {
eprintln!("warn: could not get saved password for key {}: {:#}", key_id, e);
},
}
}
}
@ -462,16 +462,6 @@ fn main() -> Result<()> {
break;
}
let timestamp = if gpg.is_some() || seq_key.is_some() {
timestamp.load(Ordering::SeqCst)
} else {
match method {
Method::Decrement => timestamp.fetch_sub(1, Ordering::SeqCst) - 1,
Method::Increment => timestamp.fetch_add(1, Ordering::SeqCst) + 1,
_ => timestamp.load(Ordering::SeqCst),
}
};
let append = if gpg.is_some() || seq_key.is_some() {
None
} else {
@ -490,6 +480,12 @@ fn main() -> Result<()> {
};
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,
_ => timestamp.load(Ordering::SeqCst),
};
author_parts[author_len - 2] = buffer.format(timestamp).to_owned();
committer_parts[committer_len - 2] = buffer.format(timestamp).to_owned();