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

Method fold

atomic-repository/src/repository/semantic_closure.rs:125–164  ·  view source on GitHub ↗

Fold one visible change's semantic ops into every trunk of the current closure. Folding the same change twice, or folding before any closure was aligned, is a no-op.

(&mut self, change_id: NodeId, change: &Change)

Source from the content-addressed store, hash-verified

123 /// current closure. Folding the same change twice, or folding before
124 /// any closure was aligned, is a no-op.
125 pub(super) fn fold(&mut self, change_id: NodeId, change: &Change) {
126 let Some(closure) = self.closures.first_mut() else {
127 return;
128 };
129 if !closure.folded.insert(change_id) {
130 return;
131 }
132 for ops in change.file_ops() {
133 if matches!(
134 ops.trunk_op(),
135 Some(atomic_core::crdt::TrunkOp::ProjectedSpanEdit { .. })
136 ) {
137 continue;
138 }
139 let trunk = resolve_trunk(change_id, ops.trunk_id());
140 let state = closure.trunks.entry(trunk).or_default();
141 for line in ops.line_ops() {
142 let branch = resolve_branch(change_id, line.branch_id());
143 match line.operation() {
144 BranchOp::Insert { after, .. } => {
145 state.alive.insert(branch, true);
146 state
147 .after
148 .insert(branch, after.map(|id| resolve_branch(change_id, id)));
149 }
150 BranchOp::Modify { .. } | BranchOp::Restore { .. } => {
151 state.alive.insert(branch, true);
152 }
153 BranchOp::Delete { .. } => {
154 state.alive.insert(branch, false);
155 }
156 BranchOp::Reparent { new_after, .. } => {
157 state
158 .after
159 .insert(branch, new_after.map(|id| resolve_branch(change_id, id)));
160 }
161 }
162 }
163 }
164 }
165
166 /// The folded state of `trunk` in the current closure; empty when the
167 /// closure never touched it.

Callers 6

publishMethod · 0.45
finish_with_guardMethod · 0.45
promote_private_stageFunction · 0.45
assert_prefixFunction · 0.45

Calls 8

resolve_trunkFunction · 0.85
resolve_branchFunction · 0.85
insertMethod · 0.45
file_opsMethod · 0.45
trunk_idMethod · 0.45
line_opsMethod · 0.45
branch_idMethod · 0.45
operationMethod · 0.45

Tested by

no test coverage detected