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

Method try_squash_insert

atomic-cli/src/commands/git/parallel.rs:5516–5625  ·  view source on GitHub ↗

Attempt to represent an atomic-origin squash commit by inserting its original change records into the target view instead of writing a new squash change (SPEC §4). Verifies that the insert reproduces the git tree for the touched paths; on divergence or missing originals it rolls back and skips the commit (SPEC §5, decision D1-A).

(
        &self,
        repo: &mut Repository,
        parsed: &ParsedCommit,
    )

Source from the content-addressed store, hash-verified

5514 /// tree for the touched paths; on divergence or missing originals it rolls
5515 /// back and skips the commit (SPEC §5, decision D1-A).
5516 fn try_squash_insert(
5517 &self,
5518 repo: &mut Repository,
5519 parsed: &ParsedCommit,
5520 ) -> CliResult<SquashDecision> {
5521 use atomic_repository::InsertOptions;
5522
5523 // Merges are handled by the normal path + the phase-3 merge tag.
5524 if parsed.is_merge {
5525 return Ok(SquashDecision::NotSquash);
5526 }
5527
5528 // Must carry Atomic-Changes trailers to be an atomic-origin squash.
5529 let message = parsed.full_message();
5530 let original_hashes = match parse_atomic_changes_trailer(&message) {
5531 Some(h) => h,
5532 None => return Ok(SquashDecision::NotSquash),
5533 };
5534 let pr_number = parse_pr_number(&message);
5535
5536 // Resolve every original to a Hash and confirm it exists locally. A
5537 // missing original means we cannot reconstruct the aggregate — skip and
5538 // advise `atomic pull` rather than fabricate a squash change (SPEC §5).
5539 let mut parsed_hashes: Vec<ContentHash> = Vec::with_capacity(original_hashes.len());
5540 for h in &original_hashes {
5541 match ContentHash::from_base32(h.as_bytes()) {
5542 Some(hash) if repo.has_change(&hash) => parsed_hashes.push(hash),
5543 _ => {
5544 print_warning(&format!(
5545 "Squash {} references change {} which is not present locally; \
5546 skipping (run `atomic pull` to fetch it, then re-import).",
5547 parsed.short_sha, h
5548 ));
5549 return Ok(SquashDecision::Skipped);
5550 }
5551 }
5552 }
5553
5554 let target = self.options.target_view.clone();
5555
5556 // Insert the originals (with dependency closure) into the target view.
5557 // Track exactly which changes we newly added, for rollback on divergence.
5558 let mut newly_applied: Vec<ContentHash> = Vec::new();
5559 for hash in &parsed_hashes {
5560 let options = InsertOptions::default()
5561 .view(target.clone())
5562 .apply_deps(true);
5563 match repo.insert_change_rec(hash, options) {
5564 Ok(outcome) => {
5565 newly_applied.extend(outcome.stats.applied_hashes.iter().copied());
5566 }
5567 Err(e) => {
5568 print_warning(&format!(
5569 "Squash {}: failed to insert original {}: {}; skipping.",
5570 parsed.short_sha,
5571 &hash.to_base32()[..12],
5572 e
5573 ));

Callers 1

phase2_writeMethod · 0.80

Calls 15

parse_pr_numberFunction · 0.85
print_warningFunction · 0.85
rollback_insertsFunction · 0.85
full_messageMethod · 0.80
apply_depsMethod · 0.80
insert_change_recMethod · 0.80
extendMethod · 0.80
lastMethod · 0.80
index_git_shaMethod · 0.80

Tested by

no test coverage detected