Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active September 20, 2020 15:10
Show Gist options
  • Save sroccaserra/0faf0a10732c279bff521a61cc591c56 to your computer and use it in GitHub Desktop.
Save sroccaserra/0faf0a10732c279bff521a61cc591c56 to your computer and use it in GitHub Desktop.
Measure SLOC evolution in time
#!/usr/bin/env bash
branch="$(git rev-parse --abbrev-ref HEAD)"
dir=api
echo "Starting from branch: $branch"
commits_with_dates=()
function find_commits() {
for i in $(seq 2020 2018)
do
for j in $(seq -w 12 1)
do
local year_month="$i-$j"
echo "Searching commit for: $year_month"
local commit
commit=$(git log --after=\'"$year_month"-01\' --before=\'"$year_month"-08\' --simplify-merges --pretty='format:%h' "$dir" | tail -1)
if [ -z "$commit" ]
then
echo "INFO: No commit found."
else
commits_with_dates+=("$commit $year_month-01")
fi
done
done
}
function process_commits() {
for commit_with_date in "${commits_with_dates[@]}"
do
printf '%s ' "$commit_with_date"
local commit
commit="$(echo $commit_with_date | awk '{ print $1 }')"
git checkout "$commit" > /dev/null 2>&1
tokei -e node_modules "$dir" | grep JavaScript | awk '{ print $4 }'
done
}
function restore_position() {
git checkout "$branch"
}
find_commits
process_commits
restore_position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment