Skip to content

Commit

Permalink
Apply --sort-paths prior to computing diffs
Browse files Browse the repository at this point in the history
This ensures that the json output is also sorted.
  • Loading branch information
yuja committed Feb 25, 2024
1 parent bb9e864 commit 3bc68d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ fn main() {
.any(|diff_result| diff_result.has_reportable_change());
display::json::print_directory(results, display_options.print_unchanged);
} else if display_options.sort_paths {
let mut result: Vec<DiffResult> = diff_iter.collect();
result.sort_unstable_by(|a, b| a.display_path.cmp(&b.display_path));
let result: Vec<DiffResult> = diff_iter.collect();
for diff_result in result {
print_diff_result(&display_options, &diff_result);

Expand Down Expand Up @@ -732,7 +731,10 @@ fn diff_directories<'a>(
// We greedily list all files in the directory, and then diff them
// in parallel. This is assuming that diffing is slower than
// enumerating files, so it benefits more from parallelism.
let paths = relative_paths_in_either(lhs_dir, rhs_dir);
let mut paths = relative_paths_in_either(lhs_dir, rhs_dir);
if display_options.sort_paths {
paths.sort_unstable();
}

paths.into_par_iter().map(move |rel_path| {
info!("Relative path is {:?} inside {:?}", rel_path, lhs_dir);
Expand Down

0 comments on commit 3bc68d4

Please sign in to comment.