Use commondir
from libgit2 instead of walking fs (#22028)
Release Notes: - N/A
This commit is contained in:
parent
35ef269233
commit
864c1ff00c
2 changed files with 42 additions and 28 deletions
|
@ -3354,18 +3354,23 @@ impl BackgroundScannerState {
|
|||
let t0 = Instant::now();
|
||||
let repository = fs.open_repo(&dot_git_abs_path)?;
|
||||
|
||||
let actual_repo_path = repository.dot_git_dir();
|
||||
let repository_path = repository.path();
|
||||
watcher.add(&repository_path).log_err()?;
|
||||
|
||||
let actual_dot_git_dir_abs_path = smol::block_on(find_git_dir(&actual_repo_path, fs))?;
|
||||
watcher.add(&actual_repo_path).log_err()?;
|
||||
|
||||
let dot_git_worktree_abs_path = if actual_dot_git_dir_abs_path.as_ref() == dot_git_abs_path
|
||||
{
|
||||
let actual_dot_git_dir_abs_path = repository.main_repository_path();
|
||||
let dot_git_worktree_abs_path = if actual_dot_git_dir_abs_path == dot_git_abs_path {
|
||||
None
|
||||
} else {
|
||||
// The two paths could be different because we opened a git worktree.
|
||||
// When that happens, the .git path in the worktree (`dot_git_abs_path`) is a file that
|
||||
// points to the worktree-subdirectory in the actual .git directory (`git_dir_path`)
|
||||
// When that happens:
|
||||
//
|
||||
// * `dot_git_abs_path` is a file that points to the worktree-subdirectory in the actual
|
||||
// .git directory.
|
||||
//
|
||||
// * `repository_path` is the worktree-subdirectory.
|
||||
//
|
||||
// * `actual_dot_git_dir_abs_path` is the path to the actual .git directory. In git
|
||||
// documentation this is called the "commondir".
|
||||
watcher.add(&dot_git_abs_path).log_err()?;
|
||||
Some(Arc::from(dot_git_abs_path))
|
||||
};
|
||||
|
@ -3400,7 +3405,7 @@ impl BackgroundScannerState {
|
|||
git_dir_scan_id: 0,
|
||||
status_scan_id: 0,
|
||||
repo_ptr: repository.clone(),
|
||||
dot_git_dir_abs_path: actual_dot_git_dir_abs_path,
|
||||
dot_git_dir_abs_path: actual_dot_git_dir_abs_path.into(),
|
||||
dot_git_worktree_abs_path,
|
||||
current_merge_head_shas: Default::default(),
|
||||
};
|
||||
|
@ -3429,15 +3434,6 @@ async fn is_git_dir(path: &Path, fs: &dyn Fs) -> bool {
|
|||
matches!(config_metadata, Ok(Some(_)))
|
||||
}
|
||||
|
||||
async fn find_git_dir(path: &Path, fs: &dyn Fs) -> Option<Arc<Path>> {
|
||||
for ancestor in path.ancestors() {
|
||||
if is_git_dir(ancestor, fs).await {
|
||||
return Some(Arc::from(ancestor));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
async fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> {
|
||||
let contents = fs.load(abs_path).await?;
|
||||
let parent = abs_path.parent().unwrap_or_else(|| Path::new("/"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue