From 89306e57f6d03a30336008c15dbd636301a54c26 Mon Sep 17 00:00:00 2001 From: structix Date: Sat, 5 Jan 2019 01:51:12 +0100 Subject: [PATCH] Restructured in functions --- gitistics.sh | 110 +++++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/gitistics.sh b/gitistics.sh index e897608..ae31d05 100755 --- a/gitistics.sh +++ b/gitistics.sh @@ -10,59 +10,73 @@ REPOUSER="\(structix\|Janek\)" STARTDATE="01 Jan 2018" # -------------------- +# --- functions -# Switch into the REPODIR -pushd $REPODIR +# returns the amount of commits for one repository +function getCommits() { + # show amount of commits of all users + committemp=$(git rev-list --count --all --author=$REPOUSER --since="$STARTDATE") + echo $committemp +} -# total commits -commitcounter=0 +# get the amount of files, insertions, deletions by specifying parameters +function getDiffChanges() { + local __files=$1 + local __insert=$2 + local __delete=$3 -# total diff stats -totalfiles=0 -totalinsertions=0 -totaldeletions=0 + # calculate total changes between given date and HEAD + local extractdiff=$(git diff @{"$STARTDATE"} HEAD --shortstat) 2>/dev/null -# Iterate over all subdirectories -for dir in $REPODIR/*/ -do - dir=${dir%*/} - echo ${dir##*/} + # set the separator to , + local IFS=',' + local array=( $extractdiff ) + local f=$(( ${array[0]//[!0-9]} + __files)) + local i=$(( ${array[1]//[!0-9]} + __insert)) + local d=$(( ${array[2]//[!0-9]} + __delete)) - # enter directory - cd ${dir##*/} + eval $__files="'$f'" + eval $__insert="'$i'" + eval $__delete="'$d'" - # --- RUN COMMANDS +} - # show amount of commits of all users - committemp=$(git rev-list --count --all --author=$REPOUSER --since="$STARTDATE") +function main() { + # Switch into the REPODIR + pushd $REPODIR + + # Iterate over all subdirectories + for dir in $REPODIR/*/ + do + dir=${dir%*/} + echo ${dir##*/} + + # enter directory + cd ${dir##*/} + + # --- RUN COMMANDS + + commtemp=$(getCommits) + # Add to the total commit counter + commitcounter=$((commitcounter + commtemp)) + # Output the commit counter of the current iteration + echo $commtemp + + getDiffChanges totalfiles totalinsertions totaldeletions + + # go back + cd .. + done + + # Switch back to the original directory state + popd + + + echo "-------------------------" + echo "Total commits since $STARTDATE: $commitcounter" + echo "Total files changed: $totalfiles" + echo "Total insertions: $totalinsertions" + echo "Total deletions: $totaldeletions" +} - # Add to the total commit counter - commitcounter=$((commitcounter + committemp)) - - - # calculate total changes between given date and HEAD - extractdiff=$(git diff @{"$STARTDATE"} HEAD --shortstat) 2>/dev/null - - # set the separator to , - IFS=',' - array=( $extractdiff ) - totalfiles=$(( ${array[0]//[!0-9]} + totalfiles)) - totalinsertions=$(( ${array[1]//[!0-9]} + totalinsertions)) - totaldeletions=$(( ${array[2]//[!0-9]} + totaldeletions)) - - - # ------------------ - # Output the commit counter of the current iteration - echo $committemp - - # go back - cd .. -done - -echo "Total commits since $STARTDATE: $commitcounter" -echo "Total files changed: $totalfiles" -echo "Total insertions: $totalinsertions" -echo "Total deletions: $totaldeletions" - -# Switch back to the original directory state -popd +main