Extract metadata from a git commit. Raw facts are captured losslessly (review blocker 6): name/email bytes come from the raw signature bytes (non-UTF-8 safe) and the timezone offsets from the raw commit object, so no UTF-8 or UTC normalization destroys foreign identity data. The display strings remain best-effort lossy conversions for presentation only.
(commit: &git2::Commit)
| 8891 | /// destroys foreign identity data. The display strings remain best-effort |
| 8892 | /// lossy conversions for presentation only. |
| 8893 | fn extract_commit_metadata(commit: &git2::Commit) -> CliResult<CommitMetadata> { |
| 8894 | let author = commit.author(); |
| 8895 | let author_name = author.name().unwrap_or("Unknown").to_string(); |
| 8896 | let author_email = author.email().ok().map(ToString::to_string); |
| 8897 | let author_name_raw = author.name_bytes().to_vec(); |
| 8898 | let author_email_raw = { |
| 8899 | let bytes = author.email_bytes(); |
| 8900 | if bytes.is_empty() { |
| 8901 | None |
| 8902 | } else { |
| 8903 | Some(bytes.to_vec()) |
| 8904 | } |
| 8905 | }; |
| 8906 | let committer = commit.committer(); |
| 8907 | let committer_name = committer.name().unwrap_or("Unknown").to_string(); |
| 8908 | let committer_email = committer.email().ok().map(ToString::to_string); |
| 8909 | let committer_name_raw = committer.name_bytes().to_vec(); |
| 8910 | let committer_email_raw = { |
| 8911 | let bytes = committer.email_bytes(); |
| 8912 | if bytes.is_empty() { |
| 8913 | None |
| 8914 | } else { |
| 8915 | Some(bytes.to_vec()) |
| 8916 | } |
| 8917 | }; |
| 8918 | |
| 8919 | let time = commit.time(); |
| 8920 | let timestamp = Utc |
| 8921 | .timestamp_opt(time.seconds(), 0) |
| 8922 | .single() |
| 8923 | .unwrap_or_else(Utc::now); |
| 8924 | let author_time = author.when().seconds(); |
| 8925 | let author_time_offset_seconds = i64::from(author.when().offset_minutes()) * 60; |
| 8926 | let committer_time = committer.when().seconds(); |
| 8927 | let committer_time_offset_seconds = i64::from(committer.when().offset_minutes()) * 60; |
| 8928 | |
| 8929 | let full_message = commit.message().unwrap_or(""); |
| 8930 | let (message, description) = parse_commit_message(full_message); |
| 8931 | |
| 8932 | Ok(CommitMetadata { |
| 8933 | author_name, |
| 8934 | author_email, |
| 8935 | author_name_raw, |
| 8936 | author_email_raw, |
| 8937 | timestamp, |
| 8938 | message, |
| 8939 | description, |
| 8940 | author_time, |
| 8941 | author_time_offset_seconds, |
| 8942 | committer_name, |
| 8943 | committer_email, |
| 8944 | committer_name_raw, |
| 8945 | committer_email_raw, |
| 8946 | committer_time, |
| 8947 | committer_time_offset_seconds, |
| 8948 | }) |
| 8949 | } |
| 8950 |
no test coverage detected