From d0d67d27ae4568ec8d68a6277717d1a0200673b4 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Mon, 17 Feb 2020 08:54:59 +0100 Subject: Keep track of file renames in the revision table --- scripts/generate_history.sh | 68 +++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 37 deletions(-) (limited to 'scripts') diff --git a/scripts/generate_history.sh b/scripts/generate_history.sh index b0d1b82..65de78e 100755 --- a/scripts/generate_history.sh +++ b/scripts/generate_history.sh @@ -1,60 +1,54 @@ #!/usr/bin/bash -function commits_count () { - local file=${1} - local res=$(git --no-pager log --pretty=format:"" "${file}" | wc -l) +FORMAT="{\"subject\":\"%s\",\"abbr_hash\":\"%h\",\"hash\":\"%H\",\"date\":\"%cs\"" + +function generate_history_json () { + local file="${1}" + + local logs=$(git --no-pager log --follow --pretty=format:"${FORMAT}" "${file}") if [ ! $? -eq 0 ]; then exit 1 fi - echo -n "$(( ${res} ))" -} + local count=0 + local name="${file}" + + while read -r line; do + local hash=$(echo "${line}}" | jq -j '.hash') + + local pre_name="$(git --no-pager show --stat=10000 ${hash} | sed -e 's/ *\(.*\){\(.*\) => \(.*\)}/\1\2 => \1\3/' | grep "=> ${name}" | xargs | cut -d' ' -f1)" + + if [[ ! -z "${pre_name}" ]]; then + name="$(echo ${pre_name})" + fi + + if [[ ${count} -eq 0 ]]; then + echo -n "[ " + else + echo -n ", " + fi + + echo "${line}, \"filename\":\"${name}\"}" -function print_commit_format () { - local file=${1} - local nth=${2} - local format=${3} + count=$(( ${count} + 1 )) + done < <(echo "${logs}") - git --no-pager log --skip=${nth} -n1 --pretty=format:"${format}" "${file}" + echo -n "]" } -function generate_json_history () { +function generate_json () { 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 " \"history\" : $(generate_history_json "${file}")" echo "}" } FILE=`cat` tmp_file=$(mktemp) -generate_json_history ${FILE} > ${tmp_file} +generate_json ${FILE} > ${tmp_file} haskell-mustache ${1} ${tmp_file} rm ${tmp_file} -- cgit v1.2.3