-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #790 from spacewander/git-summary-merge-email
git-summary: add --dedup-by-email to remove duplicate users
- Loading branch information
Showing
5 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
# 7 罗泽轩 <[email protected]> | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters