From 13ccd9276682fb2d4259ebce17a96e5c34680e40 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 1 Dec 2024 19:01:26 +0900 Subject: [PATCH] settings: do not store "debug.randomness-seed" in stringified form While this is a debug option, it doesn't make sense to store an integer value as a string. We can parse the environment variable instead. The variable is temporarily parsed into i64 because i64 is the integer type of TOML. toml_edit::Value doesn't implement any other integer conversion functions. --- cli/src/config.rs | 2 +- lib/src/settings.rs | 9 +-------- lib/testutils/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cli/src/config.rs b/cli/src/config.rs index ed112596a..42eb17924 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -411,7 +411,7 @@ fn env_overrides() -> config::Config { .set_override("debug.commit-timestamp", value) .unwrap(); } - if let Ok(value) = env::var("JJ_RANDOMNESS_SEED") { + if let Ok(Ok(value)) = env::var("JJ_RANDOMNESS_SEED").map(|s| s.parse::()) { builder = builder .set_override("debug.randomness-seed", value) .unwrap(); diff --git a/lib/src/settings.rs b/lib/src/settings.rs index c94d36320..702aa0849 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -132,17 +132,10 @@ fn get_timestamp_config(config: &StackedConfig, key: &'static str) -> Option Option { - config - .get::("debug.randomness-seed") - .ok() - .and_then(|str| str.parse().ok()) -} - impl UserSettings { pub fn from_config(config: StackedConfig) -> Self { let timestamp = get_timestamp_config(&config, "debug.commit-timestamp"); - let rng_seed = get_rng_seed_config(&config); + let rng_seed = config.get::("debug.randomness-seed").ok(); UserSettings { config, timestamp, diff --git a/lib/testutils/src/lib.rs b/lib/testutils/src/lib.rs index 9cdfb1ecb..c05e5405d 100644 --- a/lib/testutils/src/lib.rs +++ b/lib/testutils/src/lib.rs @@ -112,7 +112,7 @@ pub fn base_user_config() -> StackedConfig { user.email = "test.user@example.com" operation.username = "test-username" operation.hostname = "host.example.com" - debug.randomness-seed = "42" + debug.randomness-seed = 42 "#; let mut config = StackedConfig::empty(); config.add_layer(ConfigLayer::parse(ConfigSource::User, config_text).unwrap());