Skip to content

Commit f4d9b39

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

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
@@ -259,8 +259,7 @@ fn main() {
259259
.any(|diff_result| diff_result.has_reportable_change());
260260
display::json::print_directory(results);
261261
} else if display_options.sort_paths {
262-
let mut result: Vec<DiffResult> = diff_iter.collect();
263-
result.sort_unstable_by(|a, b| a.display_path.cmp(&b.display_path));
262+
let result: Vec<DiffResult> = diff_iter.collect();
264263
for diff_result in result {
265264
print_diff_result(&display_options, &diff_result);
266265

@@ -775,7 +774,10 @@ fn diff_directories<'a>(
775774
// We greedily list all files in the directory, and then diff them
776775
// in parallel. This is assuming that diffing is slower than
777776
// enumerating files, so it benefits more from parallelism.
778-
let paths = relative_paths_in_either(lhs_dir, rhs_dir);
777+
let mut paths = relative_paths_in_either(lhs_dir, rhs_dir);
778+
if display_options.sort_paths {
779+
paths.sort_unstable();
780+
}
779781

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

0 commit comments

Comments
 (0)