Prepare a native remote command before its protocol mutation begins.
(
&self,
working_copy: WorkingCopyId,
kind: OperationKind,
remote: &str,
evidence: Hash,
)
| 353 | |
| 354 | /// Prepare a native remote command before its protocol mutation begins. |
| 355 | pub fn prepare_remote_operation( |
| 356 | &self, |
| 357 | working_copy: WorkingCopyId, |
| 358 | kind: OperationKind, |
| 359 | remote: &str, |
| 360 | evidence: Hash, |
| 361 | ) -> Result<PreparedRemoteOperation, RepositoryError> { |
| 362 | if !matches!(kind, OperationKind::Pull | OperationKind::Push) { |
| 363 | return Err(RepositoryError::InvalidOperation { |
| 364 | message: format!("{kind:?} is not a native remote operation kind"), |
| 365 | }); |
| 366 | } |
| 367 | let operation_lock = self.try_lock_operation(working_copy)?; |
| 368 | if let OperationHeadState::Diverged(heads) = |
| 369 | self.consolidate_operation_heads_locked(&operation_lock)? |
| 370 | { |
| 371 | return Err(RepositoryError::OperationHeadsDiverged { |
| 372 | scope: OperationScope::WorkingCopy(working_copy).to_string(), |
| 373 | heads: heads.iter().map(ToString::to_string).collect(), |
| 374 | }); |
| 375 | } |
| 376 | let state = { |
| 377 | let txn = self.pristine.read_txn().map_err(pristine_error)?; |
| 378 | let record = txn |
| 379 | .get_working_copy(working_copy) |
| 380 | .map_err(pristine_error)? |
| 381 | .ok_or(RepositoryError::WorkingCopyRecordNotFound { id: working_copy })?; |
| 382 | let view = ViewTxnT::get_view_by_id(&txn, record.desired_view) |
| 383 | .map_err(pristine_error)? |
| 384 | .ok_or_else(|| RepositoryError::InvalidRepository { |
| 385 | reason: format!( |
| 386 | "working copy {working_copy} references missing view {}", |
| 387 | record.desired_view |
| 388 | ), |
| 389 | })?; |
| 390 | RepoStateRef { |
| 391 | view: Some(atomic_core::operation::ViewStateRef { |
| 392 | name: view.name, |
| 393 | state: view.state, |
| 394 | set_id: None, |
| 395 | }), |
| 396 | working_copy: Some(working_copy_state_ref(record)), |
| 397 | git: None, |
| 398 | } |
| 399 | }; |
| 400 | let operation = self.prepare_metadata_operation( |
| 401 | &operation_lock, |
| 402 | kind, |
| 403 | None, |
| 404 | state.clone(), |
| 405 | state, |
| 406 | Vec::new(), |
| 407 | vec![ |
| 408 | evidence, |
| 409 | Hash::of(format!("atomic:remote:v1\\0{remote}").as_bytes()), |
| 410 | ], |
| 411 | ActorRef::System { |
| 412 | name: format!( |