Save a change to the repository. The change is serialized and written to the `.atomic/changes/` directory using a content-addressed two-level directory structure. The change is also cached for efficient subsequent access. # Arguments `change` - The change to save # Returns The hash of the saved change, which can be used to retrieve it later. # Errors Returns an error if: - The directory can
(&self, change: &Change)
| 185 | /// println!("Saved change: {}", hash.to_base32()); |
| 186 | /// ``` |
| 187 | pub fn save_change(&self, change: &Change) -> Result<Hash, RepositoryError> { |
| 188 | self.fence_legacy_span_storage(change)?; |
| 189 | self.require_projected_semantic_storage_capability(change)?; |
| 190 | if change.file_ops().iter().any(|ops| { |
| 191 | matches!( |
| 192 | ops.trunk_op(), |
| 193 | Some(atomic_core::crdt::TrunkOp::ProjectedSpanEdit { .. }) |
| 194 | ) |
| 195 | }) { |
| 196 | let mut bytes = Vec::new(); |
| 197 | let hash = change |
| 198 | .serialize(&mut bytes) |
| 199 | .map_err(|error| RepositoryError::Serialization(error.to_string()))?; |
| 200 | return self.save_change_bytes(&hash, &bytes, change); |
| 201 | } |
| 202 | if change.hashed.span.is_some() { |
| 203 | self.require_span_storage_capability()?; |
| 204 | } |
| 205 | self.pristine |
| 206 | .require_repository_capability(CHANGE_FORMAT_VNEXT_CAPABILITY) |
| 207 | .map_err(RepositoryError::from)?; |
| 208 | self.change_store |
| 209 | .save_change(change) |
| 210 | .map_err(|e| RepositoryError::Database(e.to_string())) |
| 211 | } |
| 212 | |
| 213 | /// Verify and store a received ATOM object without changing its identity. |
| 214 | /// |