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

Method count_commits

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

Count commits for dry-run mode.

(
        &self,
        git_repo: &GitRepository,
        head_oid: git2::Oid,
        imported_shas: &HashSet<String>,
        mainline_only: bool,
    )

Source from the content-addressed store, hash-verified

343
344 /// Count commits for dry-run mode.
345 fn count_commits(
346 &self,
347 git_repo: &GitRepository,
348 head_oid: git2::Oid,
349 imported_shas: &HashSet<String>,
350 mainline_only: bool,
351 ) -> CliResult<usize> {
352 let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError {
353 message: format!("Failed to create revwalk: {}", e),
354 })?;
355
356 revwalk.push(head_oid).map_err(|e| CliError::GitError {
357 message: format!("Failed to push HEAD to revwalk: {}", e),
358 })?;
359
360 if mainline_only {
361 revwalk
362 .simplify_first_parent()
363 .map_err(|e| CliError::GitError {
364 message: format!("Failed to simplify revwalk to first-parent history: {}", e),
365 })?;
366 }
367
368 revwalk
369 .set_sorting(Sort::TOPOLOGICAL | Sort::REVERSE)
370 .map_err(|e| CliError::GitError {
371 message: format!("Failed to set sorting: {}", e),
372 })?;
373
374 let mut count = 0;
375 for oid_result in revwalk {
376 let oid = oid_result.map_err(|e| CliError::GitError {
377 message: format!("Revwalk error: {}", e),
378 })?;
379
380 if self.incremental && imported_shas.contains(&oid.to_string()) {
381 continue;
382 }
383
384 count += 1;
385 }
386
387 Ok(count)
388 }
389}
390
391impl Command for Import {

Callers 1

runMethod · 0.80

Calls 2

pushMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected