Skip to content

Commit 3ee77f5

Browse files
committed
Add number of files to Repository size
1 parent 868a95f commit 3ee77f5

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/main.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,43 @@ fn get_packed_size(dir: &str) -> Result<String> {
508508
let size_line = lines.split("\n").find(|line| {
509509
line.starts_with("size-pack:")
510510
});
511-
match size_line {
512-
None => Ok("??".into()),
513-
Some(size_str) => Ok(size_str[11..].into())
511+
512+
let repo_size = match size_line {
513+
None => "??",
514+
Some(size_str) => &(size_str[11..])
515+
};
516+
517+
let output = Command::new("git")
518+
.arg("-C")
519+
.arg(dir)
520+
.arg("ls-files")
521+
.output()
522+
.expect("Failed to execute git.");
523+
// To check if command executed successfully or not
524+
let error = &output.stderr;
525+
526+
if error.is_empty(){
527+
let output = String::from_utf8_lossy(&output.stdout);
528+
529+
let lines = output.to_string();
530+
let files_list = lines.split("\n");
531+
let mut files_count:u128 = 0;
532+
for file in files_list {
533+
files_count+=1;
534+
}
535+
files_count-=1; // As splitting giving one line extra(blank).
536+
let res = repo_size.to_owned() + &(" (") + &(files_count.to_string()) + &(" files)");
537+
Ok(res.into())
514538
}
539+
else{
540+
let mut res:&str;
541+
if repo_size == "??"{
542+
res = "??";
543+
}else{
544+
res = repo_size;
545+
}
546+
Ok(res.into())
547+
}
515548
}
516549

517550
fn is_git_installed() -> bool {

0 commit comments

Comments
 (0)