Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter authors by commit count #1059

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions bin/git-summary
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

cd "$(git root)" || { echo "Can't cd to top level directory";exit 1; }

AUTHOR_LISTING=

SUMMARY_BY_LINE=
DEDUP_BY_EMAIL=
MERGES_ARG=
OUTPUT_STYLE=
AUTHOR_COMMIT_LIMIT=0
for arg in "$@"; do
case "$arg" in
--line)
Expand All @@ -22,6 +25,10 @@ for arg in "$@"; do
OUTPUT_STYLE="$2"
shift
;;
--author-commit-limit)
AUTHOR_COMMIT_LIMIT="$2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if the commit limit exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should. I Just copied the code for --output-style.

shift
;;
-*)
>&2 echo "unknown argument $arg found"
exit 1
Expand Down Expand Up @@ -136,10 +143,15 @@ 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
# specified, so we do unesaping after it.
LC_ALL=C awk '
echo "${1:?}" | LC_ALL=C awk '
BEGIN {
commitLimit = strtonum('"${AUTHOR_COMMIT_LIMIT}"');
}
{ args[NR] = $0; sum += $0 }
END {
for (i = 1; i <= NR; ++i) {
if (strtonum(args[i]) < commitLimit)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strtonum seems to be GNU awk extension, can we find an alternative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's unnecessary to call strtonum at all, the comparison should work anyway.

break;
printf "%s♪%2.1f%%\n", args[i], 100 * args[i] / sum
}
}
Expand Down Expand Up @@ -194,6 +206,10 @@ uncommitted_changes_count() {
git status --porcelain | wc -l
}

number_of_authors() {
echo "${1:?}" | wc -l
}


COLUMN_CMD_DELIMTER="¬" # Hopefully, this symbol is not used in branch names... I use it as a separator for columns
SP="$COLUMN_CMD_DELIMTER|"
Expand All @@ -208,8 +224,9 @@ print_summary_by_line() {
echo
echo " project : $project"
echo " lines : $(line_count "${paths[@]}")"
echo " authors :"
lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors
local AUTHOR_LISTING=$(lines "${paths[@]}" | sort | uniq -c | sort -rn)
echo " authors : $(number_of_authors "${AUTHOR_LISTING}")"
format_authors "${AUTHOR_LISTING}"
fi
}

Expand All @@ -235,15 +252,17 @@ print_summary() {
echo " files : $(file_count)"
fi
echo " uncommitted : $(uncommitted_changes_count)"
echo " authors : "
local AUTHOR_LISTING
if [ -n "$DEDUP_BY_EMAIL" ]; then
# the $commit can be empty
# shellcheck disable=SC2086
git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email | format_authors
AUTHOR_LISTING=$(git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email)
else
# shellcheck disable=SC2086
git shortlog $MERGES_ARG -n -s $commit | format_authors
AUTHOR_LISTING=$(git shortlog $MERGES_ARG -n -s $commit)
fi
echo " authors : $(number_of_authors "${AUTHOR_LISTING}")"
format_authors "${AUTHOR_LISTING}"
fi
}

Expand Down
14 changes: 9 additions & 5 deletions man/git-summary.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "GIT\-SUMMARY" "1" "June 2023" "" "Git Extras"
.TH "GIT\-SUMMARY" "1" "July 2023" "" "Git Extras"
.SH "NAME"
\fBgit\-summary\fR \- Show repository summary
.SH "SYNOPSIS"
\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [<committish>]
\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [\-\-author\-commit\-limit <count>] [<committish>]
.P
\fBgit\-summary\fR \-\-line [<path>]
.SH "DESCRIPTION"
Expand Down Expand Up @@ -38,6 +38,10 @@ $ git summary \-\-dedup\-by\-email
.P
Exclude merge commits\.
.P
\-\-author\-commit\-limit <count>
.P
Omit authors with less than <count> authored commits from author listing\. Defaults to zero\.
.P
\-\-line
.P
Summarize with lines other than commits\. When \fB\-\-line\fR is specified, the last argument is treated as <path>\.
Expand All @@ -63,7 +67,7 @@ active on : 93 days
commits : 1893
files : 111
uncommitted : 3
authors :
authors : 18
1285 visionmedia
478 Tj Holowaychuk
48 Aaron Heckmann
Expand Down Expand Up @@ -99,7 +103,7 @@ $ git summary \-\-line

project : git\-extras
lines : 26820
authors :
authors : 206
\|\.\|\.\|\.
.fi
.IP "" 0
Expand All @@ -111,7 +115,7 @@ $ git summary \-\-line bin/

project : git\-extras
lines : 4420
authors :
authors : 141
\|\.\|\.\|\.
.fi
.IP "" 0
Expand Down
14 changes: 9 additions & 5 deletions man/git-summary.html

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

12 changes: 8 additions & 4 deletions man/git-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git-summary(1) -- Show repository summary

## SYNOPSIS

`git-summary` [--dedup-by-email] [--no-merges] [&lt;committish&gt;]
`git-summary` [--dedup-by-email] [--no-merges] [--author-commit-limit &lt;count&gt;] [&lt;committish&gt;]

`git-summary` --line [&lt;path&gt;]

Expand Down Expand Up @@ -39,6 +39,10 @@ Shows a summary of the repository or a path within it.

Exclude merge commits.

--author-commit-limit &lt;count&gt;

Omit authors with less than &lt;count&gt; authored commits from author listing. Defaults to zero.

--line

Summarize with lines other than commits.
Expand Down Expand Up @@ -72,7 +76,7 @@ Shows a summary of the repository or a path within it.
commits : 1893
files : 111
uncommitted : 3
authors :
authors : 18
1285 visionmedia
478 Tj Holowaychuk
48 Aaron Heckmann
Expand Down Expand Up @@ -103,7 +107,7 @@ Shows a summary of the repository or a path within it.

project : git-extras
lines : 26820
authors :
authors : 206
...

Filter with the path:
Expand All @@ -112,7 +116,7 @@ Shows a summary of the repository or a path within it.

project : git-extras
lines : 4420
authors :
authors : 141
...

Tabular summary
Expand Down