Collect commit OIDs in topological order (oldest first).
(
&self,
git_repo: &GitRepository,
branch_name: &str,
)
| 2467 | |
| 2468 | /// Collect commit OIDs in topological order (oldest first). |
| 2469 | fn collect_commit_oids( |
| 2470 | &self, |
| 2471 | git_repo: &GitRepository, |
| 2472 | branch_name: &str, |
| 2473 | ) -> CliResult<Vec<Oid>> { |
| 2474 | let reference = git_repo |
| 2475 | .find_branch(branch_name, git2::BranchType::Local) |
| 2476 | .map_err(|e| CliError::GitError { |
| 2477 | message: format!("Branch '{}' not found: {}", branch_name, e), |
| 2478 | })?; |
| 2479 | |
| 2480 | let target_oid = reference.get().target().ok_or_else(|| CliError::GitError { |
| 2481 | message: format!("Branch '{}' has no target commit", branch_name), |
| 2482 | })?; |
| 2483 | |
| 2484 | let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError { |
| 2485 | message: format!("Failed to create revwalk: {}", e), |
| 2486 | })?; |
| 2487 | |
| 2488 | revwalk.push(target_oid).map_err(|e| CliError::GitError { |
| 2489 | message: format!("Failed to push target to revwalk: {}", e), |
| 2490 | })?; |
| 2491 | |
| 2492 | if self.options.mainline_only { |
| 2493 | revwalk |
| 2494 | .simplify_first_parent() |
| 2495 | .map_err(|e| CliError::GitError { |
| 2496 | message: format!("Failed to simplify revwalk to first-parent history: {}", e), |
| 2497 | })?; |
| 2498 | } |
| 2499 | |
| 2500 | // Topological order, oldest first |
| 2501 | revwalk |
| 2502 | .set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::REVERSE) |
| 2503 | .map_err(|e| CliError::GitError { |
| 2504 | message: format!("Failed to set sorting: {}", e), |
| 2505 | })?; |
| 2506 | |
| 2507 | let mut oids = Vec::new(); |
| 2508 | for oid_result in revwalk { |
| 2509 | let oid = oid_result.map_err(|e| CliError::GitError { |
| 2510 | message: format!("Revwalk error: {}", e), |
| 2511 | })?; |
| 2512 | |
| 2513 | // Skip already imported commits in incremental mode |
| 2514 | if self.options.incremental && self.options.imported_shas.contains(&oid.to_string()) { |
| 2515 | continue; |
| 2516 | } |
| 2517 | |
| 2518 | oids.push(oid); |
| 2519 | } |
| 2520 | |
| 2521 | Ok(oids) |
| 2522 | } |
| 2523 | |
| 2524 | // ═══════════════════════════════════════════════════════════════════════ |
| 2525 | // Phase 1: Parallel Git Parsing |
no test coverage detected