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

Method phase2_write

atomic-cli/src/commands/git/parallel.rs:5271–5509  ·  view source on GitHub ↗
(
        &self,
        repo: &mut Repository,
        commits: &[VerifiedImportCommit],
        line_index: &mut ImportLineIndex,
        boundaries: &[&'static str],
        target_tip: Option<git2

Source from the content-addressed store, hash-verified

5269 /// Phase 2: Write changes sequentially with hash chaining.
5270 #[tracing::instrument(name = "write", skip_all, fields(commits = commits.len()))]
5271 fn phase2_write(
5272 &self,
5273 repo: &mut Repository,
5274 commits: &[VerifiedImportCommit],
5275 line_index: &mut ImportLineIndex,
5276 boundaries: &[&'static str],
5277 target_tip: Option<git2::Oid>,
5278 ) -> CliResult<(WriteStats, Vec<ImportedCommitInfo>)> {
5279 let working_copy = repo
5280 .require_working_copy_id()
5281 .map_err(|e| CliError::Internal(e.into()))?;
5282 let mut stats = WriteStats::default();
5283 let mut imported_commits = Vec::new();
5284 let total = commits.len();
5285 let phase2_start = Instant::now();
5286 let mut batch_start = Instant::now();
5287 let git = self.open_git_repo()?;
5288 let mut ledger = ClosureLedger::default();
5289 // The import target's full Git closure: the ancestry the walk
5290 // accumulates into the target view. Assembly exclusions whose Git
5291 // origin is inside this set are sibling legs of the same target and
5292 // are never superseded from the view (see
5293 // `supersede_exclusions_for`); origins outside it are genuinely
5294 // replaced history. A resolvable branch tip defines the closure
5295 // exactly; otherwise this run's walked commits are the best
5296 // available approximation.
5297 if let Some(tip) = target_tip {
5298 let tip_sha = tip.to_string();
5299 let closure = ledger
5300 .ancestry_of(&git, &tip_sha)
5301 .map_err(|e| CliError::GitError {
5302 message: format!("cannot read target tip {tip_sha} ancestry: {e}"),
5303 })?;
5304 ledger.target_closure = Some(closure);
5305 } else {
5306 let closure: HashSet<String> = commits
5307 .iter()
5308 .map(|candidate| candidate.parsed.git_sha.clone())
5309 .collect();
5310 ledger.target_closure = Some(std::sync::Arc::new(closure));
5311 }
5312 // The last commit this batch writes verifies the whole tree even when
5313 // earlier commits verify only the paths they touch.
5314 let last_written = commits
5315 .iter()
5316 .rposition(|candidate| !should_skip_self_push(&candidate.parsed, &self.options));
5317
5318 for (idx, candidate) in commits.iter().enumerate() {
5319 let parsed = &candidate.parsed;
5320 let _commit_span = tracing::info_span!(
5321 "commit",
5322 n = idx + 1,
5323 of = total,
5324 sha = %parsed.short_sha
5325 )
5326 .entered();
5327 // Commits created by `atomic git push` whose referenced view
5328 // state is already present add nothing — skip them entirely.

Callers 1

import_prevalidatedMethod · 0.80

Calls 15

should_skip_self_pushFunction · 0.85
print_infoFunction · 0.85
canonical_tree_pathFunction · 0.85
open_git_repoMethod · 0.80
ancestry_ofMethod · 0.80
try_squash_insertMethod · 0.80
verified_binding_forMethod · 0.80
ensure_union_stateMethod · 0.80
is_noneMethod · 0.80
git_commit_closureMethod · 0.80

Tested by

no test coverage detected