ok/jj
1
0
Fork 0
forked from mirrors/jj

fsmonitor: allow core.fsmonitor = "none" to disable

When doing things like testing snapshot performance differences,
this allows you to turn off the monitor, no matter what the enabled
user or repository configuration has, e.g.

    jj st --config-toml='core.fsmonitor="none"'

Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
Austin Seipp 2024-02-19 16:00:51 -06:00
parent 79518eafce
commit 6c31bab0d3
5 changed files with 22 additions and 13 deletions

View file

@ -24,6 +24,7 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
/// The recognized kinds of filesystem monitors. /// The recognized kinds of filesystem monitors.
#[derive(Eq, PartialEq)]
pub enum FsmonitorKind { pub enum FsmonitorKind {
/// The Watchman filesystem monitor (https://facebook.github.io/watchman/). /// The Watchman filesystem monitor (https://facebook.github.io/watchman/).
Watchman, Watchman,
@ -34,6 +35,13 @@ pub enum FsmonitorKind {
/// reporting. /// reporting.
changed_files: Vec<PathBuf>, changed_files: Vec<PathBuf>,
}, },
/// No filesystem monitor. This is the default if nothing is configured, but
/// also makes it possible to turn off the monitor on a case-by-case basis
/// when the user gives an option like
/// `--config-toml='core.fsmonitor="none"'`; useful when e.g. when doing
/// analysis of snapshot performance.
None,
} }
impl FromStr for FsmonitorKind { impl FromStr for FsmonitorKind {
@ -45,6 +53,7 @@ impl FromStr for FsmonitorKind {
"test" => Err(config::ConfigError::Message( "test" => Err(config::ConfigError::Message(
"cannot use test fsmonitor in real repository".to_string(), "cannot use test fsmonitor in real repository".to_string(),
)), )),
"none" => Ok(Self::None),
other => Err(config::ConfigError::Message(format!( other => Err(config::ConfigError::Message(format!(
"unknown fsmonitor kind: {}", "unknown fsmonitor kind: {}",
other other

View file

@ -744,7 +744,7 @@ impl TreeState {
let sparse_matcher = self.sparse_matcher(); let sparse_matcher = self.sparse_matcher();
let fsmonitor_clock_needs_save = fsmonitor_kind.is_some(); let fsmonitor_clock_needs_save = fsmonitor_kind != FsmonitorKind::None;
let mut is_dirty = fsmonitor_clock_needs_save; let mut is_dirty = fsmonitor_clock_needs_save;
let FsmonitorMatcher { let FsmonitorMatcher {
matcher: fsmonitor_matcher, matcher: fsmonitor_matcher,
@ -1017,13 +1017,13 @@ impl TreeState {
#[instrument(skip_all)] #[instrument(skip_all)]
fn make_fsmonitor_matcher( fn make_fsmonitor_matcher(
&self, &self,
fsmonitor_kind: Option<FsmonitorKind>, fsmonitor_kind: FsmonitorKind,
) -> Result<FsmonitorMatcher, SnapshotError> { ) -> Result<FsmonitorMatcher, SnapshotError> {
let (watchman_clock, changed_files) = match fsmonitor_kind { let (watchman_clock, changed_files) = match fsmonitor_kind {
None => (None, None), FsmonitorKind::None => (None, None),
Some(FsmonitorKind::Test { changed_files }) => (None, Some(changed_files)), FsmonitorKind::Test { changed_files } => (None, Some(changed_files)),
#[cfg(feature = "watchman")] #[cfg(feature = "watchman")]
Some(FsmonitorKind::Watchman) => match self.query_watchman() { FsmonitorKind::Watchman => match self.query_watchman() {
Ok((watchman_clock, changed_files)) => (Some(watchman_clock.into()), changed_files), Ok((watchman_clock, changed_files)) => (Some(watchman_clock.into()), changed_files),
Err(err) => { Err(err) => {
tracing::warn!(?err, "Failed to query filesystem monitor"); tracing::warn!(?err, "Failed to query filesystem monitor");
@ -1031,7 +1031,7 @@ impl TreeState {
} }
}, },
#[cfg(not(feature = "watchman"))] #[cfg(not(feature = "watchman"))]
Some(FsmonitorKind::Watchman) => { FsmonitorKind::Watchman => {
return Err(SnapshotError::Other { return Err(SnapshotError::Other {
message: "Failed to query the filesystem monitor".to_string(), message: "Failed to query the filesystem monitor".to_string(),
err: "Cannot query Watchman because jj was not compiled with the `watchman` \ err: "Cannot query Watchman because jj was not compiled with the `watchman` \

View file

@ -164,10 +164,10 @@ impl UserSettings {
self.config.get_string("user.email").unwrap_or_default() self.config.get_string("user.email").unwrap_or_default()
} }
pub fn fsmonitor_kind(&self) -> Result<Option<FsmonitorKind>, config::ConfigError> { pub fn fsmonitor_kind(&self) -> Result<FsmonitorKind, config::ConfigError> {
match self.config.get_string("core.fsmonitor") { match self.config.get_string("core.fsmonitor") {
Ok(fsmonitor_kind) => Ok(Some(fsmonitor_kind.parse()?)), Ok(fsmonitor_kind) => Ok(fsmonitor_kind.parse()?),
Err(config::ConfigError::NotFound(_)) => Ok(None), Err(config::ConfigError::NotFound(_)) => Ok(FsmonitorKind::None),
Err(err) => Err(err), Err(err) => Err(err),
} }
} }

View file

@ -188,7 +188,7 @@ pub struct SnapshotOptions<'a> {
/// The fsmonitor (e.g. Watchman) to use, if any. /// The fsmonitor (e.g. Watchman) to use, if any.
// TODO: Should we make this a field on `LocalWorkingCopy` instead since it's quite specific to // TODO: Should we make this a field on `LocalWorkingCopy` instead since it's quite specific to
// that implementation? // that implementation?
pub fsmonitor_kind: Option<FsmonitorKind>, pub fsmonitor_kind: FsmonitorKind,
/// A callback for the UI to display progress. /// A callback for the UI to display progress.
pub progress: Option<&'a SnapshotProgress<'a>>, pub progress: Option<&'a SnapshotProgress<'a>>,
/// The size of the largest file that should be allowed to become tracked /// The size of the largest file that should be allowed to become tracked
@ -204,7 +204,7 @@ impl SnapshotOptions<'_> {
pub fn empty_for_test() -> Self { pub fn empty_for_test() -> Self {
SnapshotOptions { SnapshotOptions {
base_ignores: GitIgnoreFile::empty(), base_ignores: GitIgnoreFile::empty(),
fsmonitor_kind: None, fsmonitor_kind: FsmonitorKind::None,
progress: None, progress: None,
max_new_file_size: u64::MAX, max_new_file_size: u64::MAX,
} }

View file

@ -976,9 +976,9 @@ fn test_fsmonitor() {
locked_ws locked_ws
.locked_wc() .locked_wc()
.snapshot(SnapshotOptions { .snapshot(SnapshotOptions {
fsmonitor_kind: Some(FsmonitorKind::Test { fsmonitor_kind: FsmonitorKind::Test {
changed_files: fs_paths, changed_files: fs_paths,
}), },
..SnapshotOptions::empty_for_test() ..SnapshotOptions::empty_for_test()
}) })
.unwrap() .unwrap()