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.
This commit is contained in:
Yuya Nishihara 2024-12-01 19:01:26 +09:00
parent 3890e426e5
commit 13ccd92766
3 changed files with 3 additions and 10 deletions

View file

@ -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::<i64>()) {
builder = builder
.set_override("debug.randomness-seed", value)
.unwrap();

View file

@ -132,17 +132,10 @@ fn get_timestamp_config(config: &StackedConfig, key: &'static str) -> Option<Tim
}
}
fn get_rng_seed_config(config: &StackedConfig) -> Option<u64> {
config
.get::<String>("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::<u64>("debug.randomness-seed").ok();
UserSettings {
config,
timestamp,

View file

@ -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());