forked from mirrors/jj
feat(fsmonitor): add watchman debug commands
This commit is contained in:
parent
9bb8e4fe2a
commit
cf1e1ddc2e
2 changed files with 70 additions and 1 deletions
|
@ -512,9 +512,13 @@ impl TreeState {
|
|||
Ok(self.store.write_symlink(path, str_target)?)
|
||||
}
|
||||
|
||||
fn reset_watchman(&mut self) {
|
||||
self.watchman_clock.take();
|
||||
}
|
||||
|
||||
#[cfg(feature = "watchman")]
|
||||
#[tokio::main]
|
||||
async fn query_watchman(
|
||||
pub async fn query_watchman(
|
||||
&self,
|
||||
) -> Result<(watchman::Clock, Option<Vec<PathBuf>>), watchman::Error> {
|
||||
let fsmonitor = watchman::Fsmonitor::init(&self.working_copy_path).await?;
|
||||
|
@ -1320,6 +1324,13 @@ impl WorkingCopy {
|
|||
locked_wc.finish(operation_id);
|
||||
Ok(stats)
|
||||
}
|
||||
|
||||
#[cfg(feature = "watchman")]
|
||||
pub fn query_watchman(
|
||||
&self,
|
||||
) -> Result<(watchman::Clock, Option<Vec<PathBuf>>), watchman::Error> {
|
||||
self.tree_state().query_watchman()
|
||||
}
|
||||
}
|
||||
|
||||
/// A working copy that's locked on disk. The lock is held until you call
|
||||
|
@ -1345,6 +1356,12 @@ impl LockedWorkingCopy<'_> {
|
|||
&self.old_tree_id
|
||||
}
|
||||
|
||||
pub fn reset_watchman(&mut self) -> Result<(), SnapshotError> {
|
||||
self.wc.tree_state_mut().reset_watchman();
|
||||
self.tree_state_dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// The base_ignores are passed in here rather than being set on the TreeState
|
||||
// because the TreeState may be long-lived if the library is used in a
|
||||
// long-lived process.
|
||||
|
|
|
@ -36,6 +36,8 @@ pub enum DebugCommands {
|
|||
ReIndex(DebugReIndexArgs),
|
||||
#[command(visible_alias = "view")]
|
||||
Operation(DebugOperationArgs),
|
||||
#[command(subcommand)]
|
||||
Watchman(DebugWatchmanSubcommand),
|
||||
}
|
||||
|
||||
/// Evaluate revset to full commit IDs
|
||||
|
@ -83,6 +85,13 @@ pub enum DebugOperationDisplay {
|
|||
All,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Clone, Debug)]
|
||||
pub enum DebugWatchmanSubcommand {
|
||||
QueryClock,
|
||||
QueryChangedFiles,
|
||||
ResetClock,
|
||||
}
|
||||
|
||||
pub fn cmd_debug(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
|
@ -171,6 +180,9 @@ pub fn cmd_debug(
|
|||
writeln!(ui, "{:#?}", op.view().store_view())?;
|
||||
}
|
||||
}
|
||||
DebugCommands::Watchman(watchman_subcommand) => {
|
||||
cmd_debug_watchman(ui, command, watchman_subcommand)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -215,3 +227,43 @@ fn cmd_debug_revset(
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "watchman")]
|
||||
fn cmd_debug_watchman(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
subcommand: &DebugWatchmanSubcommand,
|
||||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let repo = workspace_command.repo().clone();
|
||||
match subcommand {
|
||||
DebugWatchmanSubcommand::QueryClock => {
|
||||
let (clock, _changed_files) =
|
||||
workspace_command.working_copy().query_watchman().unwrap();
|
||||
ui.write(&format!("Clock: {clock:?}"))?;
|
||||
}
|
||||
DebugWatchmanSubcommand::QueryChangedFiles => {
|
||||
let (_clock, changed_files) =
|
||||
workspace_command.working_copy().query_watchman().unwrap();
|
||||
ui.write(&format!("Changed files: {changed_files:?}"))?;
|
||||
}
|
||||
DebugWatchmanSubcommand::ResetClock => {
|
||||
let (mut locked_wc, _commit) = workspace_command.start_working_copy_mutation()?;
|
||||
locked_wc.reset_watchman()?;
|
||||
locked_wc.finish(repo.op_id().clone());
|
||||
ui.write("Reset Watchman clock")?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "watchman"))]
|
||||
fn cmd_debug_watchman(
|
||||
_ui: &mut Ui,
|
||||
_command: &CommandHelper,
|
||||
_subcommand: &DebugWatchmanSubcommand,
|
||||
) -> Result<(), CommandError> {
|
||||
Err(user_error(
|
||||
"Cannot query Watchman because jj was not compiled with the `watchman` feature",
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue