mirror of
https://github.com/tj/git-extras.git
synced 2026-09-12 08:26:17 -04:00
Merge pull request #790 from spacewander/git-summary-merge-email
git-summary: add --dedup-by-email to remove duplicate users
This commit is contained in:
commit
a14547e92f
|
|
@ -3,8 +3,32 @@
|
|||
|
||||
cd "$(git root)" || { echo "Can't cd to top level directory";exit 1; }
|
||||
|
||||
SUMMARY_BY_LINE=
|
||||
DEDUP_BY_EMAIL=
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--line)
|
||||
SUMMARY_BY_LINE=1
|
||||
;;
|
||||
--dedup-by-email)
|
||||
DEDUP_BY_EMAIL=1
|
||||
;;
|
||||
*)
|
||||
# set the argument back
|
||||
set -- "$@" "$arg"
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -n "$DEDUP_BY_EMAIL" ] && [ -n "$SUMMARY_BY_LINE" ]; then
|
||||
>&2 echo "--dedup-by-email used with --line is not supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
commit=""
|
||||
test $# -ne 0 && commit=$@
|
||||
test $# -ne 0 && commit=$*
|
||||
project=${PWD##*/}
|
||||
|
||||
#
|
||||
|
|
@ -31,6 +55,7 @@ active_days() {
|
|||
#
|
||||
|
||||
commit_count() {
|
||||
# shellcheck disable=SC2086
|
||||
git log --oneline $commit | wc -l | tr -d ' '
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +67,46 @@ file_count() {
|
|||
git ls-files | wc -l | tr -d ' '
|
||||
}
|
||||
|
||||
#
|
||||
# remove duplicate authors who belong to the same email address
|
||||
#
|
||||
|
||||
dedup_by_email() {
|
||||
# in:
|
||||
# 27 luo zexuan <luozexuan@xxx.com>
|
||||
# 7 罗泽轩 <luozexuan@xxx.com>
|
||||
# out:
|
||||
# 34 luo zexuan
|
||||
LC_ALL=C awk '
|
||||
{
|
||||
sum += $1
|
||||
if ($NF in emails) {
|
||||
emails[$NF] += $1
|
||||
} else {
|
||||
email = $NF
|
||||
emails[email] = $1
|
||||
# set commits/email to empty
|
||||
$1=$NF=""
|
||||
sub(/^[[:space:]]+/, "", $0)
|
||||
sub(/[[:space:]]+$/, "", $0)
|
||||
name = $0
|
||||
if (name in names) {
|
||||
# when the same name is associated with existed email,
|
||||
# merge the previous email into the later one.
|
||||
emails[email] += emails[names[name]]
|
||||
emails[names[name]] = 0
|
||||
}
|
||||
names[name] = email
|
||||
}
|
||||
}
|
||||
END {
|
||||
for (name in names) {
|
||||
email = names[name]
|
||||
printf "%6d\t%s\n", emails[email], name
|
||||
}
|
||||
}' | sort -rn -k 1
|
||||
}
|
||||
|
||||
#
|
||||
# list authors
|
||||
#
|
||||
|
|
@ -110,7 +175,7 @@ result() {
|
|||
echo
|
||||
echo " project : $project"
|
||||
|
||||
if test "$1" = "--line"; then
|
||||
if [ -n "$SUMMARY_BY_LINE" ]; then
|
||||
echo " lines : $(line_count)"
|
||||
echo " authors :"
|
||||
lines | sort | uniq -c | sort -rn | format_authors
|
||||
|
|
@ -120,8 +185,15 @@ else
|
|||
echo " active :" $(active_days) days
|
||||
echo " commits :" $(commit_count)
|
||||
if test "$commit" = ""; then
|
||||
echo " files :" $(file_count)
|
||||
echo " files :" "$(file_count)"
|
||||
fi
|
||||
echo " authors : "
|
||||
git shortlog -n -s $commit | format_authors
|
||||
if [ -n "$DEDUP_BY_EMAIL" ]; then
|
||||
# the $commit can be empty
|
||||
# shellcheck disable=SC2086
|
||||
git shortlog -n -s -e $commit | dedup_by_email | format_authors
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
git shortlog -n -s $commit | format_authors
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -423,6 +423,7 @@ _git-standup() {
|
|||
|
||||
_git-summary() {
|
||||
_arguments '--line[summarize with lines rather than commits]'
|
||||
_arguments '--dedup-by-email[remove duplicate users by the email address]'
|
||||
__gitex_commits
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
\fBgit\-summary\fR \- Show repository summary
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
\fBgit\-summary\fR [\-\-line] [<commitish>]
|
||||
\fBgit\-summary\fR [\-\-line] [\-\-dedup\-by\-email] [<commitish>]
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Shows a summary of the repository\.
|
||||
|
|
@ -19,6 +19,32 @@ Shows a summary of the repository\.
|
|||
Summarize only the range of commits included in the <commitish>\.
|
||||
.
|
||||
.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
|
||||
This option can not be used together with \fB\-\-line\fR\.
|
||||
.
|
||||
.P
|
||||
\-\-line
|
||||
.
|
||||
.P
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-summary</code> [--line] [<commitish>]</p>
|
||||
<p><code>git-summary</code> [--line] [--dedup-by-email] [<commitish>]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
|
|
@ -88,6 +88,23 @@
|
|||
|
||||
<p> Summarize only the range of commits included in the <commitish>.</p>
|
||||
|
||||
<p> --dedup-by-email</p>
|
||||
|
||||
<p> Remove duplicate authors who belong to the same email address.
|
||||
For example,</p>
|
||||
|
||||
<pre><code>$ git summary
|
||||
...
|
||||
133 TJ Holowaychuk 9.9%
|
||||
115 Tj Holowaychuk 8.5%
|
||||
|
||||
$ git summary --dedup-by-email
|
||||
...
|
||||
248 TJ Holowaychuk 18.4%
|
||||
</code></pre>
|
||||
|
||||
<p> This option can not be used together with <code>--line</code>.</p>
|
||||
|
||||
<p> --line</p>
|
||||
|
||||
<p> Summarize with lines other than commits.
|
||||
|
|
@ -145,7 +162,7 @@ authors :
|
|||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Tj Holowaychuk <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>></p>
|
||||
<p>Written by Tj Holowaychuk <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ git-summary(1) -- Show repository summary
|
|||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-summary` [--line] [<commitish>]
|
||||
`git-summary` [--line] [--dedup-by-email] [<commitish>]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
|
|
@ -15,6 +15,22 @@ Shows a summary of the repository.
|
|||
|
||||
Summarize only the range of commits included in the <commitish>.
|
||||
|
||||
--dedup-by-email
|
||||
|
||||
Remove duplicate authors who belong to the same email address.
|
||||
For example,
|
||||
|
||||
$ git summary
|
||||
...
|
||||
133 TJ Holowaychuk 9.9%
|
||||
115 Tj Holowaychuk 8.5%
|
||||
|
||||
$ git summary --dedup-by-email
|
||||
...
|
||||
248 TJ Holowaychuk 18.4%
|
||||
|
||||
This option can not be used together with `--line`.
|
||||
|
||||
--line
|
||||
|
||||
Summarize with lines other than commits.
|
||||
|
|
|
|||
Loading…
Reference in a new issue