From 4979eaa69f4770ecc5512898198ddc534b7f013e Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sun, 13 Oct 2019 02:16:54 +0800 Subject: [PATCH] Support commits by co-authors https://github.com/arzzen/git-quick-stats/issues/70 Commits by multiple authors (co-authored-by) were only counted towards main author. Modified commitsPerAuthor() to include co-author's commits. --- git-quick-stats | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/git-quick-stats b/git-quick-stats index ea35b7f..4950871 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -453,14 +453,28 @@ function commitsPerDay() { ################################################################################ function commitsPerAuthor() { optionPicked "Git commits per author:" - git -c log.showSignature=false shortlog $_since $_until --no-merges -n -s \ - | sort -nr | LC_ALL=C awk ' - { args[NR] = $0; sum += $0 } - END { - for (i = 1; i <= NR; ++i) { - printf "%s,%2.1f%%\n", args[i], 100 * args[i] / sum - } - }' | column -t -s, + local authorCommits=$(git -c log.showSignature=false log --use-mailmap --no-merges \ + $_since $_until | grep -i Author: | cut -c9-) + local coAuthorCommits=$(git -c log.showSignature=false log --use-mailmap --no-merges \ + $_since $_until | grep -i Co-Authored-by: | cut -c21-) + + if [[ -z "${coAuthorCommits}" ]] + then + allCommits="${authorCommits}" + else + allCommits="${authorCommits}\n${coAuthorCommits}" + fi + + echo -e "${allCommits}" | awk ' + { $NF=""; author[NR] = $0 } + END { + for(i in author) { + sum[author[i]]++; name[author[i]] = author[i]; total++; + } + for(i in sum) { + printf "\t%d,%s,%2.1f%%\n", sum[i], name[i], (100 * sum[i] / total) + } + }' | sort -n -r | column -t -s, } ################################################################################