mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 16:53:25 +00:00
watchman: don't even add non-watchman files to set of deleted files
It's faster to add only files matched by the Watchman matcher to the set of deleted files than to add all files and then removed files not matched. This speeds up `jj diff` with Watchman in the Linux repo from ~530 ms to ~460 ms.
This commit is contained in:
parent
4b635e9713
commit
beb997e85a
1 changed files with 17 additions and 23 deletions
|
@ -607,29 +607,29 @@ impl TreeState {
|
|||
let sparse_matcher = self.sparse_matcher();
|
||||
let current_tree = self.store.get_tree(&RepoPath::root(), &self.tree_id)?;
|
||||
let mut tree_builder = self.store.tree_builder(self.tree_id.clone());
|
||||
let mut deleted_files: HashSet<_> =
|
||||
trace_span!("collecting existing files").in_scope(|| {
|
||||
self.file_states
|
||||
.iter()
|
||||
.filter_map(|(path, state)| {
|
||||
(state.file_type != FileType::GitSubmodule).then(|| path.clone())
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
let fsmonitor_clock_needs_save = fsmonitor_kind.is_some();
|
||||
let FsmonitorMatcher {
|
||||
matcher: fsmonitor_matcher,
|
||||
watchman_clock,
|
||||
} = self.make_fsmonitor_matcher(fsmonitor_kind, &mut deleted_files)?;
|
||||
|
||||
let matcher = IntersectionMatcher::new(
|
||||
sparse_matcher.as_ref(),
|
||||
match fsmonitor_matcher.as_ref() {
|
||||
} = self.make_fsmonitor_matcher(fsmonitor_kind)?;
|
||||
let fsmonitor_matcher = match fsmonitor_matcher.as_ref() {
|
||||
None => &EverythingMatcher,
|
||||
Some(fsmonitor_matcher) => fsmonitor_matcher.as_ref(),
|
||||
},
|
||||
);
|
||||
};
|
||||
let mut deleted_files: HashSet<_> =
|
||||
trace_span!("collecting existing files").in_scope(|| {
|
||||
self.file_states
|
||||
.iter()
|
||||
.filter_map(|(path, state)| {
|
||||
(fsmonitor_matcher.matches(path)
|
||||
&& state.file_type != FileType::GitSubmodule)
|
||||
.then(|| path.clone())
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
let matcher = IntersectionMatcher::new(sparse_matcher.as_ref(), fsmonitor_matcher);
|
||||
struct WorkItem {
|
||||
dir: RepoPath,
|
||||
disk_dir: PathBuf,
|
||||
|
@ -733,7 +733,6 @@ impl TreeState {
|
|||
fn make_fsmonitor_matcher(
|
||||
&mut self,
|
||||
fsmonitor_kind: Option<FsmonitorKind>,
|
||||
deleted_files: &mut HashSet<RepoPath>,
|
||||
) -> Result<FsmonitorMatcher, SnapshotError> {
|
||||
let (watchman_clock, changed_files) = match fsmonitor_kind {
|
||||
None => (None, None),
|
||||
|
@ -774,11 +773,6 @@ impl TreeState {
|
|||
.collect_vec()
|
||||
});
|
||||
|
||||
trace_span!("retaining fsmonitor paths").in_scope(|| {
|
||||
let repo_path_set: HashSet<_> = repo_paths.iter().collect();
|
||||
deleted_files.retain(|path| repo_path_set.contains(path));
|
||||
});
|
||||
|
||||
Some(Box::new(PrefixMatcher::new(&repo_paths)))
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue