Skip to content

Commit 5052a4e

Browse files
committed
also inform about average and max commit sizes (#364)
This helps to tune caches. Linux v5.16 - Max commit Size: 74428 - Avg commit Size: 833
1 parent 11644bd commit 5052a4e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

git-repository/examples/stats.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ use git_repository as git;
22
use git_repository::Reference;
33

44
fn main() -> Result<(), Box<dyn std::error::Error>> {
5-
let repo = git::discover(".")?.apply_environment();
5+
let mut repo = git::discover(".")?.apply_environment();
66
println!(
77
"Repo: {}",
8-
repo.work_dir().as_deref().unwrap_or(repo.git_dir()).display()
8+
repo.work_dir()
9+
.as_deref()
10+
.unwrap_or(repo.git_dir())
11+
.display()
912
);
13+
let mut max_commit_size = 0;
14+
let mut avg_commit_size = 0;
15+
repo.object_cache_size(32 * 1024);
1016
let commit_ids = repo
1117
.head()?
1218
.into_fully_peeled_id()
1319
.ok_or_else(|| "There are no commits - nothing to do here.")??
1420
.ancestors()
1521
.all()
22+
.inspect(|id| {
23+
if let Ok(Ok(object)) = id.as_ref().map(|id| id.object()) {
24+
avg_commit_size += object.data.len();
25+
if object.data.len() > max_commit_size {
26+
max_commit_size = object.data.len();
27+
}
28+
}
29+
})
1630
.collect::<Result<Vec<_>, _>>()?;
1731
println!("Num Commits: {}", commit_ids.len());
32+
println!("Max commit Size: {}", max_commit_size);
33+
println!("Avg commit Size: {}", avg_commit_size / commit_ids.len());
1834
assert!(!commit_ids.is_empty(), "checked that before");
1935

2036
let last_commit_id = &commit_ids[0];

0 commit comments

Comments
 (0)