Skip to content

Commit

Permalink
feat: include totals of all statistics
Browse files Browse the repository at this point in the history
This patch adds a final row to the table that is simply the sum of
each of the columns. This is nice in that it gives a final at-a-glance
summary of the "size" of the changes in the revision range.

Closes: #34
  • Loading branch information
lukehsiao committed Apr 19, 2024
1 parent 3429fda commit 8c1895f
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 12 deletions.
79 changes: 79 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ categories = ["command-line-utilities"]
anyhow = "1.0.81"
clap = { version = "4.5.4", features = ["wrap_help", "derive"] }
rayon = "1.10.0"
tabled = "0.15.0"
tabled = { version = "0.15.0", features = ["ansi"] }
xshell = "0.2.6"
yansi = "1.0.1"
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
</div>
<br>

Git Stats parses shortlog information to get stats about the files changed, additions, and
deletions. For example:
Git Stats parses [shortlog](https://git-scm.com/docs/git-shortlog) information to get stats about the files changed, additions, and deletions.
For example:

$ git stats -r origin..HEAD
Author Commits Changed Files Insertions Deletions Net Δ
Luke Hsiao 30 50 +1324 -166 +1158
Author Commits Changed Files Insertions Deletions Net Δ
Luke Hsiao 55 95 +2395 -1052 +1343
dependabot[bot] 31 62 +203 -267 -64
Total 86 157 +2598 -1319 +1279

Reviewer/Tester Commits
Luke Hsiao 1
Reviewer/Tester Commits
Luke Hsiao 1

## Install

This is a glorified shell script. As such, it expects that you have `git` installed on your machine
and in your `$PATH`.
This is a glorified shell script.
As such, it expects that you have `git` installed on your machine and in your `$PATH`.

### From crates.io

Expand Down
34 changes: 31 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use anyhow::{bail, Result};
use clap::Parser;
use rayon::prelude::*;
use tabled::{
settings::{object::Columns, Alignment, Modify, Style},
settings::{
format::Format,
object::{Columns, Rows},
Alignment, Modify, Style,
},
Table, Tabled,
};
use yansi::Paint;

use xshell::{cmd, Shell};

Expand Down Expand Up @@ -98,7 +103,7 @@ fn main() -> Result<()> {
.collect::<_>();

if !shortlog.is_empty() {
let stats: Vec<Stat> = shortlog
let mut stats: Vec<Stat> = shortlog
.par_iter()
.map(|(commits, author)| {
let sh = Shell::new()?;
Expand Down Expand Up @@ -138,10 +143,33 @@ fn main() -> Result<()> {
.filter_map(|r| r.ok())
.collect::<_>();

// Collect totals
let totals = stats.iter().fold(
Stat {
author: "Total".to_string(),
commits: 0,
num_files: 0,
insertions: 0,
deletions: 0,
net: 0,
},
|acc, s| Stat {
author: acc.author,
commits: acc.commits + s.commits,
num_files: acc.num_files + s.num_files,
insertions: acc.insertions + s.insertions,
deletions: acc.deletions + s.deletions,
net: acc.net + s.net,
},
);
stats.push(totals);

let mut table = Table::new(stats);
table
.with(Style::empty())
.with(Modify::new(Columns::new(1..=5)).with(Alignment::right()));
.modify(Columns::new(1..=5), Alignment::right())
.modify(Rows::last(), Alignment::right())
.modify(Rows::last(), Format::content(|s| s.bold().to_string()));

println!("{table}");
}
Expand Down

0 comments on commit 8c1895f

Please sign in to comment.