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

Function record_span_edit

atomic-repository/src/repository/record.rs:169–405  ·  view source on GitHub ↗
(
    detected: &atomic_core::record::workflow::DetectedFile,
    state: &atomic_core::pristine::span_patch_storage::SpanRecordState,
    namespace_dependencies: Vec<Hash>,
    new: &[u8],
    trunk: 

Source from the content-addressed store, hash-verified

167}
168
169fn record_span_edit(
170 detected: &atomic_core::record::workflow::DetectedFile,
171 state: &atomic_core::pristine::span_patch_storage::SpanRecordState,
172 namespace_dependencies: Vec<Hash>,
173 new: &[u8],
174 trunk: Option<atomic_core::crdt::TrunkId>,
175 branches: &[atomic_core::crdt::BranchId],
176 algorithm: atomic_core::diff::Algorithm,
177) -> Result<atomic_core::record::workflow::RecordedFile, String> {
178 use atomic_core::change::span_patch::SpanOp;
179 use atomic_core::crdt::BranchOp;
180 use atomic_core::diff::{diff_raw, DiffOp, Line};
181 use atomic_core::record::workflow::recipes::{Recipe, RecipeContext};
182 use atomic_core::record::workflow::{DetectionKind, RecordedFile};
183 use atomic_core::types::ChangePosition;
184 let path = detected.path.as_str();
185 let inode = detected
186 .inode
187 .ok_or_else(|| "span edit has no inode".to_string())?;
188 let position = detected
189 .position
190 .ok_or_else(|| "span edit has no position".to_string())?;
191 let old = state.content.as_slice();
192 if atomic_core::record::workflow::compare::detect_encoding(old)
193 == atomic_core::change::Encoding::Binary
194 || atomic_core::record::workflow::compare::detect_encoding(new)
195 == atomic_core::change::Encoding::Binary
196 {
197 return Err("span recording cannot yet change between text and binary".into());
198 }
199 let old_lines = Line::from_bytes(old);
200 let new_lines = Line::from_bytes(new);
201 if trunk.is_some() && old_lines.len() != branches.len() {
202 return Err("semantic lines do not match the span baseline".into());
203 }
204 let projection = if trunk.is_none() {
205 Some(
206 state
207 .semantic_snapshot()
208 .map_err(|error| error.to_string())?,
209 )
210 } else {
211 None
212 };
213 let mut old_offsets = vec![0usize];
214 for line in &old_lines {
215 old_offsets.push(old_offsets.last().copied().unwrap() + line.len());
216 }
217 let mut new_offsets = vec![0usize];
218 for line in &new_lines {
219 new_offsets.push(new_offsets.last().copied().unwrap() + line.len());
220 }
221 let mut blocks = Vec::new();
222 let mut open: Option<(usize, usize)> = None;
223 let (mut old_cursor, mut new_cursor) = (0usize, 0usize);
224 let diff = diff_raw(&old_lines, &new_lines, algorithm);
225 for op in diff.ops() {
226 let (old_pos, new_pos, old_len, new_len, equal) = match *op {

Callers 1

record_with_lifecycleMethod · 0.70

Calls 15

diff_rawFunction · 0.85
is_noneMethod · 0.80
semantic_snapshotMethod · 0.80
lastMethod · 0.80
extendMethod · 0.80
authored_anchorMethod · 0.80
authored_rangesMethod · 0.80
build_opsMethod · 0.80
line_ops_mutMethod · 0.80
set_positionMethod · 0.80
set_old_line_countMethod · 0.80

Tested by

no test coverage detected