| 230 | } |
| 231 | |
| 232 | fn files(change: &Change, show_hunks: bool) -> Tree { |
| 233 | let directories: BTreeSet<_> = change |
| 234 | .hashed |
| 235 | .hunks |
| 236 | .iter() |
| 237 | .filter_map(|op| match op { |
| 238 | GraphOp::DirAdd { path, .. } |
| 239 | | GraphOp::DirDel { path, .. } |
| 240 | | GraphOp::DirUndel { path, .. } => Some(path.as_str()), |
| 241 | _ => None, |
| 242 | }) |
| 243 | .collect(); |
| 244 | let mut summaries = hunk_display_summaries(&change.hashed.hunks); |
| 245 | let mut known: BTreeSet<String> = summaries |
| 246 | .iter() |
| 247 | .map(|summary| summary.path.clone()) |
| 248 | .collect(); |
| 249 | let mut span_only = 0; |
| 250 | if change.hashed.span.as_ref().is_some_and(|patch| { |
| 251 | patch |
| 252 | .ops |
| 253 | .iter() |
| 254 | .any(|op| matches!(op, atomic_core::change::span_patch::SpanOp::Edit { .. })) |
| 255 | }) { |
| 256 | // A span edit carries its portable file identity rather than a graph |
| 257 | // hunk path. Its hashed semantic operation retains the recorded path. |
| 258 | for ops in change.file_ops() { |
| 259 | if ops.trunk_op().is_none() |
| 260 | && !ops.path().is_empty() |
| 261 | && known.insert(ops.path().to_owned()) |
| 262 | { |
| 263 | summaries.push(HunkDisplaySummary { |
| 264 | symbol: "~", |
| 265 | path: ops.path().to_owned(), |
| 266 | info: "(span edits)".into(), |
| 267 | }); |
| 268 | span_only += 1; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | let mut paths = PathTree::default(); |
| 273 | for summary in summaries { |
| 274 | let mut node = &mut paths; |
| 275 | // Atomic paths use '/', including when the CLI runs on Windows. Do not |
| 276 | // interpret platform-specific separators or consult the working copy. |
| 277 | for part in summary.path.split('/') { |
| 278 | node = node.children.entry(part.to_owned()).or_default(); |
| 279 | } |
| 280 | node.directory = directories.contains(summary.path.as_str()); |
| 281 | node.summary = Some(summary); |
| 282 | } |
| 283 | let mut section = Tree::new(format!( |
| 284 | "Files changed: {}", |
| 285 | count_unique_paths(&change.hashed.hunks) + span_only |
| 286 | )); |
| 287 | section.children = path_nodes(paths, show_hunks); |
| 288 | section |
| 289 | } |