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

Method restore_operation

atomic-repository/src/repository/operation.rs:854–939  ·  view source on GitHub ↗

Re-project the verified state selected by an earlier reachable operation.

(
        &mut self,
        working_copy: WorkingCopyId,
        target: OperationId,
    )

Source from the content-addressed store, hash-verified

852
853 /// Re-project the verified state selected by an earlier reachable operation.
854 pub fn restore_operation(
855 &mut self,
856 working_copy: WorkingCopyId,
857 target: OperationId,
858 ) -> Result<OperationId, RepositoryError> {
859 let scope = OperationScope::WorkingCopy(working_copy);
860 let current_head = self.sole_operation_head(scope)?;
861 let history = self.operation_log(scope, None, false)?;
862 if !history
863 .entries
864 .iter()
865 .any(|entry| entry.operation.id() == target)
866 {
867 return Err(RepositoryError::OperationNotReachable {
868 operation: target.to_string(),
869 scope: scope.to_string(),
870 });
871 }
872 let details = self.operation_details(target)?;
873 if details.verification != OperationVerificationState::Verified {
874 return Err(RepositoryError::OperationNotVerified {
875 operation: target.to_string(),
876 });
877 }
878 if !details.operation.payload().delta.metadata.is_empty() {
879 return self.append_related_metadata_operation(
880 working_copy,
881 &details.operation,
882 OperationKind::Restore,
883 OperationRelation::Restore { target },
884 false,
885 );
886 }
887 let view = details
888 .operation
889 .payload()
890 .delta
891 .after
892 .view
893 .as_ref()
894 .map(|view| view.name.clone())
895 .ok_or_else(|| {
896 operation_not_reversible(
897 &details.operation,
898 "the operation does not carry a selected view state",
899 )
900 })?;
901 let expected_state = details
902 .operation
903 .payload()
904 .delta
905 .after
906 .view
907 .as_ref()
908 .map(|state| state.state)
909 .ok_or_else(|| {
910 operation_not_reversible(
911 &details.operation,

Calls 15

WorkingCopyInterface · 0.85
operation_not_reversibleFunction · 0.85
sole_operation_headMethod · 0.80
operation_logMethod · 0.80
operation_detailsMethod · 0.80
as_refMethod · 0.80
read_txnMethod · 0.80
iterMethod · 0.45
idMethod · 0.45
is_emptyMethod · 0.45