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

Method validate_canonical

atomic-core/src/operation/mod.rs:214–270  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

212 }
213
214 pub(crate) fn validate_canonical(&self) -> Result<(), OperationCodecError> {
215 ensure_strictly_sorted(&self.parents, "operation parents")?;
216 ensure_strictly_sorted(&self.evidence, "operation evidence")?;
217 ensure_strictly_sorted(&self.lossy, "operation loss notes")?;
218 ensure_git_ref_observations_sorted(&self.git_observed)?;
219 for note in &self.lossy {
220 ensure_strictly_sorted(&note.evidence, "loss-note evidence")?;
221 }
222 for state in [&self.before, &self.delta.after] {
223 if let Some(state_working_copy) = &state.working_copy {
224 match self.working_copy {
225 Some(operation_working_copy)
226 if operation_working_copy == state_working_copy.id => {}
227 Some(operation_working_copy) => {
228 return Err(OperationCodecError::new(format!(
229 "operation working copy {operation_working_copy} disagrees with state working copy {}",
230 state_working_copy.id
231 )));
232 }
233 None => {
234 return Err(OperationCodecError::new(
235 "repository-scoped operation cannot carry working-copy state",
236 ));
237 }
238 }
239 }
240 }
241 self.delta.validate_canonical()?;
242 match (self.relation, self.kind) {
243 (Some(OperationRelation::Undo { .. }), OperationKind::Undo)
244 | (Some(OperationRelation::Restore { .. }), OperationKind::Restore)
245 | (None, _) => {}
246 (Some(OperationRelation::Undo { .. }), kind) => {
247 return Err(OperationCodecError::new(format!(
248 "undo relation is not valid for {kind:?} operations"
249 )));
250 }
251 (Some(OperationRelation::Restore { .. }), kind) => {
252 return Err(OperationCodecError::new(format!(
253 "restore relation is not valid for {kind:?} operations"
254 )));
255 }
256 }
257 match self.kind {
258 OperationKind::Anchor if !self.parents.is_empty() => Err(OperationCodecError::new(
259 "anchor operations cannot have parents",
260 )),
261 OperationKind::Anchor => Ok(()),
262 OperationKind::Consolidate if self.parents.len() < 2 => Err(OperationCodecError::new(
263 "consolidate operations require at least two parents",
264 )),
265 _ if self.parents.is_empty() => Err(OperationCodecError::new(
266 "non-anchor operations require at least one parent",
267 )),
268 _ => Ok(()),
269 }
270 }
271

Callers 6

canonicalizeMethod · 0.80
encode_operation_payloadFunction · 0.80
decode_operationFunction · 0.80
put_repo_state_deltaMethod · 0.80
read_repo_state_deltaMethod · 0.80

Calls 5

ensure_strictly_sortedFunction · 0.85
is_emptyMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected