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

Method finish_with_guard

atomic-repository/src/repository/git_stream.rs:980–1200  ·  view source on GitHub ↗

Check an external observation while holding the operation lock before preparing the final promotion. A failed check leaves the staged changes private and does not start a target-view operation.

(
        self,
        project: &ProjectTree,
        proof: &VerifiedProspectiveEquivalence,
        guard: F,
    )

Source from the content-addressed store, hash-verified

978 /// preparing the final promotion. A failed check leaves the staged changes
979 /// private and does not start a target-view operation.
980 pub fn finish_with_guard<F>(
981 self,
982 project: &ProjectTree,
983 proof: &VerifiedProspectiveEquivalence,
984 guard: F,
985 ) -> Result<GitStreamOutcome, RepositoryError>
986 where
987 F: FnOnce() -> Result<(), RepositoryError>,
988 {
989 let started = std::time::Instant::now();
990 if self.hashes.is_empty() {
991 return Err(invalid("empty stream has no new commits to promote"));
992 }
993 if project.git.root != *proof.expected_git_tree()
994 || project.manifest.root() != *proof.manifest_root()
995 {
996 return Err(invalid("stream final manifest/proof mismatch"));
997 }
998 let last_hash = self
999 .last_hash
1000 .ok_or_else(|| invalid("empty stream has no final tip"))?;
1001 let last = self.repo.load_change(&last_hash)?;
1002 let mut expected = BTreeMap::new();
1003 for entry in &project.manifest.entries {
1004 if entry.disposition != super::ManifestDisposition::Included {
1005 continue;
1006 }
1007 let path = match std::str::from_utf8(entry.path.as_bytes()) {
1008 Ok(path) => crate::canonical_path_identity(path),
1009 Err(_) => crate::escape_repo_path(entry.path.as_bytes()),
1010 };
1011 expected.insert(
1012 path,
1013 StagedPathExpectation {
1014 bytes: entry.repository_bytes.to_vec(),
1015 mode: entry.mode,
1016 kind: entry.kind,
1017 },
1018 );
1019 }
1020 for (path, retained) in &self.retained_private {
1021 if expected.insert(path.clone(), retained.clone()).is_some() {
1022 return Err(invalid("Git target collides with a retained private path"));
1023 }
1024 }
1025 let expectation = StagedExpectation {
1026 paths: Vec::new(),
1027 tree: Some(StagedTreeExpectation {
1028 entries: expected,
1029 // Full closure verification below checks every inherited
1030 // semantic path; an empty Git tip need not invent FileOps.
1031 semantic_paths: Vec::new(),
1032 verify_paths: None,
1033 semantic_verify_paths: None,
1034 }),
1035 };
1036 let wc = self.repo.require_working_copy_id()?;
1037 let lock = self.repo.try_lock_operation(wc)?;

Callers 2

finishMethod · 0.80

Calls 15

canonical_path_identityFunction · 0.85
escape_repo_pathFunction · 0.85
working_copy_state_refFunction · 0.85
graph_visibility_closureFunction · 0.85
try_lock_operationMethod · 0.80
as_refMethod · 0.80
read_txnMethod · 0.80

Tested by

no test coverage detected