Sort committers by average length of commit message

git log --no-merges --pretty=format:'COMMIT_START|%an|%B|COMMIT_END' | \
awk '
BEGIN { RS = "COMMIT_END\n"; FS = "|" }
/COMMIT_START/ {
    author = $2
    message = ""
    for (i = 3; i <= NF; i++) {
        if (i > 3) message = message "|"
        message = message $i
    }
    len = length(message)
    authors[author] += len
    counts[author]++
    if (!min[author] || len < min[author]) min[author] = len
    if (len > max[author]) max[author] = len
}
END {
    for (author in authors) {
        avg = authors[author] / counts[author]
        printf "%6.1f|%-30s|(min: %d, max: %d, commits: %d)\n",
               avg, author, min[author], max[author], counts[author]
    }
}' | sort -t'|' -k1 -nr | awk -F'|' '{printf "%-30s %s chars %s\n", $2, $1, $3}'

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.