diff --git a/README.md b/README.md index 9456320..8e1e87f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Git Stats parses shortlog information to get stats about the files changed, additions, and deletions. For example: - $ git stats origin..HEAD + $ git stats -r origin..HEAD Author Commits Changed Files Insertions Deletions Net Δ Luke Hsiao 30 50 +1324 -166 +1158 @@ -34,7 +34,6 @@ cargo install git-stats --locked ## Usage ``` -$ git stats -h A script for grabbing more thorough shortlog stats Usage: git-stats [OPTIONS] [revision-range] @@ -43,7 +42,8 @@ Arguments: [revision-range] Show only commits in the specified revision range [default: HEAD] Options: - -e, --email Show the email address of each author - -h, --help Print help information (use `--help` for more detail) - -V, --version Print version information + -e, --email Show the email address of each author + -r, --reviews Show who reviewed/tested commits based on `Acked-by`, `Tested-by`, and `Reviewed-by` git trailers + -h, --help Print help (see more with '--help') + -V, --version Print version ``` diff --git a/src/main.rs b/src/main.rs index bd815d3..259f27f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,13 @@ struct Cli { /// commit (i.e. HEAD), but not from origin. For a complete list of ways to spell /// [revision-range], see the "Specifying Ranges" section of gitrevisions(7). rev_range: String, - #[arg(short, long, default_value = "false")] + #[arg(short, long)] /// Show the email address of each author. email: bool, + #[arg(short, long)] + /// Show who reviewed/tested commits based on `Acked-by`, `Tested-by`, and + /// `Reviewed-by` git trailers. + reviews: bool, } #[derive(Tabled)] @@ -139,36 +143,38 @@ fn main() -> Result<()> { println!("{table}"); } - let raw_reviewers = if cli.email { - cmd!(sh, "git shortlog -sen --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()? - } else { - cmd!(sh, "git shortlog -sn --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()? - }; - let reviewers: Vec<(usize, &str)> = raw_reviewers - .lines() - .map(|line| { - let chunks = line.trim().split_once('\t').unwrap(); - let commits = usize::from_str(chunks.0).unwrap(); - let author = chunks.1; - (commits, author) - }) - .collect::<_>(); - - if !reviewers.is_empty() { - let reviews: Vec = reviewers - .par_iter() - .map(|(commits, author)| Review { - author: author.to_string(), - commits: *commits, + if cli.reviews { + let raw_reviewers = if cli.email { + cmd!(sh, "git shortlog -sen --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()? + } else { + cmd!(sh, "git shortlog -sn --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()? + }; + let reviewers: Vec<(usize, &str)> = raw_reviewers + .lines() + .map(|line| { + let chunks = line.trim().split_once('\t').unwrap(); + let commits = usize::from_str(chunks.0).unwrap(); + let author = chunks.1; + (commits, author) }) .collect::<_>(); - let mut table = Table::new(reviews); - table - .with(Style::empty()) - .with(Modify::new(Columns::new(1..=1)).with(Alignment::right())); + if !reviewers.is_empty() { + let reviews: Vec = reviewers + .par_iter() + .map(|(commits, author)| Review { + author: author.to_string(), + commits: *commits, + }) + .collect::<_>(); + + let mut table = Table::new(reviews); + table + .with(Style::empty()) + .with(Modify::new(Columns::new(1..=1)).with(Alignment::right())); - println!("\n{table}"); + println!("\n{table}"); + } } Ok(())