MCPcopy Index your code
hub / github.com/HairlessVillager/minecommit / git_count_objects

Function git_count_objects

minecommit/src/utils/cmd.rs:97–170  ·  view source on GitHub ↗
(git_dir: impl AsRef<OsStr>)

Source from the content-addressed store, hash-verified

95}
96
97pub fn git_count_objects(git_dir: impl AsRef<OsStr>) -> Result<RepoStats> {
98 let cmd = git_cmd(git_dir, ["count-objects", "-v"]);
99 let result = exec(cmd, None)?;
100
101 let mut stats = RepoStats {
102 count: 0,
103 size_mib: 0.0,
104 in_pack: 0,
105 packs: 0,
106 size_pack_mib: 0.0,
107 prune_packable: 0,
108 garbage: 0,
109 size_garbage_mib: 0.0,
110 };
111
112 for line in result.lines() {
113 if let Some((key, val)) = line.split_once(": ") {
114 let val = val.trim();
115 match key {
116 "count" => {
117 stats.count = val.parse().unwrap_or_else(|e| {
118 log::warn!("Failed to parse git count-objects field 'count': {e}");
119 0
120 })
121 }
122 "size" => {
123 stats.size_mib = val.parse::<f64>().unwrap_or_else(|e| {
124 log::warn!("Failed to parse git count-objects field 'size': {e}");
125 0.0
126 }) / 1024.0
127 }
128 "in-pack" => {
129 stats.in_pack = val.parse().unwrap_or_else(|e| {
130 log::warn!("Failed to parse git count-objects field 'in-pack': {e}");
131 0
132 })
133 }
134 "packs" => {
135 stats.packs = val.parse().unwrap_or_else(|e| {
136 log::warn!("Failed to parse git count-objects field 'packs': {e}");
137 0
138 })
139 }
140 "size-pack" => {
141 stats.size_pack_mib = val.parse::<f64>().unwrap_or_else(|e| {
142 log::warn!("Failed to parse git count-objects field 'size-pack': {e}");
143 0.0
144 }) / 1024.0
145 }
146 "prune-packable" => {
147 stats.prune_packable = val.parse().unwrap_or_else(|e| {
148 log::warn!("Failed to parse git count-objects field 'prune-packable': {e}");
149 0
150 })
151 }
152 "garbage" => {
153 stats.garbage = val.parse().unwrap_or_else(|e| {
154 log::warn!("Failed to parse git count-objects field 'garbage': {e}");

Callers 2

perform_commitFunction · 0.85
mainFunction · 0.85

Calls 2

git_cmdFunction · 0.85
execFunction · 0.85

Tested by

no test coverage detected