| 866 | } |
| 867 | |
| 868 | pub(crate) fn hunk_display_summaries<H>(hunks: &[GraphOp<H>]) -> Vec<HunkDisplaySummary> { |
| 869 | let mut by_path: std::collections::BTreeMap<String, HunkDisplayAggregate> = |
| 870 | std::collections::BTreeMap::new(); |
| 871 | |
| 872 | for graph_op in hunks { |
| 873 | let (symbol, path) = hunk_symbol_and_path(graph_op); |
| 874 | let info = hunk_atom_info(graph_op); |
| 875 | let aggregate = by_path.entry(path).or_insert_with(|| HunkDisplayAggregate { |
| 876 | symbol, |
| 877 | total: 0, |
| 878 | infos: std::collections::BTreeMap::new(), |
| 879 | }); |
| 880 | aggregate.symbol = merge_hunk_symbols(aggregate.symbol, symbol); |
| 881 | aggregate.total += 1; |
| 882 | *aggregate.infos.entry(info).or_insert(0) += 1; |
| 883 | } |
| 884 | |
| 885 | by_path |
| 886 | .into_iter() |
| 887 | .map(|(path, aggregate)| HunkDisplaySummary { |
| 888 | symbol: aggregate.symbol, |
| 889 | path, |
| 890 | info: format_hunk_aggregate_info(aggregate.total, &aggregate.infos), |
| 891 | }) |
| 892 | .collect() |
| 893 | } |
| 894 | |
| 895 | fn merge_hunk_symbols(current: &'static str, next: &'static str) -> &'static str { |
| 896 | if current == next { |