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

Method count_commits

atomic-cli/src/commands/git/import.rs:640–693  ·  view source on GitHub ↗

Count the commits a real import would create, for dry-run mode. In incremental mode this applies the exact same skip rules as the real import — already-imported SHAs and self-pushed commits whose view state is already present — via [`incremental_import_skips`], so the forecast matches what the import would actually bring in.

(
        &self,
        git_repo: &GitRepository,
        head_oid: git2::Oid,
        imported_shas: &HashSet<String>,
        known_states: &HashSet<atomic_core::types::Merkle>,
        target_view

Source from the content-addressed store, hash-verified

638 /// is already present — via [`incremental_import_skips`], so the forecast
639 /// matches what the import would actually bring in.
640 fn count_commits(
641 &self,
642 git_repo: &GitRepository,
643 head_oid: git2::Oid,
644 imported_shas: &HashSet<String>,
645 known_states: &HashSet<atomic_core::types::Merkle>,
646 target_view: &str,
647 mainline_only: bool,
648 ) -> CliResult<usize> {
649 let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError {
650 message: format!("Failed to create revwalk: {}", e),
651 })?;
652
653 revwalk.push(head_oid).map_err(|e| CliError::GitError {
654 message: format!("Failed to push HEAD to revwalk: {}", e),
655 })?;
656
657 if mainline_only {
658 revwalk
659 .simplify_first_parent()
660 .map_err(|e| CliError::GitError {
661 message: format!("Failed to simplify revwalk to first-parent history: {}", e),
662 })?;
663 }
664
665 revwalk
666 .set_sorting(Sort::TOPOLOGICAL | Sort::REVERSE)
667 .map_err(|e| CliError::GitError {
668 message: format!("Failed to set sorting: {}", e),
669 })?;
670
671 let mut count = 0;
672 for oid_result in revwalk {
673 let oid = oid_result.map_err(|e| CliError::GitError {
674 message: format!("Revwalk error: {}", e),
675 })?;
676
677 if self.incremental {
678 let sha = oid.to_string();
679 let commit = git_repo.find_commit(oid).map_err(|e| CliError::GitError {
680 message: format!("Failed to load commit {}: {}", sha, e),
681 })?;
682 let message = commit.message().unwrap_or("");
683 if incremental_import_skips(&sha, message, imported_shas, target_view, known_states)
684 {
685 continue;
686 }
687 }
688
689 count += 1;
690 }
691
692 Ok(count)
693 }
694
695 /// Classify the commits an incremental import would bring in and print a
696 /// per-shape recommendation (SPEC §4.4). Purely advisory — writes nothing.

Callers 1

run_importMethod · 0.80

Calls 3

incremental_import_skipsFunction · 0.85
pushMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected