mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
Add background snapshotting info to debug watchman status
.
This commit is contained in:
parent
397e96f9ae
commit
c9b3d64ce5
3 changed files with 66 additions and 13 deletions
|
@ -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())?;
|
||||
|
|
|
@ -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.
|
||||
|
@ -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
|
||||
|
|
|
@ -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)]
|
||||
|
@ -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 {}
|
||||
|
|
Loading…
Reference in a new issue