Skip to content

Filter authors by commit count #1059

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
22 changes: 8 additions & 14 deletions bin/git-summary
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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}"');
}
Expand Down Expand Up @@ -211,7 +207,7 @@ uncommitted_changes_count() {
}

number_of_authors() {
wc -l ${authors_file:?}|cut -d$' ' -f1
echo "${AUTHOR_LISTING:?}" | wc -l
}


Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since AUTHOR_LISTING and format_authors are in the same function, could we pass AUTHOR_LISTING as an argument to format_authors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, now both format_authors and number_of_authors take the listing as an argument.

fi
}

Expand All @@ -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
}

Expand Down