From 38a14f0951f3bcd7afe009bf532ef1be9ffed357 Mon Sep 17 00:00:00 2001 From: Tobias Fendin Date: Thu, 27 Jul 2023 17:28:09 +0200 Subject: [PATCH 1/4] git-summary: Before listing authors, print how many there are. --- bin/git-summary | 24 +++++++++++++++++++----- man/git-summary.1 | 8 ++++---- man/git-summary.html | 8 ++++---- man/git-summary.md | 6 +++--- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index ddb72cd2d..d8e568ef3 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -3,6 +3,12 @@ cd "$(git root)" || { echo "Can't cd to top level directory";exit 1; } +authors_file= +_exit() { + rm -f "${authors_file}" +} +trap '_exit' EXIT + SUMMARY_BY_LINE= DEDUP_BY_EMAIL= MERGES_ARG= @@ -194,6 +200,10 @@ uncommitted_changes_count() { git status --porcelain | wc -l } +number_of_authors() { + wc -l ${authors_file:?}|cut -d$' ' -f1 +} + COLUMN_CMD_DELIMTER="¬" # Hopefully, this symbol is not used in branch names... I use it as a separator for columns SP="$COLUMN_CMD_DELIMTER|" @@ -208,8 +218,10 @@ print_summary_by_line() { echo echo " project : $project" echo " lines : $(line_count "${paths[@]}")" - echo " authors :" - lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors + authors_file=$(git_extra_mktemp) + lines "${paths[@]}" | sort | uniq -c | sort -rn >${authors_file} + echo " authors : $(number_of_authors)" + format_authors <${authors_file} fi } @@ -235,15 +247,17 @@ print_summary() { echo " files : $(file_count)" fi echo " uncommitted : $(uncommitted_changes_count)" - echo " authors : " + authors_file=$(git_extra_mktemp) 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 + git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email >${authors_file} else # shellcheck disable=SC2086 - git shortlog $MERGES_ARG -n -s $commit | format_authors + git shortlog $MERGES_ARG -n -s $commit >${authors_file} fi + echo " authors : $(number_of_authors)" + format_authors <${authors_file} fi } diff --git a/man/git-summary.1 b/man/git-summary.1 index 87a3085a8..c5a42c748 100644 --- a/man/git-summary.1 +++ b/man/git-summary.1 @@ -1,6 +1,6 @@ .\" 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" @@ -63,7 +63,7 @@ active on : 93 days commits : 1893 files : 111 uncommitted : 3 -authors : +authors : 18 1285 visionmedia 478 Tj Holowaychuk 48 Aaron Heckmann @@ -99,7 +99,7 @@ $ git summary \-\-line project : git\-extras lines : 26820 -authors : +authors : 206 \|\.\|\.\|\. .fi .IP "" 0 @@ -111,7 +111,7 @@ $ git summary \-\-line bin/ project : git\-extras lines : 4420 -authors : +authors : 141 \|\.\|\.\|\. .fi .IP "" 0 diff --git a/man/git-summary.html b/man/git-summary.html index ffcd49770..11d10bc0b 100644 --- a/man/git-summary.html +++ b/man/git-summary.html @@ -147,7 +147,7 @@

EXAMPLES

commits : 1893 files : 111 uncommitted : 3 -authors : +authors : 18 1285 visionmedia 478 Tj Holowaychuk 48 Aaron Heckmann @@ -180,7 +180,7 @@

EXAMPLES

project : git-extras lines : 26820 -authors : +authors : 206 ... @@ -190,7 +190,7 @@

EXAMPLES

project : git-extras lines : 4420 -authors : +authors : 141 ... @@ -221,7 +221,7 @@

SEE ALSO

  1. -
  2. June 2023
  3. +
  4. July 2023
  5. git-summary(1)
diff --git a/man/git-summary.md b/man/git-summary.md index 11ca4bbb0..9b277b907 100644 --- a/man/git-summary.md +++ b/man/git-summary.md @@ -72,7 +72,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 @@ -103,7 +103,7 @@ Shows a summary of the repository or a path within it. project : git-extras lines : 26820 - authors : + authors : 206 ... Filter with the path: @@ -112,7 +112,7 @@ Shows a summary of the repository or a path within it. project : git-extras lines : 4420 - authors : + authors : 141 ... Tabular summary From a595c6846719d870a74bc56c9ed0da4ad6b2236b Mon Sep 17 00:00:00 2001 From: Tobias Fendin Date: Thu, 27 Jul 2023 20:56:13 +0200 Subject: [PATCH 2/4] Added git summary --author-commit-limit option which filters author listing. --- bin/git-summary | 10 ++++++++++ man/git-summary.1 | 6 +++++- man/git-summary.html | 6 +++++- man/git-summary.md | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index d8e568ef3..718fb20ef 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -13,6 +13,7 @@ SUMMARY_BY_LINE= DEDUP_BY_EMAIL= MERGES_ARG= OUTPUT_STYLE= +AUTHOR_COMMIT_LIMIT=0 for arg in "$@"; do case "$arg" in --line) @@ -28,6 +29,10 @@ for arg in "$@"; do OUTPUT_STYLE="$2" shift ;; + --author-commit-limit) + AUTHOR_COMMIT_LIMIT="$2" + shift + ;; -*) >&2 echo "unknown argument $arg found" exit 1 @@ -143,9 +148,14 @@ format_authors() { # author name. However, Linux column utility will escape tab if separator # specified, so we do unesaping after it. 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) + break; printf "%s♪%2.1f%%\n", args[i], 100 * args[i] / sum } } diff --git a/man/git-summary.1 b/man/git-summary.1 index c5a42c748..e0293c37b 100644 --- a/man/git-summary.1 +++ b/man/git-summary.1 @@ -4,7 +4,7 @@ .SH "NAME" \fBgit\-summary\fR \- Show repository summary .SH "SYNOPSIS" -\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [] +\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [\-\-author\-commit\-limit ] [] .P \fBgit\-summary\fR \-\-line [] .SH "DESCRIPTION" @@ -38,6 +38,10 @@ $ git summary \-\-dedup\-by\-email .P Exclude merge commits\. .P +\-\-author\-commit\-limit +.P +Omit authors with less than 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 \. diff --git a/man/git-summary.html b/man/git-summary.html index 11d10bc0b..67dcdc78f 100644 --- a/man/git-summary.html +++ b/man/git-summary.html @@ -77,7 +77,7 @@

NAME

SYNOPSIS

-

git-summary [--dedup-by-email] [--no-merges] [<committish>]

+

git-summary [--dedup-by-email] [--no-merges] [--author-commit-limit <count>] [<committish>]

git-summary --line [<path>]

@@ -114,6 +114,10 @@

OPTIONS

Exclude merge commits.

+

--author-commit-limit <count>

+ +

Omit authors with less than <count> authored commits from author listing. Defaults to zero.

+

--line

Summarize with lines other than commits. diff --git a/man/git-summary.md b/man/git-summary.md index 9b277b907..5f69bb9f7 100644 --- a/man/git-summary.md +++ b/man/git-summary.md @@ -3,7 +3,7 @@ git-summary(1) -- Show repository summary ## SYNOPSIS -`git-summary` [--dedup-by-email] [--no-merges] [<committish>] +`git-summary` [--dedup-by-email] [--no-merges] [--author-commit-limit <count>] [<committish>] `git-summary` --line [<path>] @@ -39,6 +39,10 @@ Shows a summary of the repository or a path within it. Exclude merge commits. + --author-commit-limit <count> + + Omit authors with less than <count> authored commits from author listing. Defaults to zero. + --line Summarize with lines other than commits. From ed529f2461aff387a55ff064abef09f427caba36 Mon Sep 17 00:00:00 2001 From: Tobias Fendin Date: Sat, 29 Jul 2023 14:25:49 +0200 Subject: [PATCH 3/4] git-summary: Store author listing in a variable instead of a temporary file --- bin/git-summary | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index 718fb20ef..44f3b9227 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -3,11 +3,7 @@ cd "$(git root)" || { echo "Can't cd to top level directory";exit 1; } -authors_file= -_exit() { - rm -f "${authors_file}" -} -trap '_exit' EXIT +AUTHOR_LISTING= SUMMARY_BY_LINE= DEDUP_BY_EMAIL= @@ -147,7 +143,7 @@ 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 "${AUTHOR_LISTING:?}" | LC_ALL=C awk ' BEGIN { commitLimit = strtonum('"${AUTHOR_COMMIT_LIMIT}"'); } @@ -211,7 +207,7 @@ uncommitted_changes_count() { } number_of_authors() { - wc -l ${authors_file:?}|cut -d$' ' -f1 + echo "${AUTHOR_LISTING:?}" | wc -l } @@ -228,10 +224,9 @@ print_summary_by_line() { echo echo " project : $project" echo " lines : $(line_count "${paths[@]}")" - authors_file=$(git_extra_mktemp) - lines "${paths[@]}" | sort | uniq -c | sort -rn >${authors_file} + AUTHOR_LISTING=$(lines "${paths[@]}" | sort | uniq -c | sort -rn) echo " authors : $(number_of_authors)" - format_authors <${authors_file} + format_authors fi } @@ -257,17 +252,16 @@ print_summary() { echo " files : $(file_count)" fi echo " uncommitted : $(uncommitted_changes_count)" - authors_file=$(git_extra_mktemp) 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 >${authors_file} + AUTHOR_LISTING=$(git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email) else # shellcheck disable=SC2086 - git shortlog $MERGES_ARG -n -s $commit >${authors_file} + AUTHOR_LISTING=$(git shortlog $MERGES_ARG -n -s $commit) fi echo " authors : $(number_of_authors)" - format_authors <${authors_file} + format_authors fi } From 930c9efa350addd368b2a8495abf90c5122e18a2 Mon Sep 17 00:00:00 2001 From: Tobias Fendin Date: Mon, 31 Jul 2023 21:12:51 +0200 Subject: [PATCH 4/4] git-summary: Don't use a global variable for author listing --- bin/git-summary | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/git-summary b/bin/git-summary index 44f3b9227..fece45465 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -143,7 +143,7 @@ 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. - echo "${AUTHOR_LISTING:?}" | LC_ALL=C awk ' + echo "${1:?}" | LC_ALL=C awk ' BEGIN { commitLimit = strtonum('"${AUTHOR_COMMIT_LIMIT}"'); } @@ -207,7 +207,7 @@ uncommitted_changes_count() { } number_of_authors() { - echo "${AUTHOR_LISTING:?}" | wc -l + echo "${1:?}" | wc -l } @@ -224,9 +224,9 @@ print_summary_by_line() { echo echo " project : $project" echo " lines : $(line_count "${paths[@]}")" - AUTHOR_LISTING=$(lines "${paths[@]}" | sort | uniq -c | sort -rn) - echo " authors : $(number_of_authors)" - format_authors + local AUTHOR_LISTING=$(lines "${paths[@]}" | sort | uniq -c | sort -rn) + echo " authors : $(number_of_authors "${AUTHOR_LISTING}")" + format_authors "${AUTHOR_LISTING}" fi } @@ -252,6 +252,7 @@ print_summary() { echo " files : $(file_count)" fi echo " uncommitted : $(uncommitted_changes_count)" + local AUTHOR_LISTING if [ -n "$DEDUP_BY_EMAIL" ]; then # the $commit can be empty # shellcheck disable=SC2086 @@ -260,8 +261,8 @@ print_summary() { # shellcheck disable=SC2086 AUTHOR_LISTING=$(git shortlog $MERGES_ARG -n -s $commit) fi - echo " authors : $(number_of_authors)" - format_authors + echo " authors : $(number_of_authors "${AUTHOR_LISTING}")" + format_authors "${AUTHOR_LISTING}" fi }