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>,
)
| 3707 | /// This is a free function rather than a method because each rayon thread |
| 3708 | /// opens its own git repository instance (git2::Repository is not Sync). |
| 3709 | fn parse_commit( |
| 3710 | git_repo: &GitRepository, |
| 3711 | oid: Oid, |
| 3712 | _index: usize, |
| 3713 | oid_to_index: &std::collections::HashMap<Oid, usize>, |
| 3714 | ) -> CliResult<ParsedCommit> { |
| 3715 | let parse_start = Instant::now(); |
| 3716 | let commit = git_repo.find_commit(oid).map_err(|e| CliError::GitError { |
| 3717 | message: format!("Failed to find commit {}: {}", oid, e), |
| 3718 | })?; |
| 3719 | |
| 3720 | let sha = oid.to_string(); |
| 3721 | let short_sha = sha[..8.min(sha.len())].to_string(); |
| 3722 | |
| 3723 | // Extract metadata |
| 3724 | let metadata = extract_commit_metadata(&commit)?; |
| 3725 | |
| 3726 | // Get parent index |
| 3727 | let parent_index = if commit.parent_count() > 0 { |
| 3728 | commit |
| 3729 | .parent_id(0) |
| 3730 | .ok() |
| 3731 | .and_then(|parent_oid| oid_to_index.get(&parent_oid).copied()) |
| 3732 | } else { |
| 3733 | None |
| 3734 | }; |
| 3735 | |
| 3736 | let is_merge = commit.parent_count() > 1; |
| 3737 | |
| 3738 | // Get trees for diff |
| 3739 | let tree = commit.tree().map_err(|e| CliError::GitError { |
| 3740 | message: format!("Failed to get tree: {}", e), |
| 3741 | })?; |
| 3742 | |
| 3743 | let parent_tree = if commit.parent_count() > 0 { |
| 3744 | Some( |
| 3745 | commit |
| 3746 | .parent(0) |
| 3747 | .map_err(|e| CliError::GitError { |
| 3748 | message: format!("Failed to get parent: {}", e), |
| 3749 | })? |
| 3750 | .tree() |
| 3751 | .map_err(|e| CliError::GitError { |
| 3752 | message: format!("Failed to get parent tree: {}", e), |
| 3753 | })?, |
| 3754 | ) |
| 3755 | } else { |
| 3756 | None |
| 3757 | }; |
| 3758 | |
| 3759 | // Use git's default diff algorithm here. Harness parity compares against |
| 3760 | // plain `git diff`, so the captured +/- lines need to reflect the same |
| 3761 | // default edit classification rather than `--patience`. |
| 3762 | let mut diff_opts = DiffOptions::new(); |
| 3763 | diff_opts.include_untracked(false); |
| 3764 | |
| 3765 | let diff_start = Instant::now(); |
| 3766 | let mut diff = git_repo |
no test coverage detected