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

Method count_commits

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

401 /// is already present — via [`incremental_import_skips`], so the forecast
402 /// matches what the import would actually bring in.
403 fn count_commits(
404 &self,
405 git_repo: &GitRepository,
406 head_oid: git2::Oid,
407 imported_shas: &HashSet<String>,
408 known_states: &HashSet<atomic_core::types::Merkle>,
409 target_view: &str,
410 mainline_only: bool,
411 ) -> CliResult<usize> {
412 let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError {
413 message: format!("Failed to create revwalk: {}", e),
414 })?;
415
416 revwalk.push(head_oid).map_err(|e| CliError::GitError {
417 message: format!("Failed to push HEAD to revwalk: {}", e),
418 })?;
419
420 if mainline_only {
421 revwalk
422 .simplify_first_parent()
423 .map_err(|e| CliError::GitError {
424 message: format!("Failed to simplify revwalk to first-parent history: {}", e),
425 })?;
426 }
427
428 revwalk
429 .set_sorting(Sort::TOPOLOGICAL | Sort::REVERSE)
430 .map_err(|e| CliError::GitError {
431 message: format!("Failed to set sorting: {}", e),
432 })?;
433
434 let mut count = 0;
435 for oid_result in revwalk {
436 let oid = oid_result.map_err(|e| CliError::GitError {
437 message: format!("Revwalk error: {}", e),
438 })?;
439
440 if self.incremental {
441 let sha = oid.to_string();
442 let commit = git_repo.find_commit(oid).map_err(|e| CliError::GitError {
443 message: format!("Failed to load commit {}: {}", sha, e),
444 })?;
445 let message = commit.message().unwrap_or("");
446 if incremental_import_skips(&sha, message, imported_shas, target_view, known_states)
447 {
448 continue;
449 }
450 }
451
452 count += 1;
453 }
454
455 Ok(count)
456 }
457
458 /// Classify the commits an incremental import would bring in and print a
459 /// per-shape recommendation (SPEC §4.4). Purely advisory — writes nothing.

Callers 1

runMethod · 0.80

Calls 3

incremental_import_skipsFunction · 0.85
pushMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected