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

Method from_file_ops

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

Computes statistics from a list of file operations.

(file_ops: &[FileOps])

Source from the content-addressed store, hash-verified

693
694 /// Computes statistics from a list of file operations.
695 pub fn from_file_ops(file_ops: &[FileOps]) -> Self {
696 let mut stats = Self::new();
697
698 for file in file_ops {
699 // Count file-level operations
700 match file.trunk_op() {
701 Some(TrunkOp::Create { .. }) => stats.files_created += 1,
702 Some(TrunkOp::Delete { .. }) => stats.files_deleted += 1,
703 Some(TrunkOp::Move { .. }) => stats.files_moved += 1,
704 Some(TrunkOp::Undelete { .. }) => stats.files_undeleted += 1,
705 None if !file.line_ops().is_empty() => stats.files_edited += 1,
706 None => {}
707 }
708
709 // Count line and token operations
710 for line in file.line_ops() {
711 match line.operation() {
712 BranchOp::Insert { content, .. } => {
713 stats.lines_added += 1;
714 for leaf_op in content {
715 match leaf_op {
716 LeafOp::Insert { .. } => stats.tokens_added += 1,
717 LeafOp::Delete { .. } => stats.tokens_deleted += 1,
718 LeafOp::Replace { .. } => stats.tokens_replaced += 1,
719 LeafOp::Restore { .. } => {} // Restore is rare in new lines
720 }
721 }
722 }
723 BranchOp::Delete { .. } => stats.lines_deleted += 1,
724 BranchOp::Modify {
725 new_content,
726 old_content,
727 ..
728 } => {
729 // A Modify counts as both a deletion and an addition
730 stats.lines_added += 1;
731 stats.lines_deleted += 1;
732 for leaf_op in new_content {
733 match leaf_op {
734 LeafOp::Insert { .. } => stats.tokens_added += 1,
735 LeafOp::Delete { .. } => stats.tokens_deleted += 1,
736 LeafOp::Replace { .. } => stats.tokens_replaced += 1,
737 LeafOp::Restore { .. } => {}
738 }
739 }
740 for leaf_op in old_content {
741 if let LeafOp::Delete { .. } = leaf_op {
742 stats.tokens_deleted += 1;
743 }
744 }
745 }
746 BranchOp::Restore { .. } => stats.lines_restored += 1,
747 BranchOp::Reparent { .. } => {
748 // Position-only — no content delta, doesn't count
749 // against lines_added/deleted or tokens_*.
750 }
751 }
752 }

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