in src/main.rs [631:706]
fn run_fast_impl(
regex: &Regex,
matcher: &RegexMatcher,
subst: &str,
dirs: Vec<&str>,
file_set: Option<FileSet>,
hidden: bool,
changed_files: Option<Vec<PathBuf>>,
visited: Option<HashSet<PathBuf>>,
) -> Result<()> {
let walk = walk_builder_with_file_set(dirs, file_set)?
.hidden(!hidden)
.threads(min(12, num_cpus::get()))
.build_parallel();
let matcher = matcher.clone();
let visited = Arc::new(visited);
let should_record_changed_files = changed_files.is_some();
let changed_files = Arc::new(Mutex::new(changed_files.unwrap_or_else(Vec::new)));
let changed_files_inner = changed_files.clone();
walk.run(move || {
// We have to do our own changed file tracking, so don't
// enable it in our Fastmod instance.
let mut fm = Fastmod::new(true, hidden, false);
let regex = regex.clone();
let matcher = matcher.clone();
let subst = subst.to_string();
let visited = visited.clone();
let changed_files = changed_files_inner.clone();
let mut searcher = make_searcher();
Box::new(move |result| {
let dirent = match result {
Ok(d) => d,
Err(e) => {
eprintln!("Warning: {}", &e);
return WalkState::Continue;
}
};
if let Some(file_type) = dirent.file_type() {
if !file_type.is_file() {
return WalkState::Continue;
}
let path = dirent.path();
if let Some(ref visited) = *visited {
if visited.contains(path) {
return WalkState::Continue;
}
}
if !looks_like_code(path) {
return WalkState::Continue;
}
if let Some(contents) = file_contents_if_matches(&mut searcher, &matcher, path)
{
let patching_result = fm.fast_patch(®ex, &subst, path, &contents);
match patching_result {
Ok(changed_file) => {
if should_record_changed_files && changed_file {
let mut changed_files = changed_files.lock().unwrap();
changed_files.push(path.to_owned())
}
}
Err(error) => eprintln!("{}", display_warning(&error)),
}
}
}
WalkState::Continue
})
});
if should_record_changed_files {
let mut changed_files = changed_files.lock().unwrap();
(*changed_files).sort();
for file in &*changed_files {
println!("{}", file.display());
}
}
Ok(())
}