Skip to content

Commit d1cb9f9

Browse files
committed
Apply --sort-paths prior to computing diffs
This ensures that the json output is also sorted.
1 parent 393845d commit d1cb9f9

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
@@ -265,8 +265,7 @@ fn main() {
265265
.any(|diff_result| diff_result.has_reportable_change());
266266
display::json::print_directory(results, display_options.print_unchanged);
267267
} else if display_options.sort_paths {
268-
let mut result: Vec<DiffResult> = diff_iter.collect();
269-
result.sort_unstable_by(|a, b| a.display_path.cmp(&b.display_path));
268+
let result: Vec<DiffResult> = diff_iter.collect();
270269
for diff_result in result {
271270
print_diff_result(&display_options, &diff_result);
272271

@@ -748,7 +747,10 @@ fn diff_directories<'a>(
748747
// We greedily list all files in the directory, and then diff them
749748
// in parallel. This is assuming that diffing is slower than
750749
// enumerating files, so it benefits more from parallelism.
751-
let paths = relative_paths_in_either(lhs_dir, rhs_dir);
750+
let mut paths = relative_paths_in_either(lhs_dir, rhs_dir);
751+
if display_options.sort_paths {
752+
paths.sort_unstable();
753+
}
752754

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

0 commit comments

Comments
 (0)