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

Function publish

atomic-cli/src/commands/git/binding.rs:260–430  ·  view source on GitHub ↗
(key_file: PathBuf, with_changes_pack: bool, with_conflicts_pack: bool)

Source from the content-addressed store, hash-verified

258}
259
260fn publish(key_file: PathBuf, with_changes_pack: bool, with_conflicts_pack: bool) -> CliResult<()> {
261 let keypair = load_signing_key(&key_file)?;
262 let root = find_repository_root()?;
263 let mut repo = Repository::open(root.clone()).map_err(CliError::from)?;
264 let workspace = enter_workspace(&mut repo, atomic_repository::WorkspaceTxnMode::Reconcile)?;
265 let working_copy = workspace.working_copy();
266 let view_name = repo
267 .desired_view_name(working_copy)
268 .map_err(CliError::from)?;
269
270 let git = open_git(&root)?;
271 let head = git
272 .head()
273 .ok()
274 .and_then(|head| head.target())
275 .ok_or_else(|| {
276 CliError::Repository(atomic_repository::RepositoryError::InvalidOperation {
277 message: "binding publish requires an attached Git HEAD commit".to_string(),
278 })
279 })?;
280 let commit = git
281 .find_commit(head)
282 .map_err(|error| git_map(error.to_string()))?;
283 let raw_commit = git
284 .odb()
285 .map_err(|error| git_map(error.to_string()))?
286 .read(head)
287 .map_err(|error| git_map(error.to_string()))?
288 .data()
289 .to_vec();
290 let object_format = match head.as_bytes().len() {
291 20 => GitObjectFormat::Sha1,
292 32 => GitObjectFormat::Sha256,
293 other => return Err(git_map(format!("unexpected HEAD OID width {other}"))),
294 };
295
296 // Graph-derived identities: additive SetId v1, the Merkle state, and the
297 // effective closure in view-log order. Snapshots and private material
298 // never enter this payload.
299 let identity = repo.view_identity(&view_name).map_err(CliError::from)?;
300 let ordered_changes: Vec<atomic_core::Hash> = repo
301 .effective_history(Some(&view_name))
302 .map_err(CliError::from)?
303 .iter()
304 .map(|entry| entry.hash)
305 .collect();
306 let operation = sole_working_copy_operation(&repo, working_copy)?;
307
308 let tree_hex = git
309 .find_commit(head)
310 .map_err(|error| git_map(error.to_string()))?
311 .tree_id()
312 .to_string();
313 let mut payload = GitStateBindingPayload {
314 version: atomic_repository::git_binding::BINDING_VERSION,
315 git_object_format: object_format,
316 git_commit: GitOid::from_hex(&head.to_string()).map_err(git_map)?,
317 git_tree: GitOid::from_hex(&tree_hex).map_err(git_map)?,

Callers 1

runMethod · 0.70

Calls 15

load_signing_keyFunction · 0.85
find_repository_rootFunction · 0.85
openFunction · 0.85
RepositoryClass · 0.85
binding_loss_notesFunction · 0.85
parents_fromFunction · 0.85
print_successFunction · 0.85
desired_view_nameMethod · 0.80
view_identityMethod · 0.80

Tested by

no test coverage detected