Collect commit OIDs in topological order (oldest first).
(
&self,
git_repo: &GitRepository,
branch_name: &str,
)
| 2515 | |
| 2516 | /// Collect commit OIDs in topological order (oldest first). |
| 2517 | fn collect_commit_oids( |
| 2518 | &self, |
| 2519 | git_repo: &GitRepository, |
| 2520 | branch_name: &str, |
| 2521 | ) -> CliResult<Vec<Oid>> { |
| 2522 | let reference = git_repo |
| 2523 | .find_branch(branch_name, git2::BranchType::Local) |
| 2524 | .map_err(|e| CliError::GitError { |
| 2525 | message: format!("Branch '{}' not found: {}", branch_name, e), |
| 2526 | })?; |
| 2527 | |
| 2528 | let target_oid = reference.get().target().ok_or_else(|| CliError::GitError { |
| 2529 | message: format!("Branch '{}' has no target commit", branch_name), |
| 2530 | })?; |
| 2531 | |
| 2532 | let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError { |
| 2533 | message: format!("Failed to create revwalk: {}", e), |
| 2534 | })?; |
| 2535 | |
| 2536 | revwalk.push(target_oid).map_err(|e| CliError::GitError { |
| 2537 | message: format!("Failed to push target to revwalk: {}", e), |
| 2538 | })?; |
| 2539 | |
| 2540 | if self.options.mainline_only { |
| 2541 | revwalk |
| 2542 | .simplify_first_parent() |
| 2543 | .map_err(|e| CliError::GitError { |
| 2544 | message: format!("Failed to simplify revwalk to first-parent history: {}", e), |
| 2545 | })?; |
| 2546 | } |
| 2547 | |
| 2548 | // Topological order, oldest first |
| 2549 | revwalk |
| 2550 | .set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::REVERSE) |
| 2551 | .map_err(|e| CliError::GitError { |
| 2552 | message: format!("Failed to set sorting: {}", e), |
| 2553 | })?; |
| 2554 | |
| 2555 | let mut oids = Vec::new(); |
| 2556 | for oid_result in revwalk { |
| 2557 | let oid = oid_result.map_err(|e| CliError::GitError { |
| 2558 | message: format!("Revwalk error: {}", e), |
| 2559 | })?; |
| 2560 | |
| 2561 | // Skip already imported commits in incremental mode |
| 2562 | if self.options.incremental && self.options.imported_shas.contains(&oid.to_string()) { |
| 2563 | continue; |
| 2564 | } |
| 2565 | |
| 2566 | oids.push(oid); |
| 2567 | } |
| 2568 | |
| 2569 | Ok(oids) |
| 2570 | } |
| 2571 | |
| 2572 | // ═══════════════════════════════════════════════════════════════════════ |
| 2573 | // Phase 1: Parallel Git Parsing |
no test coverage detected