Collect commit OIDs in topological order (oldest first).
(
&self,
git_repo: &GitRepository,
branch_name: &str,
)
| 2370 | |
| 2371 | /// Collect commit OIDs in topological order (oldest first). |
| 2372 | fn collect_commit_oids( |
| 2373 | &self, |
| 2374 | git_repo: &GitRepository, |
| 2375 | branch_name: &str, |
| 2376 | ) -> CliResult<Vec<Oid>> { |
| 2377 | let reference = git_repo |
| 2378 | .find_branch(branch_name, git2::BranchType::Local) |
| 2379 | .map_err(|e| CliError::GitError { |
| 2380 | message: format!("Branch '{}' not found: {}", branch_name, e), |
| 2381 | })?; |
| 2382 | |
| 2383 | let target_oid = reference.get().target().ok_or_else(|| CliError::GitError { |
| 2384 | message: format!("Branch '{}' has no target commit", branch_name), |
| 2385 | })?; |
| 2386 | |
| 2387 | let mut revwalk = git_repo.revwalk().map_err(|e| CliError::GitError { |
| 2388 | message: format!("Failed to create revwalk: {}", e), |
| 2389 | })?; |
| 2390 | |
| 2391 | revwalk.push(target_oid).map_err(|e| CliError::GitError { |
| 2392 | message: format!("Failed to push target to revwalk: {}", e), |
| 2393 | })?; |
| 2394 | |
| 2395 | if self.options.mainline_only { |
| 2396 | revwalk |
| 2397 | .simplify_first_parent() |
| 2398 | .map_err(|e| CliError::GitError { |
| 2399 | message: format!("Failed to simplify revwalk to first-parent history: {}", e), |
| 2400 | })?; |
| 2401 | } |
| 2402 | |
| 2403 | // Topological order, oldest first |
| 2404 | revwalk |
| 2405 | .set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::REVERSE) |
| 2406 | .map_err(|e| CliError::GitError { |
| 2407 | message: format!("Failed to set sorting: {}", e), |
| 2408 | })?; |
| 2409 | |
| 2410 | let mut oids = Vec::new(); |
| 2411 | for oid_result in revwalk { |
| 2412 | let oid = oid_result.map_err(|e| CliError::GitError { |
| 2413 | message: format!("Revwalk error: {}", e), |
| 2414 | })?; |
| 2415 | |
| 2416 | // Skip already imported commits in incremental mode |
| 2417 | if self.options.incremental && self.options.imported_shas.contains(&oid.to_string()) { |
| 2418 | continue; |
| 2419 | } |
| 2420 | |
| 2421 | oids.push(oid); |
| 2422 | } |
| 2423 | |
| 2424 | Ok(oids) |
| 2425 | } |
| 2426 | |
| 2427 | // ═══════════════════════════════════════════════════════════════════════ |
| 2428 | // Phase 1: Parallel Git Parsing |
no test coverage detected