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

Method count_commits

atomic-cli/src/commands/git/import.rs:647–700  ·  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

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