Remove unnescessary double lookup in repo for (#2492)

Release Notes:

* Optimize repository queries (preview only)
This commit is contained in:
Max Brunsfeld 2023-05-19 11:47:05 -07:00 committed by GitHub
commit 844b8d9e1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -125,7 +125,7 @@ impl Snapshot {
let mut max_len = 0; let mut max_len = 0;
let mut current_candidate = None; let mut current_candidate = None;
for (work_directory, repo) in (&self.repository_entries).iter() { for (work_directory, repo) in (&self.repository_entries).iter() {
if repo.contains(self, path) { if path.starts_with(&work_directory.0) {
if work_directory.0.as_os_str().len() >= max_len { if work_directory.0.as_os_str().len() >= max_len {
current_candidate = Some(repo); current_candidate = Some(repo);
max_len = work_directory.0.as_os_str().len(); max_len = work_directory.0.as_os_str().len();
@ -169,10 +169,6 @@ impl RepositoryEntry {
.map(|entry| RepositoryWorkDirectory(entry.path.clone())) .map(|entry| RepositoryWorkDirectory(entry.path.clone()))
} }
pub(crate) fn contains(&self, snapshot: &Snapshot, path: &Path) -> bool {
self.work_directory.contains(snapshot, path)
}
pub fn status_for_file(&self, snapshot: &Snapshot, path: &Path) -> Option<GitFileStatus> { pub fn status_for_file(&self, snapshot: &Snapshot, path: &Path) -> Option<GitFileStatus> {
self.work_directory self.work_directory
.relativize(snapshot, path) .relativize(snapshot, path)
@ -305,14 +301,6 @@ impl AsRef<Path> for RepositoryWorkDirectory {
pub struct WorkDirectoryEntry(ProjectEntryId); pub struct WorkDirectoryEntry(ProjectEntryId);
impl WorkDirectoryEntry { impl WorkDirectoryEntry {
// Note that these paths should be relative to the worktree root.
pub(crate) fn contains(&self, snapshot: &Snapshot, path: &Path) -> bool {
snapshot
.entry_for_id(self.0)
.map(|entry| path.starts_with(&entry.path))
.unwrap_or(false)
}
pub(crate) fn relativize(&self, worktree: &Snapshot, path: &Path) -> Option<RepoPath> { pub(crate) fn relativize(&self, worktree: &Snapshot, path: &Path) -> Option<RepoPath> {
worktree.entry_for_id(self.0).and_then(|entry| { worktree.entry_for_id(self.0).and_then(|entry| {
path.strip_prefix(&entry.path) path.strip_prefix(&entry.path)