Parse a single git commit (called in parallel from rayon threads). This is a free function rather than a method because each rayon thread opens its own git repository instance (git2::Repository is not Sync).
(
git_repo: &GitRepository,
oid: Oid,
_index: usize,
oid_to_index: &std::collections::HashMap<Oid, usize>,
)
| 3677 | /// This is a free function rather than a method because each rayon thread |
| 3678 | /// opens its own git repository instance (git2::Repository is not Sync). |
| 3679 | fn parse_commit( |
| 3680 | git_repo: &GitRepository, |
| 3681 | oid: Oid, |
| 3682 | _index: usize, |
| 3683 | oid_to_index: &std::collections::HashMap<Oid, usize>, |
| 3684 | ) -> CliResult<ParsedCommit> { |
| 3685 | let parse_start = Instant::now(); |
| 3686 | let commit = git_repo.find_commit(oid).map_err(|e| CliError::GitError { |
| 3687 | message: format!("Failed to find commit {}: {}", oid, e), |
| 3688 | })?; |
| 3689 | |
| 3690 | let sha = oid.to_string(); |
| 3691 | let short_sha = sha[..8.min(sha.len())].to_string(); |
| 3692 | |
| 3693 | // Extract metadata |
| 3694 | let metadata = extract_commit_metadata(&commit)?; |
| 3695 | |
| 3696 | // Get parent index |
| 3697 | let parent_index = if commit.parent_count() > 0 { |
| 3698 | commit |
| 3699 | .parent_id(0) |
| 3700 | .ok() |
| 3701 | .and_then(|parent_oid| oid_to_index.get(&parent_oid).copied()) |
| 3702 | } else { |
| 3703 | None |
| 3704 | }; |
| 3705 | |
| 3706 | let is_merge = commit.parent_count() > 1; |
| 3707 | |
| 3708 | // Get trees for diff |
| 3709 | let tree = commit.tree().map_err(|e| CliError::GitError { |
| 3710 | message: format!("Failed to get tree: {}", e), |
| 3711 | })?; |
| 3712 | |
| 3713 | let parent_tree = if commit.parent_count() > 0 { |
| 3714 | Some( |
| 3715 | commit |
| 3716 | .parent(0) |
| 3717 | .map_err(|e| CliError::GitError { |
| 3718 | message: format!("Failed to get parent: {}", e), |
| 3719 | })? |
| 3720 | .tree() |
| 3721 | .map_err(|e| CliError::GitError { |
| 3722 | message: format!("Failed to get parent tree: {}", e), |
| 3723 | })?, |
| 3724 | ) |
| 3725 | } else { |
| 3726 | None |
| 3727 | }; |
| 3728 | |
| 3729 | // Use git's default diff algorithm here. Harness parity compares against |
| 3730 | // plain `git diff`, so the captured +/- lines need to reflect the same |
| 3731 | // default edit classification rather than `--patience`. |
| 3732 | let mut diff_opts = DiffOptions::new(); |
| 3733 | diff_opts.include_untracked(false); |
| 3734 | |
| 3735 | let diff_start = Instant::now(); |
| 3736 | let mut diff = git_repo |
no test coverage detected