Globalize a single built hunk into one or more graph operations. # Arguments `ctx` – globalization context (content buffer, dependencies, txn) `built` – the built hunk from the recording phase `inode` – the file's stable identifier `inode_pos` – the graph position of the file's inode vertex `content` – the hunk-specific content slice (the inserted/replace
(
ctx: &mut GlobalizeContext<'_, T>,
built: &BuiltHunk,
inode: Inode,
inode_pos: Position<NodeId>,
content: &[u8],
old_line_count: Option<usize>,
full_content: &[u8],
)
| 108 | /// a middle Insert cannot be performed granularly (single-vertex file) and |
| 109 | /// must be escalated to a whole-file Replace |
| 110 | pub fn globalize_hunk<T>( |
| 111 | ctx: &mut GlobalizeContext<'_, T>, |
| 112 | built: &BuiltHunk, |
| 113 | inode: Inode, |
| 114 | inode_pos: Position<NodeId>, |
| 115 | content: &[u8], |
| 116 | old_line_count: Option<usize>, |
| 117 | full_content: &[u8], |
| 118 | ) -> GlobalizeResult<Vec<GraphOp<Option<Hash>>>> |
| 119 | where |
| 120 | T: GraphTxnT + TreeTxnT + InodeGraphOps, |
| 121 | { |
| 122 | let local = built.local.clone(); |
| 123 | let encoding = built.encoding; |
| 124 | |
| 125 | log::debug!( |
| 126 | "globalize_hunk: kind={:?} old_start={} new_start={} new_len={} content_len={} full_content_len={} old_line_count={:?}", |
| 127 | built.kind, built.old_start, built.new_start, built.new_len, |
| 128 | content.len(), full_content.len(), old_line_count, |
| 129 | ); |
| 130 | |
| 131 | match built.kind { |
| 132 | BuiltHunkKind::Insert => { |
| 133 | // ::26 R1 fourth follow-up (2026-10-13): the positional line→vertex |
| 134 | // mapping in `classify_insert` is only provable when the alive graph |
| 135 | // holds exactly one content vertex per old-file line. Histories with |
| 136 | // many accumulated in-place edits leave extra alive vertices (diamond |
| 137 | // remnants the walk-through-dead re-attaches), so an insertion anchors |
| 138 | // at silent wrong vertices and the staged render loses content |
| 139 | // (atomicdotdev/atomic commit b110aa70: rendered 68,762 of 74,206 |
| 140 | // bytes after 71 in-place edits). When the counts diverge, escalate |
| 141 | // to the whole-file replace — every alive vertex is deleted and the |
| 142 | // full content inserted fresh per line, which renders byte-exactly |
| 143 | // regardless of the diamond structure. |
| 144 | if let Some(expected) = old_line_count { |
| 145 | let sorted = collect_sorted_content_vertices_cached(ctx, inode, inode_pos)?; |
| 146 | if sorted.len() != expected { |
| 147 | log::warn!( |
| 148 | "globalize_hunk: vertex/line divergence on {} ({} vertices for {} lines); \ |
| 149 | escalating to whole-file replace", |
| 150 | local.path, |
| 151 | sorted.len(), |
| 152 | expected |
| 153 | ); |
| 154 | return globalize_replace_whole_file( |
| 155 | ctx, |
| 156 | inode, |
| 157 | inode_pos, |
| 158 | full_content, |
| 159 | local, |
| 160 | encoding, |
| 161 | ); |
| 162 | } |
| 163 | } |
| 164 | match globalize_insert( |
| 165 | ctx, |
| 166 | built, |
| 167 | inode, |
no test coverage detected