Skip to content

Commit

Permalink
Add two more counts to output (#17)
Browse files Browse the repository at this point in the history
* Delete `cargo fmt` hook

* Simplify `WalkBuilder` config into one setting

* Report 2 more counts
  • Loading branch information
yury-fedotov authored Aug 1, 2024
1 parent e17e667 commit 063b984
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
9 changes: 0 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,3 @@ repos:
rev: v1.23.6
hooks:
- id: typos

- repo: local
hooks:
- id: cargo-fmt
name: cargo fmt
entry: cargo fmt --
language: system
types: [rust]
pass_filenames: false # This makes it a lot faster
30 changes: 27 additions & 3 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,30 @@ impl AnalysisResults {
println!("{}", format!("Elapsed time: {} ms", elapsed_ms).blue());

// Format file_count and dir_count with a thousand separators
let file_count_formatted = self
let n_files_identified_formatted = self
.complete_statistics
.n_files_analyzed
.n_files_identified
.to_formatted_string(&Locale::en);
let dir_count_formatted = self
.complete_statistics
.n_directories_visited
.to_formatted_string(&Locale::en);
let n_files_considered_formatted = self
.complete_statistics
.n_files_considered
.to_formatted_string(&Locale::en);
let n_files_hashed_formatted = self
.complete_statistics
.n_files_hashed
.to_formatted_string(&Locale::en);

println!(
"{}",
format!("Number of files analyzed: {}", file_count_formatted).green()
format!(
"Number of files identified: {}",
n_files_identified_formatted
)
.green()
);
println!(
"{}",
Expand All @@ -50,6 +62,18 @@ impl AnalysisResults {
)
.green()
);
println!(
"{}",
format!(
"Number of files considered: {}",
n_files_considered_formatted
)
.green()
);
println!(
"{}",
format!("Number of files hashed: {}", n_files_hashed_formatted).green()
);

println!();
println!("{}", "Largest files:".bold().underline().yellow());
Expand Down
27 changes: 17 additions & 10 deletions src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub struct DirectoryTraversalOutput {
}

pub struct CompleteTraversalStatistics {
pub n_files_analyzed: usize,
pub n_files_identified: usize,
pub n_files_considered: usize,
pub n_files_hashed: usize,
pub n_directories_visited: usize,
pub max_depth_visited: usize,
}
Expand All @@ -21,13 +23,11 @@ pub fn traverse_directory(
) -> DirectoryTraversalOutput {
let mut n_directories_visited = 1;
let mut max_depth_visited = 0;
let mut n_files_analyzed = 0;
let mut n_files_identified = 0;
let mut n_files_considered = 0;
let mut n_files_hashed = 0;
let file_infos: Vec<FileInfo> = WalkBuilder::new(dir)
.hidden(true)
.ignore(true)
.git_ignore(true)
.git_global(true)
.git_exclude(true)
.standard_filters(true)
.build()
.filter_map(|e| e.ok())
.filter_map(|entry| {
Expand All @@ -39,15 +39,20 @@ pub fn traverse_directory(
n_directories_visited += 1;
}
if entry.file_type().map_or(false, |ft| ft.is_file()) {
n_files_analyzed += 1;
n_files_identified += 1;
let path = entry.into_path();
if !file_extensions.is_empty()
&& !file_utils::has_allowed_extension(&path, file_extensions)
{
return None;
}
n_files_considered += 1;
let size = get_file_size(&path);
let hash = if size > *min_file_size as u64 {
let should_calculate_hash = size > *min_file_size as u64;
if should_calculate_hash {
n_files_hashed += 1;
}
let hash = if should_calculate_hash {
calculate_hash(&path).unwrap_or_else(|_| String::new())
} else {
String::new()
Expand All @@ -60,7 +65,9 @@ pub fn traverse_directory(
.collect();

let complete_statistics = CompleteTraversalStatistics {
n_files_analyzed,
n_files_identified,
n_files_considered,
n_files_hashed,
n_directories_visited,
max_depth_visited,
};
Expand Down

0 comments on commit 063b984

Please sign in to comment.