Avoid retraversing filesystem when testing exact glob matches (#9022)

## Summary

When testing for exact inclusion, we can just test the glob directly.
There's no need to re-traverse the filesystem to find it.
This commit is contained in:
Charlie Marsh 2024-11-11 12:54:35 -05:00 committed by GitHub
parent 760cf82ee3
commit 769afa96a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1312,17 +1312,12 @@ fn is_excluded_from_workspace(
let absolute_glob = PathBuf::from(glob::Pattern::escape(
workspace_root.simplified().to_string_lossy().as_ref(),
))
.join(exclude_glob.as_str())
.to_string_lossy()
.to_string();
for excluded_root in glob(&absolute_glob)
.map_err(|err| WorkspaceError::Pattern(absolute_glob.to_string(), err))?
{
let excluded_root = excluded_root
.map_err(|err| WorkspaceError::Glob(absolute_glob.to_string(), err))?;
if excluded_root == project_path.simplified() {
return Ok(true);
}
.join(exclude_glob.as_str());
let absolute_glob = absolute_glob.to_string_lossy();
let exclude_pattern = glob::Pattern::new(&absolute_glob)
.map_err(|err| WorkspaceError::Pattern(absolute_glob.to_string(), err))?;
if exclude_pattern.matches_path(project_path) {
return Ok(true);
}
}
Ok(false)
@ -1338,17 +1333,12 @@ fn is_included_in_workspace(
let absolute_glob = PathBuf::from(glob::Pattern::escape(
workspace_root.simplified().to_string_lossy().as_ref(),
))
.join(member_glob.as_str())
.to_string_lossy()
.to_string();
for member_root in glob(&absolute_glob)
.map_err(|err| WorkspaceError::Pattern(absolute_glob.to_string(), err))?
{
let member_root =
member_root.map_err(|err| WorkspaceError::Glob(absolute_glob.to_string(), err))?;
if member_root == project_path {
return Ok(true);
}
.join(member_glob.as_str());
let absolute_glob = absolute_glob.to_string_lossy();
let include_pattern = glob::Pattern::new(&absolute_glob)
.map_err(|err| WorkspaceError::Pattern(absolute_glob.to_string(), err))?;
if include_pattern.matches_path(project_path) {
return Ok(true);
}
}
Ok(false)