Skip to content

Commit 004e687

Browse files
committed
Display repository size
Signed-off-by: Nikos Filippakis <nikolaos.filippakis@cern.ch>
1 parent bde2d86 commit 004e687

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct Info {
3636
last_change: String,
3737
repo: String,
3838
commits: String,
39+
repo_size: String,
3940
number_of_lines: usize,
4041
license: String,
4142
}
@@ -130,6 +131,12 @@ impl fmt::Display for Info {
130131
"Lines of code: ".color(color).bold(),
131132
self.number_of_lines
132133
)?;
134+
writeln!(
135+
buffer,
136+
"{}{}",
137+
"Repository size: ".color(color).bold(),
138+
self.repo_size
139+
)?;
133140
writeln!(
134141
buffer,
135142
"{}{}",
@@ -339,6 +346,7 @@ fn main() -> Result<()> {
339346
let config = get_configuration(&dir)?;
340347
let version = get_version(&dir)?;
341348
let commits = get_commits(&dir)?;
349+
let repo_size = get_packed_size(&dir)?;
342350
let last_change = get_last_change(&dir)?;
343351

344352
let info = Info {
@@ -351,6 +359,7 @@ fn main() -> Result<()> {
351359
last_change,
352360
repo: config.repository_url,
353361
commits,
362+
repo_size,
354363
number_of_lines: get_total_loc(&tokei_langs),
355364
license: project_license(&dir)?,
356365
};
@@ -472,6 +481,26 @@ fn get_commits(dir: &str) -> Result<String> {
472481
}
473482
}
474483

484+
fn get_packed_size(dir: &str) -> Result<String> {
485+
let output = Command::new("git")
486+
.arg("-C")
487+
.arg(dir)
488+
.arg("count-objects")
489+
.arg("-vH")
490+
.output()
491+
.expect("Failed to execute git.");
492+
493+
let output = String::from_utf8_lossy(&output.stdout);
494+
let lines = output.to_string();
495+
let size_line = lines.split("\n").find(|line| {
496+
line.starts_with("size-pack:")
497+
});
498+
match size_line {
499+
None => Ok("??".into()),
500+
Some(size_str) => Ok(size_str[11..].into())
501+
}
502+
}
503+
475504
fn is_git_installed() -> bool {
476505
Command::new("git")
477506
.arg("--version")

0 commit comments

Comments
 (0)