Last active
October 5, 2015 08:33
-
-
Save JohannesMP/1af441d14b09e5f2f48d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #details: this file is intended to be called from inside generate_csv.sh | |
| #usage: ./file_info.sh <Path to root> <Path to file> <blank lines int> <comment lines int> <code lines int> | |
| #example "<ABSOLUTE_PATH>/../../" | |
| OFFSET=$1 # how to get to the directory to search | |
| #example:'Source/Engine/main.cpp' | |
| SOURCEFILE=${2//###/ } | |
| # note: currently as a workaround spaces in filepaths are passed from generate_csv.sh as '###' | |
| # it's handled automatically so you shouldn't need to worry about it. | |
| LINES_BLANK=$3 | |
| LINES_COMMENT=$4 | |
| LINES_CODE=$5 | |
| LINES_TOTAL=$(($LINES_BLANK + $LINES_COMMENT + $LINES_CODE)) | |
| CODE_RATIO=$(echo $LINES_CODE / $LINES_TOTAL | bc -l) | |
| CODE_RATIO_ROUND=$(printf %.3f $CODE_RATIO) | |
| # using git blame on a single file path to figure out who worked on it (and line numbers) | |
| cd $OFFSET | |
| git blame "$SOURCEFILE" -e | awk -v file="$SOURCEFILE" ' | |
| { | |
| email_begin = index($0, "<") + 1; | |
| email_len = index($0, ">") - email_begin; | |
| email = substr($0,email_begin, email_len); | |
| print email " " file; | |
| } | |
| ' | sort | uniq -c | awk -v file="$SOURCEFILE" -v total=$LINES_TOTAL -v ratio=$CODE_RATIO ' | |
| { | |
| lines_normalized=($1 * ratio); | |
| email = $2 | |
| printf "%s, %s, %.0f\n", file, email, lines_normalized | |
| }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| cd ${0%/*} | |
| # please edit # | |
| NAME="Premake5_LibTest" | |
| # edit if necessary | |
| OUTPUT_FILE="GGEngine_Prototypes_"$NAME".csv" | |
| DIR="../"$NAME"/" | |
| # don't edit # | |
| SCRIPTPATH=`pwd -P` | |
| SOURCE_FILES='temp_source_files.txt' | |
| BLAME_SCRIPT="blame_info.sh" | |
| cd $DIR; | |
| # Step 1: use cloc for paths and line statistics; Stored in temporary file | |
| cloc . --by-file | grep "./" | grep -v "http://" | awk -F" " ' | |
| { | |
| path = substr($1,3,length($1)-2); | |
| vals = substr($0,length($1)+1, length($0)); | |
| sub(" ", "###", path); | |
| print path vals | |
| }' > $SCRIPTPATH/$SOURCE_FILES; | |
| # Run git blame on each path | |
| cd $SCRIPTPATH | |
| while read p; do | |
| sh $BLAME_SCRIPT $DIR $p | |
| done < $SOURCE_FILES | sort > $OUTPUT_FILE | |
| # Clean up temporary file | |
| rm $SCRIPTPATH/$SOURCE_FILES; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment