Finish removing git repository state and scanning logic from worktrees (#27568)

This PR completes the process of moving git repository state storage and
scanning logic from the worktree crate to `project::git_store`.

Release Notes:

- N/A

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Cole Miller 2025-04-01 17:41:20 -04:00 committed by GitHub
parent 8f25251faf
commit e7290df02b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 3121 additions and 3529 deletions

View file

@ -334,7 +334,7 @@ impl Database {
project_repository::ActiveModel {
project_id: ActiveValue::set(project_id),
legacy_worktree_id: ActiveValue::set(Some(worktree_id)),
id: ActiveValue::set(repository.work_directory_id as i64),
id: ActiveValue::set(repository.repository_id as i64),
scan_id: ActiveValue::set(update.scan_id as i64),
is_deleted: ActiveValue::set(false),
branch_summary: ActiveValue::Set(
@ -384,7 +384,7 @@ impl Database {
project_repository_statuses::ActiveModel {
project_id: ActiveValue::set(project_id),
repository_id: ActiveValue::set(
repository.work_directory_id as i64,
repository.repository_id as i64,
),
scan_id: ActiveValue::set(update.scan_id as i64),
is_deleted: ActiveValue::set(false),
@ -424,7 +424,7 @@ impl Database {
.eq(project_id)
.and(
project_repository_statuses::Column::RepositoryId
.eq(repo.work_directory_id),
.eq(repo.repository_id),
)
.and(
project_repository_statuses::Column::RepoPath
@ -936,7 +936,7 @@ impl Database {
worktree.legacy_repository_entries.insert(
db_repository_entry.id as u64,
proto::RepositoryEntry {
work_directory_id: db_repository_entry.id as u64,
repository_id: db_repository_entry.id as u64,
updated_statuses,
removed_statuses: Vec::new(),
current_merge_conflicts,
@ -955,6 +955,7 @@ impl Database {
current_merge_conflicts,
branch_summary,
scan_id: db_repository_entry.scan_id as u64,
is_last_update: true,
});
}
}

View file

@ -764,7 +764,7 @@ impl Database {
.find(|worktree| worktree.id as i64 == legacy_worktree_id)
{
worktree.updated_repositories.push(proto::RepositoryEntry {
work_directory_id: db_repository.id as u64,
repository_id: db_repository.id as u64,
updated_statuses,
removed_statuses,
current_merge_conflicts,
@ -782,6 +782,7 @@ impl Database {
id: db_repository.id as u64,
abs_path: db_repository.abs_path,
scan_id: db_repository.scan_id as u64,
is_last_update: true,
});
}
}

View file

@ -2898,8 +2898,8 @@ async fn test_git_branch_name(
assert_eq!(
repository
.read(cx)
.repository_entry
.branch()
.branch
.as_ref()
.map(|branch| branch.name.to_string()),
branch_name
)
@ -3033,7 +3033,6 @@ async fn test_git_status_sync(
let repo = repos.into_iter().next().unwrap();
assert_eq!(
repo.read(cx)
.repository_entry
.status_for_path(&file.into())
.map(|entry| entry.status),
status
@ -6882,7 +6881,8 @@ async fn test_remote_git_branches(
.next()
.unwrap()
.read(cx)
.current_branch()
.branch
.as_ref()
.unwrap()
.clone()
})
@ -6919,7 +6919,8 @@ async fn test_remote_git_branches(
.next()
.unwrap()
.read(cx)
.current_branch()
.branch
.as_ref()
.unwrap()
.clone()
})

View file

@ -1181,6 +1181,10 @@ impl RandomizedTest for ProjectCollaborationTest {
(worktree.id(), worktree.snapshot())
})
.collect::<BTreeMap<_, _>>();
let host_repository_snapshots = host_project.read_with(host_cx, |host_project, cx| {
host_project.git_store().read(cx).repo_snapshots(cx)
});
let guest_repository_snapshots = guest_project.git_store().read(cx).repo_snapshots(cx);
assert_eq!(
guest_worktree_snapshots.values().map(|w| w.abs_path()).collect::<Vec<_>>(),
@ -1189,6 +1193,13 @@ impl RandomizedTest for ProjectCollaborationTest {
client.username, guest_project.remote_id(),
);
assert_eq!(
guest_repository_snapshots.values().collect::<Vec<_>>(),
host_repository_snapshots.values().collect::<Vec<_>>(),
"{} has different repositories than the host for project {:?}",
client.username, guest_project.remote_id(),
);
for (id, host_snapshot) in &host_worktree_snapshots {
let guest_snapshot = &guest_worktree_snapshots[id];
assert_eq!(
@ -1216,12 +1227,6 @@ impl RandomizedTest for ProjectCollaborationTest {
id,
guest_project.remote_id(),
);
assert_eq!(guest_snapshot.repositories().iter().collect::<Vec<_>>(), host_snapshot.repositories().iter().collect::<Vec<_>>(),
"{} has different repositories than the host for worktree {:?} and project {:?}",
client.username,
host_snapshot.abs_path(),
guest_project.remote_id(),
);
assert_eq!(guest_snapshot.scan_id(), host_snapshot.scan_id(),
"{} has different scan id than the host for worktree {:?} and project {:?}",
client.username,

View file

@ -313,7 +313,8 @@ async fn test_ssh_collaboration_git_branches(
.next()
.unwrap()
.read(cx)
.current_branch()
.branch
.as_ref()
.unwrap()
.clone()
})
@ -352,7 +353,8 @@ async fn test_ssh_collaboration_git_branches(
.next()
.unwrap()
.read(cx)
.current_branch()
.branch
.as_ref()
.unwrap()
.clone()
})