Display repository size
@@ -36,6 +36,7 @@ struct Info {
last_change: String,
repo: String,
commits: String,
+ repo_size: String,
number_of_lines: usize,
license: String,
}
@@ -130,6 +131,12 @@ impl fmt::Display for Info {
"Lines of code: ".color(color).bold(),
self.number_of_lines
)?;
+ writeln!(
+ buffer,
+ "{}{}",
+ "Repository size: ".color(color).bold(),
+ self.repo_size
+ )?;
writeln!(
buffer,
"{}{}",
@@ -339,6 +346,7 @@ fn main() -> Result<()> {
let config = get_configuration(&dir)?;
let version = get_version(&dir)?;
let commits = get_commits(&dir)?;
+ let repo_size = get_packed_size(&dir)?;
let last_change = get_last_change(&dir)?;
let info = Info {
@@ -351,6 +359,7 @@ fn main() -> Result<()> {
last_change,
repo: config.repository_url,
commits,
+ repo_size,
number_of_lines: get_total_loc(&tokei_langs),
license: project_license(&dir)?,
};
@@ -472,6 +481,26 @@ fn get_commits(dir: &str) -> Result<String> {
}
}
+fn get_packed_size(dir: &str) -> Result<String> {
+ let output = Command::new("git")
+ .arg("-C")
+ .arg(dir)
+ .arg("count-objects")
+ .arg("-vH")
+ .output()
+ .expect("Failed to execute git.");
+
+ let output = String::from_utf8_lossy(&output.stdout);
+ let lines = output.to_string();
+ let size_line = lines.split("\n").find(|line| {
+ line.starts_with("size-pack:")
+ });
+ match size_line {
+ None => Ok("??".into()),
+ Some(size_str) => Ok(size_str[11..].into())
+ }
+}
+
fn is_git_installed() -> bool {
Command::new("git")
.arg("--version")
