MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / from_file_ops

Method from_file_ops

atomic-core/src/change/ops.rs:1042–1107  ·  view source on GitHub ↗

Computes statistics from a list of file operations.

(file_ops: &[FileOps])

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

trunk_opMethod · 0.45
is_emptyMethod · 0.45
line_opsMethod · 0.45
operationMethod · 0.45

Tested by

no test coverage detected