Fix git stage race condition with delayed fs events (#27036)

This PR adds a failing test `test_staging_hunks_with_delayed_fs_event`
and makes it pass

Also skips a queued read for git diff states if another read was
requested (less work)

This still doesn't catch all race conditions, but the PR is getting long
so I'll yield this and start another branch

Release Notes:

- N/A
This commit is contained in:
João Marcos 2025-03-18 22:44:36 -03:00 committed by GitHub
parent 68a572873b
commit 7f2e3fb5bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 476 additions and 245 deletions

View file

@ -58,16 +58,26 @@ impl FakeGitRepositoryState {
impl GitRepository for FakeGitRepository {
fn reload_index(&self) {}
fn load_index_text(&self, path: RepoPath, _: AsyncApp) -> BoxFuture<Option<String>> {
fn load_index_text(&self, path: RepoPath, cx: AsyncApp) -> BoxFuture<Option<String>> {
let state = self.state.lock();
let content = state.index_contents.get(path.as_ref()).cloned();
async { content }.boxed()
let executor = cx.background_executor().clone();
async move {
executor.simulate_random_delay().await;
content
}
.boxed()
}
fn load_committed_text(&self, path: RepoPath, _: AsyncApp) -> BoxFuture<Option<String>> {
fn load_committed_text(&self, path: RepoPath, cx: AsyncApp) -> BoxFuture<Option<String>> {
let state = self.state.lock();
let content = state.head_contents.get(path.as_ref()).cloned();
async { content }.boxed()
let executor = cx.background_executor().clone();
async move {
executor.simulate_random_delay().await;
content
}
.boxed()
}
fn set_index_text(