chore: Fix several style lints (#17488)

It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-06 11:58:39 +02:00 committed by GitHub
parent 93249fc82b
commit e6c1c51b37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
361 changed files with 3530 additions and 3587 deletions

View file

@ -797,11 +797,9 @@ impl Worktree {
}
Worktree::Remote(this) => {
let relative_worktree_source_path =
if let Some(relative_worktree_source_path) = relative_worktree_source_path {
Some(relative_worktree_source_path.to_string_lossy().into())
} else {
None
};
relative_worktree_source_path.map(|relative_worktree_source_path| {
relative_worktree_source_path.to_string_lossy().into()
});
let response = this.client.request(proto::CopyProjectEntry {
project_id: this.project_id,
entry_id: entry_id.to_proto(),
@ -958,13 +956,8 @@ impl Worktree {
mut cx: AsyncAppContext,
) -> Result<proto::ProjectEntryResponse> {
let (scan_id, task) = this.update(&mut cx, |this, cx| {
let relative_worktree_source_path = if let Some(relative_worktree_source_path) =
request.relative_worktree_source_path
{
Some(PathBuf::from(relative_worktree_source_path))
} else {
None
};
let relative_worktree_source_path =
request.relative_worktree_source_path.map(PathBuf::from);
(
this.scan_id(),
this.copy_entry(
@ -1454,26 +1447,24 @@ impl LocalWorktree {
} else {
fs.remove_file(&abs_path?, Default::default()).await?;
}
} else if trash {
fs.trash_dir(
&abs_path?,
RemoveOptions {
recursive: true,
ignore_if_not_exists: false,
},
)
.await?;
} else {
if trash {
fs.trash_dir(
&abs_path?,
RemoveOptions {
recursive: true,
ignore_if_not_exists: false,
},
)
.await?;
} else {
fs.remove_dir(
&abs_path?,
RemoveOptions {
recursive: true,
ignore_if_not_exists: false,
},
)
.await?;
}
fs.remove_dir(
&abs_path?,
RemoveOptions {
recursive: true,
ignore_if_not_exists: false,
},
)
.await?;
}
anyhow::Ok(entry.path)
});
@ -2123,14 +2114,10 @@ impl Snapshot {
update.removed_repositories.sort_unstable();
self.repository_entries.retain(|_, entry| {
if let Ok(_) = update
update
.removed_repositories
.binary_search(&entry.work_directory.to_proto())
{
false
} else {
true
}
.is_err()
});
for repository in update.updated_repositories {
@ -2566,7 +2553,7 @@ impl LocalSnapshot {
new_ignores.push((ancestor, None));
}
}
if ancestor.join(&*DOT_GIT).is_dir() {
if ancestor.join(*DOT_GIT).is_dir() {
break;
}
}
@ -2658,9 +2645,9 @@ impl LocalSnapshot {
for ignore_parent_abs_path in self.ignores_by_parent_abs_path.keys() {
let ignore_parent_path =
ignore_parent_abs_path.strip_prefix(&self.abs_path).unwrap();
assert!(self.entry_for_path(&ignore_parent_path).is_some());
assert!(self.entry_for_path(ignore_parent_path).is_some());
assert!(self
.entry_for_path(ignore_parent_path.join(&*GITIGNORE))
.entry_for_path(ignore_parent_path.join(*GITIGNORE))
.is_some());
}
}
@ -2811,7 +2798,7 @@ impl BackgroundScannerState {
}
if let Some(ignore) = ignore {
let abs_parent_path = self.snapshot.abs_path.join(&parent_path).into();
let abs_parent_path = self.snapshot.abs_path.join(parent_path).into();
self.snapshot
.ignores_by_parent_abs_path
.insert(abs_parent_path, (ignore, false));
@ -2892,7 +2879,7 @@ impl BackgroundScannerState {
);
self.snapshot
.git_repositories
.retain(|id, _| removed_ids.binary_search(&id).is_err());
.retain(|id, _| removed_ids.binary_search(id).is_err());
self.snapshot
.repository_entries
.retain(|repo_path, _| !repo_path.0.starts_with(path));
@ -3381,13 +3368,12 @@ impl sum_tree::Item for Entry {
}
let mut statuses = GitStatuses::default();
match self.git_status {
Some(status) => match status {
if let Some(status) = self.git_status {
match status {
GitFileStatus::Added => statuses.added = 1,
GitFileStatus::Modified => statuses.modified = 1,
GitFileStatus::Conflict => statuses.conflict = 1,
},
None => {}
}
}
EntrySummary {
@ -3536,7 +3522,7 @@ impl BackgroundScanner {
for (index, ancestor) in root_abs_path.ancestors().enumerate() {
if index != 0 {
if let Ok(ignore) =
build_gitignore(&ancestor.join(&*GITIGNORE), self.fs.as_ref()).await
build_gitignore(&ancestor.join(*GITIGNORE), self.fs.as_ref()).await
{
self.state
.lock()
@ -3546,7 +3532,7 @@ impl BackgroundScanner {
}
}
let ancestor_dot_git = ancestor.join(&*DOT_GIT);
let ancestor_dot_git = ancestor.join(*DOT_GIT);
if ancestor_dot_git.is_dir() {
if index != 0 {
// We canonicalize, since the FS events use the canonicalized path.
@ -3714,7 +3700,7 @@ impl BackgroundScanner {
let mut relative_paths = Vec::with_capacity(abs_paths.len());
let mut dot_git_paths = Vec::new();
abs_paths.sort_unstable();
abs_paths.dedup_by(|a, b| a.starts_with(&b));
abs_paths.dedup_by(|a, b| a.starts_with(b));
abs_paths.retain(|abs_path| {
let snapshot = &self.state.lock().snapshot;
{
@ -3832,7 +3818,7 @@ impl BackgroundScanner {
self.scan_dir(&job).await.log_err();
}
mem::take(&mut self.state.lock().paths_to_scan).len() > 0
!mem::take(&mut self.state.lock().paths_to_scan).is_empty()
}
async fn scan_dirs(
@ -4208,7 +4194,7 @@ impl BackgroundScanner {
repo_paths: Vec::new(),
relative_paths: Vec::new(),
})
.add_paths(&relative_path, repo_path);
.add_paths(relative_path, repo_path);
}
}
}
@ -4223,7 +4209,7 @@ impl BackgroundScanner {
});
for (path, metadata) in relative_paths.iter().zip(metadata.into_iter()) {
let abs_path: Arc<Path> = root_abs_path.join(&path).into();
let abs_path: Arc<Path> = root_abs_path.join(path).into();
match metadata {
Ok(Some((metadata, canonical_path))) => {
let ignore_stack = state
@ -4320,7 +4306,7 @@ impl BackgroundScanner {
}
}
let ignore_path = parent_path.join(&*GITIGNORE);
let ignore_path = parent_path.join(*GITIGNORE);
if snapshot.snapshot.entry_for_path(ignore_path).is_none() {
return false;
}
@ -4430,7 +4416,7 @@ impl BackgroundScanner {
path_entry.is_ignored = entry.is_ignored;
if !entry.is_dir() && !entry.is_ignored && !entry.is_external {
if let Some((ref repo_entry, local_repo)) = repo {
if let Ok(repo_path) = repo_entry.relativize(&snapshot, &entry.path) {
if let Ok(repo_path) = repo_entry.relativize(snapshot, &entry.path) {
let status = local_repo
.repo_ptr
.status(&[repo_path.0.clone()])
@ -4612,7 +4598,7 @@ impl BackgroundScanner {
let git_status = if let Some(location) = &job.location_in_repo {
statuses.get(&location.join(repo_path))
} else {
statuses.get(&repo_path)
statuses.get(repo_path)
};
if file.git_status != git_status {
let mut entry = file.clone();
@ -4732,7 +4718,7 @@ impl BackgroundScanner {
let is_newly_loaded = self.phase == InitialScan
|| last_newly_loaded_dir_path
.as_ref()
.map_or(false, |dir| new_entry.path.starts_with(&dir));
.map_or(false, |dir| new_entry.path.starts_with(dir));
changes.push((
new_entry.path.clone(),
new_entry.id,
@ -4750,7 +4736,7 @@ impl BackgroundScanner {
let is_newly_loaded = self.phase == InitialScan
|| last_newly_loaded_dir_path
.as_ref()
.map_or(false, |dir| new_entry.path.starts_with(&dir));
.map_or(false, |dir| new_entry.path.starts_with(dir));
changes.push((
new_entry.path.clone(),
new_entry.id,
@ -5222,7 +5208,7 @@ impl<'a> Iterator for ChildEntriesIter<'a> {
fn next(&mut self) -> Option<Self::Item> {
if let Some(item) = self.traversal.entry() {
if item.path.starts_with(&self.parent_path) {
if item.path.starts_with(self.parent_path) {
self.traversal.advance_to_sibling();
return Some(item);
}

View file

@ -16,12 +16,12 @@ pub struct WorktreeSettings {
impl WorktreeSettings {
pub fn is_path_private(&self, path: &Path) -> bool {
path.ancestors()
.any(|ancestor| self.private_files.is_match(&ancestor))
.any(|ancestor| self.private_files.is_match(ancestor))
}
pub fn is_path_excluded(&self, path: &Path) -> bool {
path.ancestors()
.any(|ancestor| self.file_scan_exclusions.is_match(&ancestor))
.any(|ancestor| self.file_scan_exclusions.is_match(ancestor))
}
}

View file

@ -725,7 +725,7 @@ async fn test_rescan_with_gitignore(cx: &mut TestAppContext) {
});
fs.set_status_for_repo_via_working_copy_change(
&Path::new("/root/tree/.git"),
Path::new("/root/tree/.git"),
&[(Path::new("tracked-dir/tracked-file2"), GitFileStatus::Added)],
);
@ -809,7 +809,7 @@ async fn test_update_gitignore(cx: &mut TestAppContext) {
.unwrap();
fs.set_status_for_repo_via_working_copy_change(
&Path::new("/root/.git"),
Path::new("/root/.git"),
&[(Path::new("b.txt"), GitFileStatus::Added)],
);
@ -1266,7 +1266,7 @@ async fn test_bump_mtime_of_git_repo_workdir(cx: &mut TestAppContext) {
// Regression test: changes to the git repository should still be
// detected.
fs.set_status_for_repo_via_git_operation(
&Path::new("/root/.git"),
Path::new("/root/.git"),
&[(Path::new("b/c.txt"), GitFileStatus::Modified)],
);
cx.executor().run_until_parked();
@ -1646,7 +1646,7 @@ fn check_worktree_change_events(tree: &mut Worktree, cx: &mut ModelContext<Workt
cx.subscribe(&cx.handle(), move |tree, _, event, _| {
if let Event::UpdatedEntries(changes) = event {
for (path, _, change_type) in changes.iter() {
let entry = tree.entry_for_path(&path).cloned();
let entry = tree.entry_for_path(path).cloned();
let ix = match entries.binary_search_by_key(&path, |e| &e.path) {
Ok(ix) | Err(ix) => ix,
};
@ -1781,16 +1781,16 @@ async fn randomly_mutate_fs(
}
} else if rng.gen_bool(0.05) {
let ignore_dir_path = dirs.choose(rng).unwrap();
let ignore_path = ignore_dir_path.join(&*GITIGNORE);
let ignore_path = ignore_dir_path.join(*GITIGNORE);
let subdirs = dirs
.iter()
.filter(|d| d.starts_with(&ignore_dir_path))
.filter(|d| d.starts_with(ignore_dir_path))
.cloned()
.collect::<Vec<_>>();
let subfiles = files
.iter()
.filter(|d| d.starts_with(&ignore_dir_path))
.filter(|d| d.starts_with(ignore_dir_path))
.cloned()
.collect::<Vec<_>>();
let files_to_ignore = {
@ -1808,7 +1808,7 @@ async fn randomly_mutate_fs(
ignore_contents,
"{}",
path_to_ignore
.strip_prefix(&ignore_dir_path)
.strip_prefix(ignore_dir_path)
.unwrap()
.to_str()
.unwrap()
@ -1817,7 +1817,7 @@ async fn randomly_mutate_fs(
}
log::info!(
"creating gitignore {:?} with contents:\n{}",
ignore_path.strip_prefix(&root_path).unwrap(),
ignore_path.strip_prefix(root_path).unwrap(),
ignore_contents
);
fs.save(
@ -1843,10 +1843,10 @@ async fn randomly_mutate_fs(
.unwrap();
let overwrite_existing_dir =
!old_path.starts_with(&new_path_parent) && rng.gen_bool(0.3);
!old_path.starts_with(new_path_parent) && rng.gen_bool(0.3);
let new_path = if overwrite_existing_dir {
fs.remove_dir(
&new_path_parent,
new_path_parent,
RemoveOptions {
recursive: true,
ignore_if_not_exists: true,
@ -1861,16 +1861,16 @@ async fn randomly_mutate_fs(
log::info!(
"renaming {:?} to {}{:?}",
old_path.strip_prefix(&root_path).unwrap(),
old_path.strip_prefix(root_path).unwrap(),
if overwrite_existing_dir {
"overwrite "
} else {
""
},
new_path.strip_prefix(&root_path).unwrap()
new_path.strip_prefix(root_path).unwrap()
);
fs.rename(
&old_path,
old_path,
&new_path,
fs::RenameOptions {
overwrite: true,
@ -1879,19 +1879,19 @@ async fn randomly_mutate_fs(
)
.await
.unwrap();
} else if fs.is_file(&old_path).await {
} else if fs.is_file(old_path).await {
log::info!(
"deleting file {:?}",
old_path.strip_prefix(&root_path).unwrap()
old_path.strip_prefix(root_path).unwrap()
);
fs.remove_file(old_path, Default::default()).await.unwrap();
} else {
log::info!(
"deleting dir {:?}",
old_path.strip_prefix(&root_path).unwrap()
old_path.strip_prefix(root_path).unwrap()
);
fs.remove_dir(
&old_path,
old_path,
RemoveOptions {
recursive: true,
ignore_if_not_exists: true,
@ -2048,7 +2048,7 @@ async fn test_git_repository_for_path(cx: &mut TestAppContext) {
(
entry.path.as_ref(),
repo.and_then(|repo| {
repo.work_directory(&tree)
repo.work_directory(tree)
.map(|work_directory| work_directory.0.to_path_buf())
}),
)
@ -2262,7 +2262,7 @@ async fn test_git_status(cx: &mut TestAppContext) {
tree.read_with(cx, |tree, _cx| {
let snapshot = tree.snapshot();
assert_eq!(
snapshot.status_for_file(&project_path.join(renamed_dir_name).join(RENAMED_FILE)),
snapshot.status_for_file(project_path.join(renamed_dir_name).join(RENAMED_FILE)),
Some(GitFileStatus::Added)
);
});
@ -2413,7 +2413,7 @@ async fn test_propagate_git_statuses(cx: &mut TestAppContext) {
.await;
fs.set_status_for_repo_via_git_operation(
&Path::new("/root/.git"),
Path::new("/root/.git"),
&[
(Path::new("a/b/c1.txt"), GitFileStatus::Added),
(Path::new("a/d/e2.txt"), GitFileStatus::Modified),
@ -2527,7 +2527,7 @@ fn git_commit(msg: &'static str, repo: &git2::Repository) {
let signature = Signature::now("test", "test@zed.dev").unwrap();
let oid = repo.index().unwrap().write_tree().unwrap();
let tree = repo.find_tree(oid).unwrap();
if let Some(head) = repo.head().ok() {
if let Ok(head) = repo.head() {
let parent_obj = head.peel(git2::ObjectType::Commit).unwrap();
let parent_commit = parent_obj.as_commit().unwrap();
@ -2566,10 +2566,9 @@ fn git_reset(offset: usize, repo: &git2::Repository) {
.inspect(|parnet| {
parnet.message();
})
.skip(offset)
.next()
.nth(offset)
.expect("Not enough history");
repo.reset(&new_head.as_object(), git2::ResetType::Soft, None)
repo.reset(new_head.as_object(), git2::ResetType::Soft, None)
.expect("Could not reset");
}