From e5361c6cc011f5301dad8e0e9461f27bcc0863a3 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 24 Dec 2024 10:53:58 +0900 Subject: [PATCH] fsmonitor: move default settings to config/misc.toml --- lib/src/config/misc.toml | 6 ++++++ lib/src/fsmonitor.rs | 39 ++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/src/config/misc.toml b/lib/src/config/misc.toml index 315a675245..d432be25f9 100644 --- a/lib/src/config/misc.toml +++ b/lib/src/config/misc.toml @@ -1,3 +1,9 @@ +[core] +fsmonitor = "none" + +[core.watchman] +register_snapshot_trigger = false + [debug] # commit-timestamp = # operation-timestamp = diff --git a/lib/src/fsmonitor.rs b/lib/src/fsmonitor.rs index a65c2f9440..36221df5a2 100644 --- a/lib/src/fsmonitor.rs +++ b/lib/src/fsmonitor.rs @@ -25,7 +25,6 @@ use std::path::PathBuf; use crate::config::ConfigGetError; -use crate::config::ConfigGetResultExt as _; use crate::settings::UserSettings; /// Config for Watchman filesystem monitor (). @@ -59,28 +58,22 @@ impl FsmonitorSettings { /// Creates an `FsmonitorSettings` from a `config`. pub fn from_settings(settings: &UserSettings) -> Result { let name = "core.fsmonitor"; - match settings.get_string(name) { - Ok(s) => match s.as_str() { - "watchman" => Ok(Self::Watchman(WatchmanConfig { - register_trigger: settings - .get_bool("core.watchman.register_snapshot_trigger") - .optional()? - .unwrap_or_default(), - })), - "test" => Err(ConfigGetError::Type { - name: name.to_owned(), - error: "Cannot use test fsmonitor in real repository".into(), - source_path: None, - }), - "none" => Ok(Self::None), - other => Err(ConfigGetError::Type { - name: name.to_owned(), - error: format!("Unknown fsmonitor kind: {other}").into(), - source_path: None, - }), - }, - Err(ConfigGetError::NotFound { .. }) => Ok(Self::None), - Err(err) => Err(err), + match settings.get_string(name)?.as_ref() { + "watchman" => Ok(Self::Watchman(WatchmanConfig { + // TODO: rename to "register-snapshot-trigger" for consistency? + register_trigger: settings.get_bool("core.watchman.register_snapshot_trigger")?, + })), + "test" => Err(ConfigGetError::Type { + name: name.to_owned(), + error: "Cannot use test fsmonitor in real repository".into(), + source_path: None, + }), + "none" => Ok(Self::None), + other => Err(ConfigGetError::Type { + name: name.to_owned(), + error: format!("Unknown fsmonitor kind: {other}").into(), + source_path: None, + }), } } }