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

Function write_new_vertex_with_frontier

atomic-core/src/apply/insertion.rs:113–244  ·  view source on GitHub ↗

Write a new vertex using repository-verified causal knowledge.

(
    txn: &mut CachedWriteGraphTxn<'_, '_>,
    workspace: &mut Workspace,
    change_id: NodeId,
    insertion: &Insertion<Option<Hash>>,
    change: &Change,
    verified_frontier: &VerifiedCausalF

Source from the content-addressed store, hash-verified

111
112/// Write a new vertex using repository-verified causal knowledge.
113pub fn write_new_vertex_with_frontier(
114 txn: &mut CachedWriteGraphTxn<'_, '_>,
115 workspace: &mut Workspace,
116 change_id: NodeId,
117 insertion: &Insertion<Option<Hash>>,
118 change: &Change,
119 verified_frontier: &VerifiedCausalFrontier,
120 detect_conflicts: bool,
121) -> Result<(), LocalApplyError> {
122 // Create the new span
123 let node = GraphNode {
124 change: change_id,
125 start: insertion.start,
126 end: insertion.end,
127 };
128
129 // Clear workspace context for this span
130 workspace.clear_context();
131
132 // The file this span belongs to, for INODE_GRAPH indexing and for
133 // inode-scoped context resolution.
134 let resolved_inode = resolve_inode(txn, &insertion.inode, change_id)?;
135
136 // Fast path for the common "append one more line from this same change"
137 // pattern used by large FileAdd chains. The predecessor is a vertex we
138 // already inserted in this change, there are no successors, and the new
139 // edge can be wired directly without re-running the general context walk.
140 if insertion.successors.is_empty() && insertion.predecessors.len() == 1 {
141 let internal_pos = resolve_position(txn, &insertion.predecessors[0], change_id)?;
142 if let Some(up_vertex) = workspace.get_current_vertex(internal_pos, true) {
143 let up_flag = insertion.flag | EdgeFlags::BLOCK;
144 add_edge_with_reverse(txn, resolved_inode, up_flag, up_vertex, node, change_id)?;
145 workspace.add_up_context(up_vertex.end_pos());
146 workspace.add_up_context_vertex(up_vertex);
147 workspace.register_current_vertex(node);
148 return Ok(());
149 }
150 }
151
152 // Resolve predecessors: vertices that come BEFORE this new content.
153 // Uses the unified overlay-aware resolver so Local stacks can find
154 // vertices written to GRAPH earlier in the same change.
155 for up_pos in &insertion.predecessors {
156 let internal_pos = resolve_position(txn, up_pos, change_id)?;
157 let up_vertex = context_vertex(txn, workspace, resolved_inode, internal_pos, true)?;
158 // Store the end position (where new content connects)
159 workspace.add_up_context(up_vertex.end_pos());
160 workspace.add_up_context_vertex(up_vertex);
161
162 // Check if predecessors was deleted by an unknown change
163 if detect_conflicts {
164 check_deleted_context(txn, workspace, change, verified_frontier, up_vertex)?;
165 }
166 }
167
168 let exact_inode_successor = resolve_position(txn, &insertion.inode, change_id).ok();
169
170 // Resolve successors: vertices that come AFTER this new content.

Callers 2

write_new_vertexFunction · 0.85
write_hunkFunction · 0.85

Calls 15

resolve_inodeFunction · 0.85
resolve_positionFunction · 0.85
add_edge_with_reverseFunction · 0.85
context_vertexFunction · 0.85
check_deleted_contextFunction · 0.85
clear_contextMethod · 0.80
get_current_vertexMethod · 0.80
add_up_contextMethod · 0.80
add_up_context_vertexMethod · 0.80
add_down_contextMethod · 0.80

Tested by

no test coverage detected