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

Method count_commits

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

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

Callers 1

runMethod · 0.80

Calls 2

pushMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected