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 | match globalize_insert( |
| 134 | ctx, |
| 135 | built, |
| 136 | inode, |
| 137 | inode_pos, |
| 138 | content, |
| 139 | old_line_count, |
| 140 | local.clone(), |
| 141 | encoding, |
| 142 | ) { |
| 143 | Ok(ops) => Ok(ops), |
| 144 | Err(e) => { |
| 145 | log::debug!( |
| 146 | "globalize_hunk: insert failed ({:?}), falling back to replace", |
| 147 | e |
| 148 | ); |
| 149 | // Middle insert into a single-vertex file — fall back to |
| 150 | // a whole-file Replace using the full file content (not |
| 151 | // just the inserted slice). |
| 152 | globalize_replace(ctx, built, inode, inode_pos, full_content, local, encoding) |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | BuiltHunkKind::Replace => { |
| 157 | globalize_replace(ctx, built, inode, inode_pos, content, local, encoding) |
| 158 | } |
| 159 | BuiltHunkKind::Delete => globalize_delete(ctx, built, inode, inode_pos, local, encoding), |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // ─────────────────────────────────────────────────────────────────────────── |
| 164 | // Insert: prepend / append (the only two safe positions) |
no test coverage detected