diff options
Diffstat (limited to 'scripts/generate_history.sh')
-rwxr-xr-x | scripts/generate_history.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/generate_history.sh b/scripts/generate_history.sh new file mode 100755 index 0000000..b0d1b82 --- /dev/null +++ b/scripts/generate_history.sh @@ -0,0 +1,60 @@ +#!/usr/bin/bash + +function commits_count () { + local file=${1} + local res=$(git --no-pager log --pretty=format:"" "${file}" | wc -l) + + if [ ! $? -eq 0 ]; then + exit 1 + fi + + echo -n "$(( ${res} ))" +} + +function print_commit_format () { + local file=${1} + local nth=${2} + local format=${3} + + git --no-pager log --skip=${nth} -n1 --pretty=format:"${format}" "${file}" +} + +function generate_json_history () { + local file="${1}" + local count=$(commits_count ${file}) + + echo "{" + echo " \"file\" : \"${file}\"," + echo " \"history\" :" + echo " [" + for i in $(seq 0 ${count}); do + subject="$(print_commit_format ${file} ${i} '%s')" + abbr_hash="$(print_commit_format ${file} ${i} '%h')" + hash="$(print_commit_format ${file} ${i} '%H')" + date="$(print_commit_format ${file} ${i} '%cs')" + + echo " {" + echo " \"subject\" : \"${subject}\"," + echo " \"abbr_hash\" : \"${abbr_hash}\"," + echo " \"hash\" : \"${hash}\"," + echo " \"date\" : \"${date}\"" + echo -n \ + " }" + + if [ ! ${i} -eq ${count} ]; then + echo "," + else + echo "" + fi + done + + echo " ]" + echo "}" +} + +FILE=`cat` + +tmp_file=$(mktemp) +generate_json_history ${FILE} > ${tmp_file} +haskell-mustache ${1} ${tmp_file} +rm ${tmp_file} |