Skip to content

Commit

Permalink
Display repository size
Browse files Browse the repository at this point in the history
Signed-off-by: Nikos Filippakis <nikolaos.filippakis@cern.ch>
  • Loading branch information
nikofil committed Oct 2, 2019
1 parent bde2d86 commit 004e687
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Info {
last_change: String,
repo: String,
commits: String,
repo_size: String,
number_of_lines: usize,
license: String,
}
Expand Down Expand Up @@ -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,
"{}{}",
Expand Down Expand Up @@ -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 {
Expand All @@ -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)?,
};
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 004e687

Please sign in to comment.