Skip to content

Commit 623a6ec

Browse files
authored
git: Do not rescan .git on fsmonitor events (#18326)
Fixes #16404 by ignoring events coming from .git/fsmonitor--daemon/cookies subdirectory. Closes #16404 Release Notes: - Improved performance in repositories using Git fsmonitor--daemon feature.
1 parent 7bb5109 commit 623a6ec

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

crates/git/src/git.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub mod repository;
1818
pub mod status;
1919

2020
pub static DOT_GIT: LazyLock<&'static OsStr> = LazyLock::new(|| OsStr::new(".git"));
21+
pub static COOKIES: LazyLock<&'static OsStr> = LazyLock::new(|| OsStr::new("cookies"));
22+
pub static FSMONITOR_DAEMON: LazyLock<&'static OsStr> =
23+
LazyLock::new(|| OsStr::new("fsmonitor--daemon"));
2124
pub static GITIGNORE: LazyLock<&'static OsStr> = LazyLock::new(|| OsStr::new(".gitignore"));
2225

2326
#[derive(Clone, Copy, Eq, Hash, PartialEq)]

crates/worktree/src/worktree.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use fuzzy::CharBag;
2222
use git::{
2323
repository::{GitFileStatus, GitRepository, RepoPath},
2424
status::GitStatus,
25-
DOT_GIT, GITIGNORE,
25+
COOKIES, DOT_GIT, FSMONITOR_DAEMON, GITIGNORE,
2626
};
2727
use gpui::{
2828
AppContext, AsyncAppContext, BackgroundExecutor, Context, EventEmitter, Model, ModelContext,
@@ -3707,9 +3707,32 @@ impl BackgroundScanner {
37073707
let snapshot = &self.state.lock().snapshot;
37083708
{
37093709
let mut is_git_related = false;
3710+
3711+
// We don't want to trigger .git rescan for events within .git/fsmonitor--daemon/cookies directory.
3712+
#[derive(PartialEq)]
3713+
enum FsMonitorParseState {
3714+
Cookies,
3715+
FsMonitor
3716+
}
3717+
let mut fsmonitor_parse_state = None;
37103718
if let Some(dot_git_dir) = abs_path
37113719
.ancestors()
3712-
.find(|ancestor| ancestor.file_name() == Some(*DOT_GIT))
3720+
.find(|ancestor| {
3721+
let file_name = ancestor.file_name();
3722+
if file_name == Some(*COOKIES) {
3723+
fsmonitor_parse_state = Some(FsMonitorParseState::Cookies);
3724+
false
3725+
} else if fsmonitor_parse_state == Some(FsMonitorParseState::Cookies) && file_name == Some(*FSMONITOR_DAEMON) {
3726+
fsmonitor_parse_state = Some(FsMonitorParseState::FsMonitor);
3727+
false
3728+
} else if fsmonitor_parse_state != Some(FsMonitorParseState::FsMonitor) && file_name == Some(*DOT_GIT) {
3729+
true
3730+
} else {
3731+
fsmonitor_parse_state.take();
3732+
false
3733+
}
3734+
3735+
})
37133736
{
37143737
let dot_git_path = dot_git_dir
37153738
.strip_prefix(&root_canonical_path)

0 commit comments

Comments
 (0)