Skip to content

Commit

Permalink
Add background snapshotting info to debug watchman status.
Browse files Browse the repository at this point in the history
  • Loading branch information
fowles committed Jun 20, 2024
1 parent 397e96f commit c9b3d64
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
46 changes: 35 additions & 11 deletions cli/src/commands/debug/watchman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,52 @@ pub fn cmd_debug_watchman(
match subcommand {
WatchmanCommand::Status => {
// TODO(ilyagr): It would be nice to add colors here
match command.settings().fsmonitor_settings()? {
FsmonitorSettings::Watchman { .. } => {
writeln!(ui.stdout(), "Watchman is enabled via `core.fsmonitor`.")?
let config = match command.settings().fsmonitor_settings()? {
FsmonitorSettings::Watchman(config) => {
writeln!(ui.stdout(), "Watchman is enabled via `core.fsmonitor`.")?;
writeln!(
ui.stdout(),
r"Background snapshotting is {}. Use `core.watchman.register_snapshot_trigger` to control it.",
if config.register_trigger {
"enabled"
} else {
"disabled"
}
)?;
config
}
FsmonitorSettings::None => {
writeln!(
ui.stdout(),
r#"Watchman is disabled. Set `core.fsmonitor="watchman"` to enable."#
)?;
writeln!(
ui.stdout(),
"Attempting to contact the `watchman` CLI regardless..."
)?;
WatchmanConfig::default()
}
FsmonitorSettings::None => writeln!(
ui.stdout(),
"Watchman is disabled. Set `core.fsmonitor=\"watchman\"` to \
enable.\nAttempting to contact the `watchman` CLI regardless..."
)?,
other_fsmonitor => {
return Err(user_error(format!(
"This command does not support the currently enabled filesystem monitor: \
{other_fsmonitor:?}."
r"This command does not support the currently enabled filesystem monitor: {other_fsmonitor:?}."
)))
}
};
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let _ = wc.query_watchman(&WatchmanConfig::default())?;
let _ = wc.query_watchman(&config)?;
writeln!(
ui.stdout(),
"The watchman server seems to be installed and working correctly."
)?;
writeln!(
ui.stdout(),
"Background snapshotting is currently {}.",
if wc.is_watchman_trigger_registered(&config)? {
"active"
} else {
"inactive"
}
)?;
}
WatchmanCommand::QueryClock => {
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::settings::ConfigResultExt;
#[derive(Default, Eq, PartialEq, Clone, Debug)]
pub struct WatchmanConfig {
/// Whether to use triggers to monitor for changes in the background.
register_trigger: bool,
pub register_trigger: bool,
}

/// The recognized kinds of filesystem monitors.
Expand Down Expand Up @@ -260,7 +260,7 @@ pub mod watchman {

/// Return whether or not a trigger has been registered already.
#[instrument(skip(self))]
async fn is_trigger_registered(&self) -> Result<bool, Error> {
pub async fn is_trigger_registered(&self) -> Result<bool, Error> {
info!("Checking for an existing Watchman trigger...");
Ok(self
.client
Expand Down
29 changes: 29 additions & 0 deletions lib/src/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,22 @@ impl TreeState {
Ok(changed_files)
}

#[cfg(feature = "watchman")]
#[tokio::main(flavor = "current_thread")]
#[instrument(skip(self))]
pub async fn is_watchman_trigger_registered(
&self,
config: &WatchmanConfig,
) -> Result<bool, TreeStateError> {
let fsmonitor = watchman::Fsmonitor::init(&self.working_copy_path, config)
.await
.map_err(|err| TreeStateError::Fsmonitor(Box::new(err)))?;
fsmonitor
.is_trigger_registered()
.await
.map_err(|err| TreeStateError::Fsmonitor(Box::new(err)))
}

/// Look for changes to the working copy. If there are any changes, create
/// a new tree from it and return it, and also update the dirstate on disk.
#[instrument(skip_all)]
Expand Down Expand Up @@ -1696,6 +1712,19 @@ impl LocalWorkingCopy {
err: err.into(),
})
}

#[cfg(feature = "watchman")]
pub fn is_watchman_trigger_registered(
&self,
config: &WatchmanConfig,
) -> Result<bool, WorkingCopyStateError> {
self.tree_state()?
.is_watchman_trigger_registered(config)
.map_err(|err| WorkingCopyStateError {
message: "Failed to query watchman".to_string(),
err: err.into(),
})
}
}

pub struct LocalWorkingCopyFactory {}
Expand Down

0 comments on commit c9b3d64

Please sign in to comment.