Skip to content

Commit

Permalink
Sort output files by input paths if --isolate is used
Browse files Browse the repository at this point in the history
Consider the following command:

    fclones group --isolate /path3 /path2 /path1

In this case each file group will be first sorted internally
the same way as the input paths. Then files within each
subgroup are sorted lexicographically. Example:

49165422e775f631cca3b09124f8ee89, 6274 B (6.3 KB) * 7:
    /path3/A
    /path3/B
    /path3/C
    /path2/A
    /path2/AA
    /path1/A
    /path1/B
  • Loading branch information
pkolaczk committed Mar 18, 2022
1 parent 67d55aa commit 9f0a8cb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ impl<F: AsPath> FileGroup<F> {
FileSubGroup::group(&self.files, &filter.root_paths).len()
}
}

/// Sorts the files by their path names.
/// If filter requires grouping by roots, then groups are kept together.
pub fn sort(&mut self, root_paths: &[Path]) {
self.files.sort_by(|f1, f2| f1.path().cmp(f2.path()));
if !root_paths.is_empty() {
self.files = FileSubGroup::group(self.files.drain(..), root_paths)
.into_iter()
.flat_map(|g| g.files)
.collect()
}
}
}

/// A subgroup of identical files, typically smaller than a `FileGroup`.
Expand Down Expand Up @@ -1043,7 +1055,9 @@ pub fn group_files(config: &GroupConfig, log: &Log) -> Result<Vec<FileGroup<Path
.collect();
groups.retain(|g| g.files.len() < ctx.config.rf_under());
groups.par_sort_by_key(|g| Reverse((g.file_len, g.file_hash)));
groups.par_iter_mut().for_each(|g| g.files.sort());
groups
.par_iter_mut()
.for_each(|g| g.sort(&ctx.group_filter.root_paths));
Ok(groups)
}

Expand Down

0 comments on commit 9f0a8cb

Please sign in to comment.