-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make tidy not traverse untracked directories #112921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
use ignore::DirEntry; | ||
|
||
use std::process::Command; | ||
use std::{ffi::OsStr, fs::File, io::Read, path::Path}; | ||
|
||
/// The default directory filter. | ||
pub fn filter_dirs(path: &Path) -> bool { | ||
let skip = [ | ||
let skip = vec![ | ||
"tidy-test-file", | ||
"compiler/rustc_codegen_cranelift", | ||
"compiler/rustc_codegen_gcc", | ||
|
@@ -31,6 +32,17 @@ pub fn filter_dirs(path: &Path) -> bool { | |
"src/bootstrap/target", | ||
"vendor", | ||
]; | ||
let command = | ||
Command::new("git").args(["ls-files", ".", "--exclude-standard", "--others"]).output(); | ||
if let Ok(output) = command { | ||
let stdout: Vec<&str> = | ||
String::from_utf8_lossy(&output.stdout).split('\n').into_iter().collect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: no need to collect when you iterate over it below |
||
for line in stdout { | ||
if skip.contains(&line) { | ||
skip.remove(skip.iter().position(|x| **x = line)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this just add each line of stdout to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue (unless I'm interpreting it wrong) says that you need to remove these elements from the skip array. But, that could be wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The existing |
||
} | ||
} | ||
} | ||
skip.iter().any(|p| path.ends_with(p)) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work properly if tidy is run from a subdirectory. Maybe this could be combined with
git rev-parse --show-toplevel
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
ls-files
will return each untracked file in a directory rather than the directory itself. I think--directory
is the flag you want to prevent recursing into untracked dirsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the command that was posted in the linked issue, so I wasn't sure. I'll look into it.