Collect commit OIDs in topological order (oldest first).
(
&self,
git_repo: &GitRepository,
branch_name: &str,
)
| 2444 | |
| 2445 | /// Collect commit OIDs in topological order (oldest first). |
| 2446 | fn collect_commit_oids( |
| 2447 | &self, |
| 2448 | git_repo: &GitRepository, |
| 2449 | branch_name: &str, |
| 2450 | ) -> CliResult<Vec<Oid>> { |
| 2451 | let reference = git_repo |
| 2452 | .find_branch(branch_name, git2::BranchType::Local) |
| 2453 | .map_err(|e| CliError::GitError { |
| 2454 | message: format!("Branch '{}' not found: {}", branch_name, e), |
| 2455 | })?; |
| 2456 | |
| 2457 | let target_oid = reference.get().target().ok_or_else(|| CliError::GitError { |
| 2458 | message: format!("Branch '{}' has no target commit", branch_name), |
| 2459 | })?; |
| 2460 | |
| 2461 | let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError { |
| 2462 | message: format!("Failed to create revwalk: {}", e), |
| 2463 | })?; |
| 2464 | |
| 2465 | revwalk.push(target_oid).map_err(|e| CliError::GitError { |
| 2466 | message: format!("Failed to push target to revwalk: {}", e), |
| 2467 | })?; |
| 2468 | |
| 2469 | if self.options.mainline_only { |
| 2470 | revwalk |
| 2471 | .simplify_first_parent() |
| 2472 | .map_err(|e| CliError::GitError { |
| 2473 | message: format!("Failed to simplify revwalk to first-parent history: {}", e), |
| 2474 | })?; |
| 2475 | } |
| 2476 | |
| 2477 | // Topological order, oldest first |
| 2478 | revwalk |
| 2479 | .set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::REVERSE) |
| 2480 | .map_err(|e| CliError::GitError { |
| 2481 | message: format!("Failed to set sorting: {}", e), |
| 2482 | })?; |
| 2483 | |
| 2484 | let mut oids = Vec::new(); |
| 2485 | for oid_result in revwalk { |
| 2486 | let oid = oid_result.map_err(|e| CliError::GitError { |
| 2487 | message: format!("Revwalk error: {}", e), |
| 2488 | })?; |
| 2489 | |
| 2490 | // Skip already imported commits in incremental mode |
| 2491 | if self.options.incremental && self.options.imported_shas.contains(&oid.to_string()) { |
| 2492 | continue; |
| 2493 | } |
| 2494 | |
| 2495 | oids.push(oid); |
| 2496 | } |
| 2497 | |
| 2498 | Ok(oids) |
| 2499 | } |
| 2500 | |
| 2501 | // ═══════════════════════════════════════════════════════════════════════ |
| 2502 | // Phase 1: Parallel Git Parsing |
no test coverage detected