summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorThomas Letan <lthms@soap.coffee>2020-02-17 08:54:59 +0100
committerThomas Letan <lthms@soap.coffee>2020-02-17 08:54:59 +0100
commitd0d67d27ae4568ec8d68a6277717d1a0200673b4 (patch)
tree9b17f3d2f3c69e3029ee76d1eb2dc5cd7abe020a /scripts
parentAdopt a literate programming approach for the configuration (diff)
Keep track of file renames in the revision table
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate_history.sh68
1 files changed, 31 insertions, 37 deletions
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}