Skip to content

Commit

Permalink
settings: do not store "debug.randomness-seed" in stringified form
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuja committed Dec 3, 2024
1 parent 3890e42 commit 13ccd92
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 1 addition & 8 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn base_user_config() -> StackedConfig {
user.email = "[email protected]"
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());
Expand Down

0 comments on commit 13ccd92

Please sign in to comment.