From f239b1e8f0e74423c11e1f7cebdb2b522110166c Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 21 Nov 2024 22:59:16 +0900 Subject: [PATCH] settings: pass around &UserSettings instead of &config::Config consistently Ui::with_config() is unchanged because I'm not sure if UserSettings should be constructed earlier. I assume UserSettings will hold an immutable copy of LayerdConfigs object, whereas Ui has to be initialized before all config layers get loaded. --- cli/src/cli_util.rs | 6 +++--- cli/src/commands/fix.rs | 6 ++++-- lib/src/fsmonitor.rs | 10 +++++----- lib/src/settings.rs | 14 ++++++++------ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 66d1462b8..f219c98fd 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -658,10 +658,10 @@ struct AdvanceBookmarksSettings { } impl AdvanceBookmarksSettings { - fn from_config(config: &config::Config) -> Result { + fn from_settings(settings: &UserSettings) -> Result { let get_setting = |setting_key| { let setting = format!("experimental-advance-branches.{setting_key}"); - match config.get::>(&setting).optional()? { + match settings.config().get::>(&setting).optional()? { Some(patterns) => patterns .into_iter() .map(|s| { @@ -2180,7 +2180,7 @@ Then run `jj squash` to move the resolution into the conflicted commit."#, &self, from: impl IntoIterator, ) -> Result, CommandError> { - let ab_settings = AdvanceBookmarksSettings::from_config(self.settings().config())?; + let ab_settings = AdvanceBookmarksSettings::from_settings(self.settings())?; if !ab_settings.feature_enabled() { // Return early if we know that there's no work to do. return Ok(Vec::new()); diff --git a/cli/src/commands/fix.rs b/cli/src/commands/fix.rs index 71fabc829..57cba17eb 100644 --- a/cli/src/commands/fix.rs +++ b/cli/src/commands/fix.rs @@ -38,6 +38,7 @@ use jj_lib::repo_path::RepoPathBuf; use jj_lib::repo_path::RepoPathUiConverter; use jj_lib::revset::RevsetExpression; use jj_lib::revset::RevsetIteratorExt; +use jj_lib::settings::UserSettings; use jj_lib::store::Store; use jj_lib::tree::Tree; use pollster::FutureExt; @@ -144,7 +145,7 @@ pub(crate) fn cmd_fix( args: &FixArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let tools_config = get_tools_config(ui, command.settings().config())?; + let tools_config = get_tools_config(ui, command.settings())?; let root_commits: Vec = if args.source.is_empty() { let revs = command.settings().config().get_string("revsets.fix")?; workspace_command.parse_revset(ui, &RevisionArg::from(revs))? @@ -445,7 +446,8 @@ struct RawToolConfig { /// Fails if any of the commands or patterns are obviously unusable, but does /// not check for issues that might still occur later like missing executables. /// This is a place where we could fail earlier in some cases, though. -fn get_tools_config(ui: &mut Ui, config: &config::Config) -> Result { +fn get_tools_config(ui: &mut Ui, settings: &UserSettings) -> Result { + let config = settings.config(); let mut tools_config = ToolsConfig { tools: Vec::new() }; // TODO: Remove this block of code and associated documentation after at least // one release where the feature is marked deprecated. diff --git a/lib/src/fsmonitor.rs b/lib/src/fsmonitor.rs index 1cf4317b9..bc197848a 100644 --- a/lib/src/fsmonitor.rs +++ b/lib/src/fsmonitor.rs @@ -24,10 +24,9 @@ use std::path::PathBuf; -use config::Config; - use crate::config::ConfigError; use crate::settings::ConfigResultExt; +use crate::settings::UserSettings; /// Config for Watchman filesystem monitor (). #[derive(Default, Eq, PartialEq, Clone, Debug)] @@ -59,11 +58,12 @@ pub enum FsmonitorSettings { impl FsmonitorSettings { /// Creates an `FsmonitorSettings` from a `config`. - pub fn from_config(config: &Config) -> Result { - match config.get_string("core.fsmonitor") { + pub fn from_settings(settings: &UserSettings) -> Result { + match settings.config().get_string("core.fsmonitor") { Ok(s) => match s.as_str() { "watchman" => Ok(Self::Watchman(WatchmanConfig { - register_trigger: config + register_trigger: settings + .config() .get_bool("core.watchman.register_snapshot_trigger") .optional()? .unwrap_or_default(), diff --git a/lib/src/settings.rs b/lib/src/settings.rs index dab6ec1e5..7c4dbffa5 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -50,12 +50,14 @@ pub struct GitSettings { } impl GitSettings { - pub fn from_config(config: &config::Config) -> Self { - let auto_local_bookmark = config + pub fn from_settings(settings: &UserSettings) -> Self { + let auto_local_bookmark = settings + .config() .get_bool("git.auto-local-bookmark") - .or_else(|_| config.get_bool("git.auto-local-branch")) + .or_else(|_| settings.config().get_bool("git.auto-local-branch")) .unwrap_or(false); - let abandon_unreachable_commits = config + let abandon_unreachable_commits = settings + .config() .get_bool("git.abandon-unreachable-commits") .unwrap_or(true); GitSettings { @@ -169,7 +171,7 @@ impl UserSettings { } pub fn fsmonitor_settings(&self) -> Result { - FsmonitorSettings::from_config(&self.config) + FsmonitorSettings::from_settings(self) } // Must not be changed to avoid git pushing older commits with no set email @@ -236,7 +238,7 @@ impl UserSettings { } pub fn git_settings(&self) -> GitSettings { - GitSettings::from_config(&self.config) + GitSettings::from_settings(self) } pub fn max_new_file_size(&self) -> Result {