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

Function assemble_changes_pack

atomic-repository/src/git_binding/pack.rs:154–207  ·  view source on GitHub ↗

Assemble the optional `changes.pack` blob from candidate records. Applies the audited CB-6A Git boundary (family allowlist + content addressing), then the per-change quarantine, then the transport budgets. The result is the exact blob bytes for the binding tree.

(
    candidates: &[ObjectRecord],
    limits: &BindingPackLimits,
)

Source from the content-addressed store, hash-verified

152/// addressing), then the per-change quarantine, then the transport budgets.
153/// The result is the exact blob bytes for the binding tree.
154pub fn assemble_changes_pack(
155 candidates: &[ObjectRecord],
156 limits: &BindingPackLimits,
157) -> Result<Vec<u8>, BindingPackError> {
158 if candidates.len() > limits.max_objects {
159 return Err(BindingPackError::TooManyObjects {
160 limit: limits.max_objects,
161 found: candidates.len(),
162 });
163 }
164
165 // Audited family + content-addressing gates (CB-6A privacy boundary).
166 let allowed = binding_pack_records(candidates).map_err(|error| match error {
167 super::privacy::BindingTreeError::HashMismatch { key } => {
168 BindingPackError::HashMismatch { key }
169 }
170 other => BindingPackError::Refused {
171 detail: other.to_string(),
172 },
173 })?;
174
175 // Per-change quarantine before anything may enter Git (§12.13).
176 let total: usize = allowed.iter().map(|record| record.bytes.len()).sum();
177 if total > limits.max_decompressed_bytes {
178 return Err(BindingPackError::ObjectTooLarge {
179 key: "<pack total>".to_string(),
180 limit: limits.max_decompressed_bytes,
181 found: total,
182 });
183 }
184 for record in &allowed {
185 quarantine_change_record(record)?;
186 if record.bytes.len() > limits.max_object_bytes {
187 return Err(BindingPackError::ObjectTooLarge {
188 key: record.key.clone(),
189 limit: limits.max_object_bytes,
190 found: record.bytes.len(),
191 });
192 }
193 }
194
195 // Duplicate ids make the closure ambiguous even when byte-identical.
196 let mut seen: HashSet<&str> = HashSet::with_capacity(allowed.len());
197 for record in &allowed {
198 if !seen.insert(record.key.as_str()) {
199 return Err(BindingPackError::DuplicateObject {
200 key: record.key.clone(),
201 });
202 }
203 }
204
205 let envelope = ChangesPack::V1(ChangesPackV1 { records: allowed });
206 encode(&envelope).map_err(|error| BindingPackError::Encode(error.to_string()))
207}
208
209/// Decode a `changes.pack` blob under the transport budgets.
210///

Calls 8

binding_pack_recordsFunction · 0.85
quarantine_change_recordFunction · 0.85
encodeFunction · 0.50
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
as_strMethod · 0.45