Skip to content

Commit 81f08a4

Browse files
committed
Apply --sort-paths prior to computing diffs
This ensures that the json output is also sorted.
1 parent 2b19e59 commit 81f08a4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ fn main() {
261261
.any(|diff_result| diff_result.has_reportable_change());
262262
display::json::print_directory(results, display_options.print_unchanged);
263263
} else if display_options.sort_paths {
264-
let mut result: Vec<DiffResult> = diff_iter.collect();
265-
result.sort_unstable_by(|a, b| a.display_path.cmp(&b.display_path));
264+
let result: Vec<DiffResult> = diff_iter.collect();
266265
for diff_result in result {
267266
print_diff_result(&display_options, &diff_result);
268267

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

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

0 commit comments

Comments
 (0)