MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / input_blob_bytes

Function input_blob_bytes

atomic-cli/src/commands/git/stream.rs:49–84  ·  view source on GitHub ↗
(git: &GitRepository, commit: &git2::Commit<'_>)

Source from the content-addressed store, hash-verified

47}
48
49fn 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)]
87struct Compiler {

Callers 3

input_budgetFunction · 0.85
rolling_sampleFunction · 0.85

Calls 8

treeMethod · 0.80
parentMethod · 0.80
as_refMethod · 0.80
new_fileMethod · 0.80
git_errorFunction · 0.70
is_zeroMethod · 0.45
idMethod · 0.45
modeMethod · 0.45

Tested by

no test coverage detected