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

Method publish

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

One prepared journal operation and one graph transaction per batch.

(&mut self, entries: &[PreparedGitGraphChange])

Source from the content-addressed store, hash-verified

728
729 /// One prepared journal operation and one graph transaction per batch.
730 pub fn publish(&mut self, entries: &[PreparedGitGraphChange]) -> Result<(), RepositoryError> {
731 let started = std::time::Instant::now();
732 let size = entries
733 .iter()
734 .try_fold(0usize, |sum, entry| sum.checked_add(entry.bytes.len()));
735 if entries.is_empty()
736 || entries.len() > self.limits.commits
737 || size.is_none_or(|bytes| bytes > self.limits.bytes)
738 {
739 return Err(invalid(
740 "stream batch exceeds its count/byte limit or is empty",
741 ));
742 }
743 let mut previous = self.last_sha.as_deref();
744 let mut unique = HashSet::new();
745 for entry in entries {
746 if entry.change.hashed.span.is_some() != self.span_mode {
747 return Err(invalid("stream change format does not match session mode"));
748 }
749 if entry.parent.as_deref() != previous || !unique.insert(&entry.sha) {
750 return Err(invalid(
751 "stream batch must follow the exact first-parent chain",
752 ));
753 }
754 previous = Some(&entry.sha);
755 }
756 let wc = self.repo.require_working_copy_id()?;
757 let lock = self.repo.try_lock_operation(wc)?;
758 if !self.base_prefix.is_empty() {
759 self.repo
760 .validate_span_git_prefix(&self.target, &self.base_prefix)?;
761 let (policy, expected) = self
762 .baseline_git_tree
763 .as_ref()
764 .expect("incremental baseline");
765 if verify_incremental_baseline(self.repo, &self.target, policy, expected)?
766 != self.retained_private
767 {
768 return Err(invalid("incremental private baseline changed"));
769 }
770 }
771 let txn = self.repo.pristine.read_txn()?;
772 let stage = txn
773 .get_view(&self.stage)?
774 .ok_or_else(|| invalid("private stream view disappeared"))?;
775 let target = txn
776 .get_view(&self.target)?
777 .ok_or_else(|| invalid("target disappeared"))?;
778 let expected_stage = self
779 .base_hashes
780 .iter()
781 .chain(&self.hashes)
782 .fold(Merkle::ZERO, |state, hash| state.next(hash));
783 if target.id != self.target_id
784 || target.change_count != self.target_count
785 || target.state != self.target_state
786 || stage.parent != Some(target.id)
787 || stage.kind != ViewScope::Draft

Calls 15

WorkingCopyInterface · 0.85
working_copy_state_refFunction · 0.85
try_lock_operationMethod · 0.80
as_refMethod · 0.80
read_txnMethod · 0.80
is_noneMethod · 0.80