Build git metadata for the change's unhashed field.
(
&self,
parsed: &ParsedCommit,
is_empty: bool,
is_merge: bool,
)
| 8035 | |
| 8036 | /// Build git metadata for the change's unhashed field. |
| 8037 | fn build_git_metadata( |
| 8038 | &self, |
| 8039 | parsed: &ParsedCommit, |
| 8040 | is_empty: bool, |
| 8041 | is_merge: bool, |
| 8042 | ) -> serde_json::Value { |
| 8043 | let mut git = serde_json::json!({ |
| 8044 | "repository": self.options.repo_name, |
| 8045 | "sha": parsed.git_sha, |
| 8046 | "short_sha": parsed.short_sha, |
| 8047 | }); |
| 8048 | |
| 8049 | // A pure Git-detected rename has no patch lines, but omitting it makes |
| 8050 | // the Git-origin diff fall back to the graph's deliberate delete+add |
| 8051 | // representation. Record this as non-authoritative Git evidence only |
| 8052 | // when every path has a usable text diff or is an exact-byte rename. |
| 8053 | let complete_diff = parsed.files.iter().all(|file| { |
| 8054 | file.diff_lines.is_some() |
| 8055 | || (file.operation == FileOperation::Renamed |
| 8056 | && file.old_content.is_some() |
| 8057 | && file.old_content == file.new_content) |
| 8058 | }); |
| 8059 | let diff_files: Vec<serde_json::Value> = parsed |
| 8060 | .files |
| 8061 | .iter() |
| 8062 | // A partial list would silently omit changed paths when the |
| 8063 | // metadata-based renderer takes precedence over graph diffs. |
| 8064 | .filter(|_| complete_diff) |
| 8065 | .filter_map(|file| { |
| 8066 | let exact_rename = file.operation == FileOperation::Renamed |
| 8067 | && file.old_content.is_some() |
| 8068 | && file.old_content == file.new_content; |
| 8069 | let lines = file |
| 8070 | .diff_lines |
| 8071 | .as_deref() |
| 8072 | .or_else(|| (complete_diff && exact_rename).then_some(&[][..]))?; |
| 8073 | Some({ |
| 8074 | serde_json::json!({ |
| 8075 | "path": file.path, |
| 8076 | "old_path": file.old_path, |
| 8077 | "operation": match file.operation { |
| 8078 | FileOperation::Added => "added", |
| 8079 | FileOperation::Modified => "modified", |
| 8080 | FileOperation::Deleted => "deleted", |
| 8081 | FileOperation::Renamed => "renamed", |
| 8082 | FileOperation::Copied => "copied", |
| 8083 | }, |
| 8084 | "lines": lines, |
| 8085 | }) |
| 8086 | }) |
| 8087 | }) |
| 8088 | .collect(); |
| 8089 | |
| 8090 | if !diff_files.is_empty() { |
| 8091 | git["diff_lines"] = serde_json::Value::Array(diff_files); |
| 8092 | } |
| 8093 | |
| 8094 | if is_empty { |