Skip to content

Instantly share code, notes, and snippets.

@ragulpr
Created April 27, 2018 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ragulpr/490dc4ed9ef499c6aed105cc35f29fa5 to your computer and use it in GitHub Desktop.
Save ragulpr/490dc4ed9ef499c6aed105cc35f29fa5 to your computer and use it in GitHub Desktop.
Exports all git logs in tree as csv
#!/bin/bash
# Go to a git-repository and neatly export the commit log.
# assumes "_Z_Z_Z_" and "_Y_Y_" "_X_X_" as unused characters
# (just some improbable string i wrote)
# Truncate subject line sanitized (%f) or not (%s) to 79 %<(79,trunc)%f
for repo in $(ls -d */) ; do
echo $repo
cd $repo
inside_git_repo="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
if [ "$inside_git_repo" ]; then
git pull;
git submodule update --recursive --remote;
FILENAME="$(echo $repo|sed s/\\///).csv"
echo commit,author_name,time_sec,subject,files_changed,lines_inserted,lines_deleted>../logs/$FILENAME;
git log --oneline --pretty="_Z_Z_Z_%h_Y_Y_\"%an\"_Y_Y_%at_Y_Y_\"%<(79,trunc)%f\"_Y_Y__X_X_" --stat \
| grep -v \| \
| sed -E 's/@//g' \
| sed -E 's/_Z_Z_Z_/@/g' \
| tr "\n" " " \
| tr "@" "\n" |sed -E 's/,//g' \
| sed -E 's/_Y_Y_/, /g' \
| sed -E 's/(changed [0-9].*\+\))/,\1,/' \
| sed -E 's/(changed [0-9]* deleti.*-\)) /,,\1/' \
| sed -E 's/insertion.*\+\)//g' \
| sed -E 's/deletion.*\-\)//g' \
| sed -E 's/,changed/,/' \
| sed -E 's/files? ,/,/g' \
| sed -E 's/_X_X_ $/,,/g' \
| sed -E 's/_X_X_//g' \
| sed -E 's/ +,/,/g' \
| sed -E 's/, +/,/g'>>../logs/$FILENAME;
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment