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

Method phase2_write

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

Phase 2: Write changes sequentially with hash chaining.

(
        &self,
        repo: &mut Repository,
        commits: &[ParsedCommit],
        line_index: &mut ImportLineIndex,
    )

Source from the content-addressed store, hash-verified

2569
2570 /// Phase 2: Write changes sequentially with hash chaining.
2571 fn phase2_write(
2572 &self,
2573 repo: &mut Repository,
2574 commits: &[ParsedCommit],
2575 line_index: &mut ImportLineIndex,
2576 ) -> CliResult<(WriteStats, Vec<ImportedCommitInfo>)> {
2577 let mut stats = WriteStats::default();
2578 let mut imported_commits = Vec::new();
2579 let total = commits.len();
2580 let phase2_start = Instant::now();
2581 let mut batch_start = Instant::now();
2582
2583 for (idx, parsed) in commits.iter().enumerate() {
2584 // Commits created by `atomic git push` whose referenced view
2585 // state is already present add nothing — skip them entirely.
2586 if should_skip_self_push(parsed, &self.options) {
2587 stats.self_push_skipped += 1;
2588 continue;
2589 }
2590
2591 // Progress reporting with per-batch timing
2592 if total > 100 && idx % 100 == 0 {
2593 if idx == 0 {
2594 print_info(&format!(" Writing {}/{}...", idx, total));
2595 } else {
2596 let batch_elapsed = batch_start.elapsed();
2597 let total_elapsed = phase2_start.elapsed();
2598 let avg_per_commit = total_elapsed.as_secs_f64() / idx as f64;
2599 print_info(&format!(
2600 " Writing {}/{}... (last 100: {:.2}s, avg: {:.1}ms/commit)",
2601 idx,
2602 total,
2603 batch_elapsed.as_secs_f64(),
2604 avg_per_commit * 1000.0,
2605 ));
2606 }
2607 batch_start = Instant::now();
2608 }
2609
2610 // Write the change
2611 match self.write_commit(repo, parsed, line_index) {
2612 Ok(info) => {
2613 if parsed.is_empty {
2614 stats.empty_commits += 1;
2615 } else if parsed.is_merge {
2616 stats.merge_commits += 1;
2617 } else {
2618 stats.changes_written += 1;
2619 }
2620 stats.files_processed += parsed.files.len();
2621 imported_commits.push(info);
2622 }
2623 Err(e) => {
2624 print_warning(&format!("Failed to write {}: {}", parsed.short_sha, e));
2625 }
2626 }
2627 }
2628

Callers 1

import_branchMethod · 0.80

Calls 13

should_skip_self_pushFunction · 0.85
print_infoFunction · 0.85
print_warningFunction · 0.85
write_commitMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
rootMethod · 0.45
modifiedMethod · 0.45
replaceMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected