Add summary fields (#1013)

Co-authored-by: guenthgr <guenther.grill@frauscher.com>
This commit is contained in:
Günther Grill 2023-01-04 01:58:16 +01:00 committed by GitHub
parent aea25d2d4b
commit cd348dad21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 71 deletions

View file

@ -151,12 +151,14 @@ Outputs a repo or path summary:
```bash
$ git summary
project : git-extras
repo age : 10 months ago
commits : 163
active : 60 days
files : 93
authors :
project : git-extras
repo age : 10 months ago
last active : 3 weeks ago
active on : 93 days
commits : 163
files : 93
uncommitted : 3
authors :
97 Tj Holowaychuk 59.5%
37 Jonhnny Weslley 22.7%
8 Kenneth Reitz 4.9%

View file

@ -52,7 +52,6 @@ project=${PWD##*/}
#
# get date for the given <commit>
#
date() {
# the $1 can be empty
# shellcheck disable=SC2086
@ -62,7 +61,6 @@ date() {
#
# get active days for the given <commit>
#
active_days() {
# shellcheck disable=SC2086
date $1 | sort -r | uniq | awk '
@ -74,7 +72,6 @@ active_days() {
#
# get the commit total
#
commit_count() {
# shellcheck disable=SC2086
git log $MERGES_ARG --oneline $commit | wc -l | tr -d ' '
@ -83,7 +80,6 @@ commit_count() {
#
# total file count
#
file_count() {
git ls-files | wc -l | tr -d ' '
}
@ -91,7 +87,6 @@ file_count() {
#
# remove duplicate authors who belong to the same email address
#
dedup_by_email() {
# in:
# 27 luo zexuan <LuoZexuan@xxx.com>
@ -132,7 +127,6 @@ dedup_by_email() {
#
# list authors
#
format_authors() {
# a rare unicode character is used as separator to avoid conflicting with
# author name. However, Linux column utility will escape tab if separator
@ -150,9 +144,15 @@ format_authors() {
#
# fetch repository age from oldest commit
#
repository_age() {
git log --reverse --pretty=oneline --format="%ar" | head -n 1 | LC_ALL=C sed 's/ago//'
git log --reverse --pretty=oneline --format="%ar" -n 1 | LC_ALL=C sed 's/ago//'
}
#
# fetch repository age of the latest commit
#
last_active() {
git log --pretty=oneline --format="%ar" -n 1
}
#
@ -181,27 +181,32 @@ line_count() {
lines "$@" | wc -l
}
# summary
uncommitted_changes_count() {
git status --porcelain | wc -l
}
# summary
echo
echo " project : $project"
echo " project : $project"
if [ -n "$SUMMARY_BY_LINE" ]; then
echo " lines : $(line_count "${paths[@]}")"
echo " authors :"
echo " lines : $(line_count "${paths[@]}")"
echo " authors :"
lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors
else
echo " repo age : $(repository_age)"
echo " repo age : $(repository_age)"
echo " last active : $(last_active)"
# shellcheck disable=SC2086
echo " active : $(active_days $commit) days"
echo " active on : $(active_days $commit) days"
# shellcheck disable=SC2086
echo " commits : $(commit_count $commit)"
echo " commits : $(commit_count $commit)"
# The file count doesn't support passing a git ref so ignore it if a ref is given
if [ "$commit" == "HEAD" ]; then
echo " files : $(file_count)"
echo " files : $(file_count)"
fi
echo " authors : "
echo " uncommitted : $(uncommitted_changes_count)"
echo " authors : "
if [ -n "$DEDUP_BY_EMAIL" ]; then
# the $commit can be empty
# shellcheck disable=SC2086

View file

@ -1,60 +1,87 @@
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "GIT\-SUMMARY" "1" "August 2021" "" "Git Extras"
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-SUMMARY" "1" "December 2022" "" "Git Extras"
.
.SH "NAME"
\fBgit\-summary\fR \- Show repository summary
.
.SH "SYNOPSIS"
\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [<committish>]
.
.br
\fBgit\-summary\fR \-\-line [<path>]
.
.SH "DESCRIPTION"
Shows a summary of the repository or a path within it\.
.
.SH "OPTIONS"
<committish>
.
.P
Summarize only the range of commits included in the <committish>\.
.
.P
<path>
.
.P
Summarize only the range of files included in the <path>\.
.
.P
\-\-dedup\-by\-email
.
.P
Remove duplicate authors who belong to the same email address\. For example,
.
.IP "" 4
.
.nf
$ git summary
\|\.\|\.\|\.
\.\.\.
133 TJ Holowaychuk 9\.9%
115 Tj Holowaychuk 8\.5%
$ git summary \-\-dedup\-by\-email
\|\.\|\.\|\.
\.\.\.
248 TJ Holowaychuk 18\.4%
.
.fi
.
.IP "" 0
.
.P
\-\-no\-merges
.
.P
Exclude merge commits\.
.
.P
\-\-line
.
.P
Summarize with lines other than commits\. When \fB\-\-line\fR is specified, the last argument is treated as <path>\.
.
.P
This option can not be used together with \fB\-\-dedup\-by\-email\fR or \fB\-\-no\-merges\fR\.
.
.SH "EXAMPLES"
Outputs a repo summary:
.
.IP "" 4
.
.nf
$ git summary
project : express
repo age : 10 months ago
commits : 1893
active : 93 days
files : 111
authors :
project : express
repo age : 10 months ago
last active : 3 weeks ago
active on : 93 days
commits : 1893
files : 111
uncommitted : 3
authors :
1285 visionmedia
478 Tj Holowaychuk
48 Aaron Heckmann
@ -73,42 +100,65 @@ authors :
1 ewoudj
1 isaacs
1 Matt Colyer
.
.fi
.
.IP "" 0
.
.P
This command can also take a committish, and will print a summary for the range of commits included in the committish:
.
.IP "" 4
.
.nf
$ git summary v42\.\.
.
.fi
.
.IP "" 0
.
.P
Outputs a repo summary by line:
.
.IP "" 4
.
.nf
$ git summary \-\-line
project : git\-extras
lines : 26820
authors :
\|\.\|\.\|\.
\.\.\.
.
.fi
.
.IP "" 0
.
.P
Filter with the path:
.
.IP "" 4
.
.nf
$ git summary \-\-line bin/
project : git\-extras
lines : 4420
authors :
\|\.\|\.\|\.
\.\.\.
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>

View file

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf8'>
<meta name='generator' content='Ronn-NG/v0.9.1 (http://github.com/apjanke/ronn-ng/tree/0.9.1)'>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<title>git-summary(1) - Show repository summary</title>
<style type='text/css' media='all'>
/* style: man */
@ -69,15 +69,14 @@
<li class='tr'>git-summary(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>git-summary</code> - <span class="man-whatis">Show repository summary</span>
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-summary</code> [--dedup-by-email] [--no-merges] [&lt;committish&gt;]<br>
<p> <code>git-summary</code> [--dedup-by-email] [--no-merges] [&lt;committish&gt;]<br />
<code>git-summary</code> --line [&lt;path&gt;]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -86,17 +85,17 @@
<h2 id="OPTIONS">OPTIONS</h2>
<p>&lt;committish&gt;</p>
<p> &lt;committish&gt;</p>
<p>Summarize only the range of commits included in the &lt;committish&gt;.</p>
<p> Summarize only the range of commits included in the &lt;committish&gt;.</p>
<p>&lt;path&gt;</p>
<p> &lt;path&gt;</p>
<p>Summarize only the range of files included in the &lt;path&gt;.</p>
<p> Summarize only the range of files included in the &lt;path&gt;.</p>
<p>--dedup-by-email</p>
<p> --dedup-by-email</p>
<p>Remove duplicate authors who belong to the same email address.
<p> Remove duplicate authors who belong to the same email address.
For example,</p>
<pre><code>$ git summary
@ -109,29 +108,31 @@ $ git summary --dedup-by-email
248 TJ Holowaychuk 18.4%
</code></pre>
<p>--no-merges</p>
<p> --no-merges</p>
<p>Exclude merge commits.</p>
<p> Exclude merge commits.</p>
<p>--line</p>
<p> --line</p>
<p>Summarize with lines other than commits.
<p> Summarize with lines other than commits.
When <code>--line</code> is specified, the last argument is treated as &lt;path&gt;.</p>
<p>This option can not be used together with <code>--dedup-by-email</code> or <code>--no-merges</code>.</p>
<p> This option can not be used together with <code>--dedup-by-email</code> or <code>--no-merges</code>.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p>Outputs a repo summary:</p>
<p> Outputs a repo summary:</p>
<pre><code>$ git summary
project : express
repo age : 10 months ago
commits : 1893
active : 93 days
files : 111
authors :
project : express
repo age : 10 months ago
last active : 3 weeks ago
active on : 93 days
commits : 1893
files : 111
uncommitted : 3
authors :
1285 visionmedia
478 Tj Holowaychuk
48 Aaron Heckmann
@ -152,13 +153,13 @@ authors :
1 Matt Colyer
</code></pre>
<p>This command can also take a committish, and will print a summary for the range
<p> This command can also take a committish, and will print a summary for the range
of commits included in the committish:</p>
<pre><code>$ git summary v42..
</code></pre>
<p>Outputs a repo summary by line:</p>
<p> Outputs a repo summary by line:</p>
<pre><code>$ git summary --line
@ -168,7 +169,7 @@ authors :
...
</code></pre>
<p>Filter with the path:</p>
<p> Filter with the path:</p>
<pre><code>$ git summary --line bin/
@ -180,7 +181,7 @@ authors :
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Tj Holowaychuk &lt;<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>&gt;</p>
<p>Written by Tj Holowaychuk &lt;<a href="&#x6d;&#x61;&#105;&#108;&#x74;&#111;&#x3a;&#116;&#x6a;&#x40;&#118;&#x69;&#x73;&#105;&#111;&#110;&#45;&#x6d;&#101;&#100;&#x69;&#x61;&#x2e;&#x63;&#x61;" data-bare-link="true">&#116;&#x6a;&#x40;&#118;&#x69;&#x73;&#x69;&#111;&#110;&#x2d;&#x6d;&#101;&#100;&#x69;&#x61;&#x2e;&#x63;&#x61;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -190,9 +191,10 @@ authors :
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>August 2021</li>
<li class='tc'>December 2022</li>
<li class='tr'>git-summary(1)</li>
</ol>

View file

@ -51,12 +51,14 @@ Shows a summary of the repository or a path within it.
$ git summary
project : express
repo age : 10 months ago
commits : 1893
active : 93 days
files : 111
authors :
project : express
repo age : 10 months ago
last active : 3 weeks ago
active on : 93 days
commits : 1893
files : 111
uncommitted : 3
authors :
1285 visionmedia
478 Tj Holowaychuk
48 Aaron Heckmann