Skip to content

Commit

Permalink
fsmonitor: move default settings to config/misc.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Dec 25, 2024
1 parent 9b60a9d commit e5361c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
6 changes: 6 additions & 0 deletions lib/src/config/misc.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[core]
fsmonitor = "none"

[core.watchman]
register_snapshot_trigger = false

[debug]
# commit-timestamp = <now>
# operation-timestamp = <now>
Expand Down
39 changes: 16 additions & 23 deletions lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<https://facebook.github.io/watchman/>).
Expand Down Expand Up @@ -59,28 +58,22 @@ impl FsmonitorSettings {
/// Creates an `FsmonitorSettings` from a `config`.
pub fn from_settings(settings: &UserSettings) -> Result<FsmonitorSettings, ConfigGetError> {
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,
}),
}
}
}
Expand Down

0 comments on commit e5361c6

Please sign in to comment.