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)
| 163 | /// println!("Saved change: {}", hash.to_base32()); |
| 164 | /// ``` |
| 165 | pub fn save_change(&self, change: &Change) -> Result<Hash, RepositoryError> { |
| 166 | self.require_projected_semantic_storage_capability(change)?; |
| 167 | if change.file_ops().iter().any(|ops| { |
| 168 | matches!( |
| 169 | ops.trunk_op(), |
| 170 | Some(atomic_core::crdt::TrunkOp::ProjectedSpanEdit { .. }) |
| 171 | ) |
| 172 | }) { |
| 173 | let mut bytes = Vec::new(); |
| 174 | let hash = change |
| 175 | .serialize(&mut bytes) |
| 176 | .map_err(|error| RepositoryError::Serialization(error.to_string()))?; |
| 177 | return self.save_change_bytes(&hash, &bytes, change); |
| 178 | } |
| 179 | if change.hashed.span.is_some() { |
| 180 | self.require_span_storage_capability()?; |
| 181 | } |
| 182 | self.pristine |
| 183 | .require_repository_capability(CHANGE_FORMAT_VNEXT_CAPABILITY) |
| 184 | .map_err(RepositoryError::from)?; |
| 185 | self.change_store |
| 186 | .save_change(change) |
| 187 | .map_err(|e| RepositoryError::Database(e.to_string())) |
| 188 | } |
| 189 | |
| 190 | /// Verify and store a received ATOM object without changing its identity. |
| 191 | /// |