From ffb646963178e57f7db8d10dd6fd536afa69dfbc Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Mon, 13 Jul 2015 14:47:50 +0100 Subject: [PATCH 1/9] updated bash scripts and made them executable --- determine_authors.sh | 1 + file_stats.sh | 2 ++ 2 files changed, 3 insertions(+) mode change 100644 => 100755 file_stats.sh diff --git a/determine_authors.sh b/determine_authors.sh index aa7b473..45c8d0f 100755 --- a/determine_authors.sh +++ b/determine_authors.sh @@ -1,3 +1,4 @@ +#!/bin/bash # determine who are the key authors on the site; this file collects the data, another # (Ruby) file sorts it to determine an **extremely** primitive measure of authority diff --git a/file_stats.sh b/file_stats.sh old mode 100644 new mode 100755 index 01348a4..633de67 --- a/file_stats.sh +++ b/file_stats.sh @@ -1,3 +1,5 @@ +#!/bin/bash + function git_history { git log $filename | grep "Date: " } From 034d216ce5b8bc3c91e1f7e12f0698329420116e Mon Sep 17 00:00:00 2001 From: Matteo 'Peach' Pescarin Date: Tue, 14 Jul 2015 21:44:39 +0100 Subject: [PATCH 2/9] renamed readme to all caps --- readme.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename readme.md => README.md (100%) diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md From efa4579180ae8676271e92846629a3f96d0119e1 Mon Sep 17 00:00:00 2001 From: Matteo 'Peach' Pescarin Date: Tue, 14 Jul 2015 22:05:29 +0100 Subject: [PATCH 3/9] updated script to use getopts and added usage function and exit status --- determine_authors.sh | 46 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/determine_authors.sh b/determine_authors.sh index 45c8d0f..96c811e 100755 --- a/determine_authors.sh +++ b/determine_authors.sh @@ -1,19 +1,39 @@ #!/bin/bash -# determine who are the key authors on the site; this file collects the data, another -# (Ruby) file sorts it to determine an **extremely** primitive measure of authority +CMD=`basename $0`; -# usage: determine_authors.sh [filetype] -# -# e.g. determine_authors.sh "js" # examines authorship for *.js files -# determine_authors.sh "handlebars" -# determine_authors.sh "ruby" -# determine_authors.sh "et_cetera" +# prints the usage message +function usage() { + echo -e "$CMD is a simple script to extract the list of GIT authors from +the files contained in the current directory. +It can be used to extract information only on specific file extensions.\n +Syntax: $CMD [-h|] +\t-h: prints usage information +\t: display authors for specific filetype +\te.g. determine_authors.sh 'js' # examines authorship for *.js files +\n" +} -function generate_authors_file { - for filename in $(find . -iname "*.$1"); do - git log $filename | grep Author; - done +function extract_authors { + for filename in $(find . -iname "*.$1"); do + git log $filename | grep Author; + done } -generate_authors_file $1 +while getopts ":h" Option +do + case $Option in + h ) usage + exit 0;; + esac +done + +# initialise params +if [ $# -eq 1 ]; then + EXT=$1; +else + EXT='*'; +fi + +extract_authors "${EXT}" +exit 0 \ No newline at end of file From 7e52fae6ffc5c35d2f8f40ee6e5c8ca0798590b7 Mon Sep 17 00:00:00 2001 From: Matteo 'Peach' Pescarin Date: Tue, 14 Jul 2015 22:13:15 +0100 Subject: [PATCH 4/9] small copy fix --- determine_authors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/determine_authors.sh b/determine_authors.sh index 96c811e..9e4b080 100755 --- a/determine_authors.sh +++ b/determine_authors.sh @@ -9,7 +9,7 @@ It can be used to extract information only on specific file extensions.\n Syntax: $CMD [-h|] \t-h: prints usage information \t: display authors for specific filetype -\te.g. determine_authors.sh 'js' # examines authorship for *.js files +\te.g. determine_authors.sh js # examines authorship for *.js files \n" } From 75dac4c1c6e4cc0474b8a3e67af1cbb2109e6ad0 Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Sat, 18 Jul 2015 17:42:52 +0100 Subject: [PATCH 5/9] updated script and expanded its functionality - the file now can display most information without the need of rb scripts --- determine_authors.sh | 114 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 13 deletions(-) diff --git a/determine_authors.sh b/determine_authors.sh index 9e4b080..b72f261 100755 --- a/determine_authors.sh +++ b/determine_authors.sh @@ -3,37 +3,125 @@ CMD=`basename $0`; # prints the usage message function usage() { - echo -e "$CMD is a simple script to extract the list of GIT authors from + echo -e "$CMD is a script to extract the some info on GIT authors from the files contained in the current directory. It can be used to extract information only on specific file extensions.\n -Syntax: $CMD [-h|] +Syntax: $CMD [-h|-o|[-c] ] \t-h: prints usage information -\t: display authors for specific filetype +\t-o: displays just the overall commits count per author +\t-c: displays the files ordered by number of commits +\t-a: displays overall commits, and list of commits by author per each file +\t-d: just extract the authors, to be used in conjunction with tally_authors.rb +\t: display authors commit count for specific filetypes \te.g. determine_authors.sh js # examines authorship for *.js files \n" } +# returns the list of authors function extract_authors { - for filename in $(find . -iname "*.$1"); do - git log $filename | grep Author; + for filename in $(find . -iname "${PATTERN}"); do + git log $filename | grep "Author" done } -while getopts ":h" Option +# uses the log of a specific file to capture the number of commits per person +function count_author_commits_per_file { + if [[ ! -n $1 ]]; then + filename='' + else + filename=$1; + fi + git log --pretty=format:"%an <%ae>" $filename | awk '{ + authorsCount[$NF]++; + authors[$NF]=$0; + } + END { + for (i in authorsCount) + printf("%d\t%s\n", authorsCount[i], authors[i]); + }'; +} + +function tally_authors { + if [[ -n $OVERALL_ONLY ]]; then + echo "Overall"; + count_author_commits_per_file | sort -k1,1nr -k2,2; + return + fi + for filename in $(find . -iname "${PATTERN}" -not -wholename "*.git*" -not -wholename "*.svn*"); do + authors=`count_author_commits_per_file $filename | sort -k1,1nr -k2,2`; + if [ "$authors" = "" ]; then + continue; + fi + if [ $filename = '.' ]; then + echo "Overall" + else + echo $filename; + fi + echo "$authors"; + done +} + +function count_commits_per_file { + for filename in $(find . -iname "${PATTERN}" -not -wholename "*.git*" -not -wholename "*.svn*"); do + commits_count=`git rev-list HEAD --count ${filename}`; + if [ $commits_count -gt 0 ]; then + echo -e "${commits_count}\t${filename}"; + fi + done +} + +function sort_files_by_commits { + file_commits=`count_commits_per_file | sort -k1,1nr -k2,2`; + if [[ -n $ALL_STATS ]]; then + echo "${file_commits}" | while read line; do + tot_commits=`echo ${line} | awk '{ print $1 }'`; + filename=`echo "${line}" | awk '{ sub(/.*\t/, ""); print }'`; + echo ${filename}; + echo "${tot_commits} total commit(s)" + count_author_commits_per_file $filename | sort -k1,1nr -k2,2; + echo ""; + done + else + echo "$file_commits"; + fi +} + +while getopts ":hocad" Option do case $Option in - h ) usage - exit 0;; + h) usage + exit 0 + ;; + o) OVERALL_ONLY=true + ;; + c) FILE_COMMITS_ONLY=true + ;; + a) ALL_STATS=true + ;; + d) DEPRECATED=true + ;; esac done -# initialise params +# Decrements the argument pointer so it points to next argument. +# $1 now references the first non-option item supplied on the command-line +# if one exists. +shift $(($OPTIND - 1)) + if [ $# -eq 1 ]; then - EXT=$1; + PATTERN="*.$1"; else - EXT='*'; + PATTERN='*.*'; fi -extract_authors "${EXT}" +if [[ -n $FILE_COMMITS_ONLY ]]; then + sort_files_by_commits; +elif [[ -n $ALL_STATS ]]; then + sort_files_by_commits; +elif [[ -n $DEPRECATED ]]; then + extract_authors; +else + tally_authors "${PATTERN}"; +fi -exit 0 \ No newline at end of file +exit 0 From 6fd56e5744a2b056d26226d9aa2e60d5759a4dd7 Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Sat, 18 Jul 2015 17:46:43 +0100 Subject: [PATCH 6/9] renamed script and updated README --- README.md | 6 +++--- determine_authors.sh => basic_stats.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename determine_authors.sh => basic_stats.sh (98%) diff --git a/README.md b/README.md index 55a75cf..276afeb 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,13 @@ Or: ## authorship This is more tricky, and requires Ruby. First run the -`determine_authors.sh` script to get a count of all the authorship +`basic_stats.sh` script to get a count of all the authorship events in the repo; then run the `tally_authors.rb` Ruby script to sort the authorship events by name. You can do all that as a one-liner in bash like this: - ruby tally_authors.rb <(cd /project && /this_dir/determine_authors.sh "js") + ruby tally_authors.rb <(cd /project && /this_dir/basic_stats.sh -d "js") The code isn't tricky at all, and the output is easy to understand, but it's also easy to misconstrue. That's the tricky part. A developer @@ -47,7 +47,7 @@ commits to small ones, or for several other possible reasons. Exercise good judgement. Also, where `file_stats.sh` will examine multiple file types, -`determine_authors.sh` and `tally_authors.rb` assumes you're only +`basic_stats.sh` and `tally_authors.rb` assumes you're only working with one type of file at a time. Pull requests welcome! Caveat: Running this code against extremely large projects with very diff --git a/determine_authors.sh b/basic_stats.sh similarity index 98% rename from determine_authors.sh rename to basic_stats.sh index b72f261..31d1df2 100755 --- a/determine_authors.sh +++ b/basic_stats.sh @@ -6,7 +6,7 @@ function usage() { echo -e "$CMD is a script to extract the some info on GIT authors from the files contained in the current directory. It can be used to extract information only on specific file extensions.\n -Syntax: $CMD [-h|-o|[-c] ] +Syntax: $CMD [-h|-o|[-c|-a|-d] ] \t-h: prints usage information \t-o: displays just the overall commits count per author \t-c: displays the files ordered by number of commits From f7724b6091ef5290c6757631159748c428e7d09f Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Wed, 26 Apr 2017 12:12:03 +0100 Subject: [PATCH 7/9] GIT is not an acronym ;) fixed --- basic_stats.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic_stats.sh b/basic_stats.sh index 31d1df2..a966732 100755 --- a/basic_stats.sh +++ b/basic_stats.sh @@ -3,7 +3,7 @@ CMD=`basename $0`; # prints the usage message function usage() { - echo -e "$CMD is a script to extract the some info on GIT authors from + echo -e "$CMD is a script to extract the some info on git authors from the files contained in the current directory. It can be used to extract information only on specific file extensions.\n Syntax: $CMD [-h|-o|[-c|-a|-d] ] From 0bfe9685d5ef7523d8edc7cd466a60b6b43adcc7 Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Fri, 28 Apr 2017 12:04:07 +0100 Subject: [PATCH 8/9] updated usage help --- basic_stats.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/basic_stats.sh b/basic_stats.sh index a966732..a753737 100755 --- a/basic_stats.sh +++ b/basic_stats.sh @@ -3,17 +3,20 @@ CMD=`basename $0`; # prints the usage message function usage() { - echo -e "$CMD is a script to extract the some info on git authors from + echo -e "$CMD is a script to extract some basic info on git authors from the files contained in the current directory. -It can be used to extract information only on specific file extensions.\n +If invoked without parameters it will output the overall list of commits count +per author (-o) followed by the list of files in the current directory with +the commit count for each author. +It can also be used to extract information on specific file extensions.\n Syntax: $CMD [-h|-o|[-c|-a|-d] ] -\t-h: prints usage information +\t-h: prints this help \t-o: displays just the overall commits count per author \t-c: displays the files ordered by number of commits \t-a: displays overall commits, and list of commits by author per each file \t-d: just extract the authors, to be used in conjunction with tally_authors.rb \t: display authors commit count for specific filetypes -\te.g. determine_authors.sh js # examines authorship for *.js files +\te.g. $CMD js # examines authorship for *.js files \n" } From 8f7bdb2e0cb9a368730646910a91aaaf149897b0 Mon Sep 17 00:00:00 2001 From: Matteo Pescarin Date: Fri, 28 Apr 2017 12:32:09 +0100 Subject: [PATCH 9/9] renamed file and updated README - renamed basic_stats as commits_stats - updated references in README --- README.md | 6 +++--- basic_stats.sh => commits_stats.sh | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) rename basic_stats.sh => commits_stats.sh (93%) diff --git a/README.md b/README.md index 276afeb..1ad1a22 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,13 @@ Or: ## authorship This is more tricky, and requires Ruby. First run the -`basic_stats.sh` script to get a count of all the authorship +`commits_stats.sh` script to get a count of all the authorship events in the repo; then run the `tally_authors.rb` Ruby script to sort the authorship events by name. You can do all that as a one-liner in bash like this: - ruby tally_authors.rb <(cd /project && /this_dir/basic_stats.sh -d "js") + ruby tally_authors.rb <(cd /project && /this_dir/commits_stats.sh -d "js") The code isn't tricky at all, and the output is easy to understand, but it's also easy to misconstrue. That's the tricky part. A developer @@ -47,7 +47,7 @@ commits to small ones, or for several other possible reasons. Exercise good judgement. Also, where `file_stats.sh` will examine multiple file types, -`basic_stats.sh` and `tally_authors.rb` assumes you're only +`commits_stats.sh` and `tally_authors.rb` assumes you're only working with one type of file at a time. Pull requests welcome! Caveat: Running this code against extremely large projects with very diff --git a/basic_stats.sh b/commits_stats.sh similarity index 93% rename from basic_stats.sh rename to commits_stats.sh index a753737..1eee364 100755 --- a/basic_stats.sh +++ b/commits_stats.sh @@ -3,11 +3,11 @@ CMD=`basename $0`; # prints the usage message function usage() { - echo -e "$CMD is a script to extract some basic info on git authors from -the files contained in the current directory. -If invoked without parameters it will output the overall list of commits count -per author (-o) followed by the list of files in the current directory with -the commit count for each author. + echo -e "$CMD is a script to extract some basic info on git commits and +authors from the files contained in the current directory. +If invoked without parameters it will output the overall list of commits +count per author (-o) followed by the list of files with the commit count +for each author. It can also be used to extract information on specific file extensions.\n Syntax: $CMD [-h|-o|[-c|-a|-d] ] \t-h: prints this help