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

Function setup_publisher

atomic-cli/tests/it/git_binding_cb6c_test.rs:59–108  ·  view source on GitHub ↗

A publisher: Git baseline, imported shim baseline, three recorded changes, and a bound projection commit whose tree is the projected closure (built through the projection API — the same facts `git shim reconcile` exports).

(root: &Path, home: &Path)

Source from the content-addressed store, hash-verified

57/// and a bound projection commit whose tree is the projected closure (built
58/// through the projection API — the same facts `git shim reconcile` exports).
59fn setup_publisher(root: &Path, home: &Path) -> (git2::Oid, String) {
60 // A native Atomic repository (no Git, no Git import): every closure member
61 // is a hash-authoritative V3 change without unhashed sections, so the
62 // bounded pack can carry it (RFC §12.13), and no shim baseline is needed.
63 assert_success(&atomic(root, home, &["init"]), "atomic init");
64
65 for (name, message) in [("a.txt", "one"), ("b.txt", "two"), ("c.txt", "three")] {
66 fs::write(root.join(name), format!("{message}\n")).expect("edit file");
67 assert_success(&atomic(root, home, &["add", name]), "add");
68 assert_success(&atomic(root, home, &["record", "-m", message]), "record");
69 }
70
71 // Materialize the projected closure as a real Git commit over the
72 // projected tree so the binding has a bound commit the proof can verify.
73 let project = {
74 let repo = atomic_repository::Repository::open_readonly(root).expect("open atomic");
75 let policy = atomic_repository::ConversionPolicy::new(
76 atomic_core::operation::GitHashAlgorithm::Sha1,
77 );
78 let view = repo.current_view().to_string();
79 repo.project_tree(&view, &policy).expect("project tree")
80 };
81 let git = git2::Repository::init(root).expect("init git");
82 {
83 let odb = git.odb().expect("odb");
84 for (expected, object) in project.git.objects.iter() {
85 let kind = match object.kind {
86 atomic_repository::GitObjectKind::Blob => git2::ObjectType::Blob,
87 atomic_repository::GitObjectKind::Tree => git2::ObjectType::Tree,
88 };
89 let written = odb.write(kind, &object.bytes).expect("write object");
90 assert_eq!(written.as_bytes(), expected.as_bytes());
91 }
92 }
93 let tree_oid = git2::Oid::from_bytes(project.git.root.as_bytes()).expect("tree oid");
94 let tree = git.find_tree(tree_oid).expect("find tree");
95 let signature = git2::Signature::now("Publisher", "pub@example.com").expect("signature");
96 let commit = git
97 .commit(
98 Some("refs/heads/master"),
99 &signature,
100 &signature,
101 "bound projection",
102 &tree,
103 &[],
104 )
105 .expect("bind commit");
106 git.set_head("refs/heads/master").expect("set head");
107 (commit, hex_of_oid(&project.git.root))
108}
109
110/// Assemble the bounded changes.pack for the closure from the local store.
111fn changes_pack_for(

Calls 11

hex_of_oidFunction · 0.85
project_treeMethod · 0.80
assert_successFunction · 0.70
atomicFunction · 0.70
writeFunction · 0.70
initFunction · 0.70
current_viewMethod · 0.45
iterMethod · 0.45
writeMethod · 0.45
as_bytesMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected