(
detected: &atomic_core::record::workflow::DetectedFile,
state: &atomic_core::pristine::span_patch_storage::SpanRecordState,
namespace_dependencies: Vec<Hash>,
new: &[u8],
trunk:
| 167 | } |
| 168 | |
| 169 | fn 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 trunk.is_none() && cfg!(not(unix)) { |
| 193 | return Err("projected semantic recording is not supported on this platform".into()); |
| 194 | } |
| 195 | if atomic_core::record::workflow::compare::detect_encoding(old) |
| 196 | == atomic_core::change::Encoding::Binary |
| 197 | || atomic_core::record::workflow::compare::detect_encoding(new) |
| 198 | == atomic_core::change::Encoding::Binary |
| 199 | { |
| 200 | return Err("span recording cannot yet change between text and binary".into()); |
| 201 | } |
| 202 | let old_lines = Line::from_bytes(old); |
| 203 | let new_lines = Line::from_bytes(new); |
| 204 | if trunk.is_some() && old_lines.len() != branches.len() { |
| 205 | return Err("semantic lines do not match the span baseline".into()); |
| 206 | } |
| 207 | let projection = if trunk.is_none() { |
| 208 | Some( |
| 209 | state |
| 210 | .semantic_snapshot() |
| 211 | .map_err(|error| error.to_string())?, |
| 212 | ) |
| 213 | } else { |
| 214 | None |
| 215 | }; |
| 216 | let mut old_offsets = vec![0usize]; |
| 217 | for line in &old_lines { |
| 218 | old_offsets.push(old_offsets.last().copied().unwrap() + line.len()); |
| 219 | } |
| 220 | let mut new_offsets = vec![0usize]; |
| 221 | for line in &new_lines { |
| 222 | new_offsets.push(new_offsets.last().copied().unwrap() + line.len()); |
| 223 | } |
| 224 | let mut blocks = Vec::new(); |
| 225 | let mut open: Option<(usize, usize)> = None; |
| 226 | let (mut old_cursor, mut new_cursor) = (0usize, 0usize); |
no test coverage detected