Computes statistics from a list of file operations.
(file_ops: &[FileOps])
| 1025 | |
| 1026 | /// Computes statistics from a list of file operations. |
| 1027 | pub fn from_file_ops(file_ops: &[FileOps]) -> Self { |
| 1028 | let mut stats = Self::new(); |
| 1029 | |
| 1030 | for file in file_ops { |
| 1031 | // Count file-level operations |
| 1032 | match file.trunk_op() { |
| 1033 | Some(TrunkOp::Create { .. }) => stats.files_created += 1, |
| 1034 | Some(TrunkOp::Delete { .. }) => stats.files_deleted += 1, |
| 1035 | Some(TrunkOp::Move { .. }) => stats.files_moved += 1, |
| 1036 | Some(TrunkOp::Undelete { .. }) => stats.files_undeleted += 1, |
| 1037 | Some(TrunkOp::SetMode { .. }) | Some(TrunkOp::SetKind { .. }) => { |
| 1038 | stats.files_edited += 1 |
| 1039 | } |
| 1040 | Some(TrunkOp::ProjectedSpanEdit { .. }) => stats.files_edited += 1, |
| 1041 | None if !file.line_ops().is_empty() => stats.files_edited += 1, |
| 1042 | None => {} |
| 1043 | } |
| 1044 | |
| 1045 | // Count line and token operations |
| 1046 | for line in file.line_ops() { |
| 1047 | match line.operation() { |
| 1048 | BranchOp::Insert { content, .. } => { |
| 1049 | stats.lines_added += 1; |
| 1050 | for leaf_op in content { |
| 1051 | match leaf_op { |
| 1052 | LeafOp::Insert { .. } => stats.tokens_added += 1, |
| 1053 | LeafOp::Delete { .. } => stats.tokens_deleted += 1, |
| 1054 | LeafOp::Replace { .. } => stats.tokens_replaced += 1, |
| 1055 | LeafOp::Restore { .. } => {} // Restore is rare in new lines |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | BranchOp::Delete { .. } => stats.lines_deleted += 1, |
| 1060 | BranchOp::Modify { |
| 1061 | new_content, |
| 1062 | old_content, |
| 1063 | .. |
| 1064 | } => { |
| 1065 | // A Modify counts as both a deletion and an addition |
| 1066 | stats.lines_added += 1; |
| 1067 | stats.lines_deleted += 1; |
| 1068 | for leaf_op in new_content { |
| 1069 | match leaf_op { |
| 1070 | LeafOp::Insert { .. } => stats.tokens_added += 1, |
| 1071 | LeafOp::Delete { .. } => stats.tokens_deleted += 1, |
| 1072 | LeafOp::Replace { .. } => stats.tokens_replaced += 1, |
| 1073 | LeafOp::Restore { .. } => {} |
| 1074 | } |
| 1075 | } |
| 1076 | for leaf_op in old_content { |
| 1077 | if let LeafOp::Delete { .. } = leaf_op { |
| 1078 | stats.tokens_deleted += 1; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | BranchOp::Restore { .. } => stats.lines_restored += 1, |
| 1083 | BranchOp::Reparent { .. } => { |
| 1084 | // Position-only — no content delta, doesn't count |