From 8fc06690d200323cc726e235a39414a951b3ccb0 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 17 Dec 2024 20:23:19 +0900 Subject: [PATCH] settings: cache "debug.operation-timestamp" value This will make error handling easier in later commit. --- lib/src/settings.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 2002e7ac1..afdf09770 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -42,7 +42,8 @@ use crate::signing::SignBehavior; #[derive(Debug, Clone)] pub struct UserSettings { config: StackedConfig, - timestamp: Option, + commit_timestamp: Option, + operation_timestamp: Option, rng: Arc, } @@ -136,11 +137,13 @@ fn get_timestamp_config(config: &StackedConfig, key: &'static str) -> Option Self { - let timestamp = get_timestamp_config(&config, "debug.commit-timestamp"); + let commit_timestamp = get_timestamp_config(&config, "debug.commit-timestamp"); + let operation_timestamp = get_timestamp_config(&config, "debug.operation-timestamp"); let rng_seed = config.get::("debug.randomness-seed").ok(); UserSettings { config, - timestamp, + commit_timestamp, + operation_timestamp, rng: Arc::new(JJRng::new(rng_seed)), } } @@ -176,11 +179,11 @@ impl UserSettings { pub const USER_EMAIL_PLACEHOLDER: &'static str = "(no email configured)"; pub fn commit_timestamp(&self) -> Option { - self.timestamp + self.commit_timestamp } pub fn operation_timestamp(&self) -> Option { - get_timestamp_config(&self.config, "debug.operation-timestamp") + self.operation_timestamp } pub fn operation_hostname(&self) -> String { @@ -212,7 +215,7 @@ impl UserSettings { } pub fn signature(&self) -> Signature { - let timestamp = self.timestamp.unwrap_or_else(Timestamp::now); + let timestamp = self.commit_timestamp.unwrap_or_else(Timestamp::now); Signature { name: self.user_name(), email: self.user_email(),