(git: &GitRepository, commit: &git2::Commit<'_>)
| 47 | } |
| 48 | |
| 49 | fn input_blob_bytes(git: &GitRepository, commit: &git2::Commit<'_>) -> CliResult<usize> { |
| 50 | let tree = commit.tree().map_err(|e| git_error(e.to_string()))?; |
| 51 | let parent = if commit.parent_count() == 0 { |
| 52 | None |
| 53 | } else { |
| 54 | Some( |
| 55 | commit |
| 56 | .parent(0) |
| 57 | .and_then(|parent| parent.tree()) |
| 58 | .map_err(|e| git_error(e.to_string()))?, |
| 59 | ) |
| 60 | }; |
| 61 | let diff = git |
| 62 | .diff_tree_to_tree(parent.as_ref(), Some(&tree), None) |
| 63 | .map_err(|e| git_error(e.to_string()))?; |
| 64 | let odb = git.odb().map_err(|e| git_error(e.to_string()))?; |
| 65 | let mut bytes = 0usize; |
| 66 | for delta in diff.deltas() { |
| 67 | for file in [delta.old_file(), delta.new_file()] { |
| 68 | // Gitlinks name commits in another repository. Their objects need |
| 69 | // not exist here; only blob payloads consume this input budget. |
| 70 | if file.id().is_zero() || file.mode() == git2::FileMode::Commit { |
| 71 | continue; |
| 72 | } |
| 73 | let (size, kind) = odb |
| 74 | .read_header(file.id()) |
| 75 | .map_err(|e| git_error(e.to_string()))?; |
| 76 | if kind == ObjectType::Blob { |
| 77 | bytes = bytes |
| 78 | .checked_add(size) |
| 79 | .ok_or_else(|| git_error("input size overflow"))?; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | Ok(bytes) |
| 84 | } |
| 85 | |
| 86 | #[derive(Default)] |
| 87 | struct Compiler { |
no test coverage detected