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

Function globalize_hunk

atomic-core/src/record/workflow/globalize/hunk.rs:110–161  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

108/// a middle Insert cannot be performed granularly (single-vertex file) and
109/// must be escalated to a whole-file Replace
110pub 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>>>>
119where
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)

Callers 1

globalize_recorded_fileFunction · 0.85

Calls 4

globalize_insertFunction · 0.85
globalize_replaceFunction · 0.85
globalize_deleteFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected