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

Method apply_commit

atomic-cli/src/commands/git/parallel.rs:1499–1661  ·  view source on GitHub ↗
(
        &mut self,
        parsed: &ParsedCommit,
        git: Option<&GitRepository>,
    )

Source from the content-addressed store, hash-verified

1497 }
1498
1499 fn apply_commit(
1500 &mut self,
1501 parsed: &ParsedCommit,
1502 git: Option<&GitRepository>,
1503 ) -> CliResult<(ProjectTree, VerifiedProspectiveEquivalence)> {
1504 if let Some(parent) = parsed.parent_tree_oid {
1505 if let Some(project) = self.manifests.get(&parent) {
1506 self.entries = project
1507 .manifest
1508 .entries
1509 .iter()
1510 .cloned()
1511 .map(|entry| (entry.path.clone(), entry))
1512 .collect();
1513 } else {
1514 // CB-9B review B4: the parent's manifest is not cached — the
1515 // baseline is the parent commit's ACTUAL Git tree, not the
1516 // ambient view state. Seeding from the current view here
1517 // kept rewritten-away content alive (e.g. an intermediate
1518 // the squash cancels), so the folded prospective tree
1519 // diverged from the commit's verified Git tree and the
1520 // import refused (or published a diverged boundary). The
1521 // parent tree is the commit's exact parent interpretation.
1522 let Some(git) = git else {
1523 return Err(git_error(
1524 "commit's parent tree is not cached and no Git object database is \
1525 available to reconstruct it; refusing to fold a prospective state \
1526 from stale ambient entries",
1527 ));
1528 };
1529 let tree = git.find_tree(parent).map_err(|error| {
1530 git_error(format!("cannot read parent Git tree {parent}: {error}"))
1531 })?;
1532 self.entries = repository_entries_from_git_tree(git, tree, &self.policy)?;
1533 }
1534 } else {
1535 self.entries.clear();
1536 }
1537
1538 // Two phases: every path the commit vacates (rename sources,
1539 // deletions) leaves the fold before any insertion, so a rename chain
1540 // or swap (`a→b`, `c→a`) folds the same whatever order libgit2 emits
1541 // the deltas in.
1542 for file in &parsed.files {
1543 let vacated = match file.operation {
1544 FileOperation::Renamed => file.old_path.as_deref(),
1545 FileOperation::Deleted => Some(file.path.as_str()),
1546 _ => None,
1547 };
1548 if let Some(vacated) = vacated {
1549 self.entries.remove(
1550 &RepoPath::from_bytes(vacated.as_bytes())
1551 .map_err(|e| git_error(format!("invalid Git path '{vacated}': {e}")))?,
1552 );
1553 }
1554 }
1555 for file in &parsed.files {
1556 if file.operation == FileOperation::Deleted {

Calls 15

tagged_oid_from_hexFunction · 0.85
import_expected_tree_oidFunction · 0.85
exclusionMethod · 0.80
git_errorFunction · 0.70
git_object_idFunction · 0.70
getMethod · 0.65
clearMethod · 0.65
removeMethod · 0.65
collectMethod · 0.45
iterMethod · 0.45