diff options
author | Thomas Letan <lthms@soap.coffee> | 2020-02-24 17:59:52 +0100 |
---|---|---|
committer | Thomas Letan <lthms@soap.coffee> | 2020-02-24 17:59:52 +0100 |
commit | 5ae34b06c1d1ba2f10cac260ab6c98c15ca1ebc7 (patch) | |
tree | 497ad71a8949c3baa870e75a21167a383a0e80be /site/cleopatra | |
parent | More tweaking of too long code lines (diff) |
Improve the readability of the revisions table script
Diffstat (limited to 'site/cleopatra')
-rw-r--r-- | site/cleopatra/Soupault.org | 108 |
1 files changed, 82 insertions, 26 deletions
diff --git a/site/cleopatra/Soupault.org b/site/cleopatra/Soupault.org index c5e1062..b246646 100644 --- a/site/cleopatra/Soupault.org +++ b/site/cleopatra/Soupault.org @@ -191,7 +191,8 @@ will replace the content of this ~<div>~ with the revisions table of *** Implementations Details #+BEGIN_TODO -This plugin fails silently. +This plugin should be reimplemented using ~libgit2~ or other ~git~ libraries, in +a language more suitable than bash. #+END_TODO The base of the URL webview for the document you are currently reading @@ -212,46 +213,99 @@ This plugin proceeds as follows: 3. The content of the selected DOM element is replaced with the output of ~haskell-mustache~ -#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) :exports none #!/usr/bin/bash +#+END_SRC -FORMAT="{\"subject\":\"%s\",\"abbr_hash\":\"%h\",\"hash\":\"%H\",\"date\":\"%cs\"" +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) +function _jq () { + local input="${1}" + local filter="${2}" -function generate_history_json () { - local file="${1}" + echo "${input}" | jq -jcM "${filter}" +} +#+END_SRC - local logs=$(git --no-pager log --follow --pretty=format:"${FORMAT}" "${file}") +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) :export none +function jset () { + local obj="${1}" + local field="${2}" + local val="${3}" - if [ ! $? -eq 0 ]; then - exit 1 - fi + _jq "${obj}" "setpath([\"${field}\"]; ${val})" +} - local count=0 - local name="${file}" +function jget () { + local obj="${1}" + local field="${2}" - while read -r line; do - local hash=$(echo "${line}}" | jq -j '.hash') + _jq "${obj}" ".${field}" +} - local pre_name="$(git --no-pager show --stat=10000 ${hash} | sed -e 's/ *\(.*\){\(.*\) => \(.*\)}/\1\2 => \1\3/' | grep "=> ${name}" | xargs | cut -d' ' -f1)" +function jappend () { + local arr="${1}" + local val="${2}" - if [[ ${count} -eq 0 ]]; then - echo -n "[ " - else - echo -n ", " - fi + _jq "${arr}" ". + [ ${val} ]" +} +#+END_SRC - echo "${line}, \"filename\":\"${name}\"}" +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) +FORMAT='{'\ +' "subject" : "%s",'\ +' "abbr_hash" : "%h",'\ +' "hash" : "%H",'\ +' "date" : "%cs"'\ +'}' + +GIT="git --no-pager" + +function previous_name () { + local name=${1} + local hash=${2} + + local unfold=\ + 's/ *\(.*\){\(.*\) => \(.*\)}/\1\2 => \1\3/' + + ${GIT} show --stat=10000 ${hash} \ + | sed -e "${unfold}" \ + | grep "=> ${name}" \ + | xargs \ + | cut -d' ' -f1 +} - if [[ ! -z "${pre_name}" ]]; then - name="$(echo ${pre_name})" - fi +function generate_history_json () { + local file="${1}" + + local logs=$(${GIT} log \ + --follow \ + --pretty=format:"${FORMAT}" \ + "${file}") + + if [ ! $? -eq 0 ]; then + exit 1 + fi + + local name="${file}" + local revisions='[]' + + while read -r rev; do + rev=$(jset "${rev}" "filename" "\"${name}\"") + revisions=$(jappend "${revisions}" "${rev}") - count=$(( ${count} + 1 )) - done < <(echo "${logs}") + local hash=$(jget "${rev}" "hash") + local rename=$(previous_name "${name}" "${hash}") - echo -n "]" + if [[ ! -z "${rename}" ]]; then + name=${rename} + fi + done < <(echo "${logs}") + + echo "${revisions}" } +#+END_SRC +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) function generate_json () { local file="${1}" @@ -261,7 +315,9 @@ function generate_json () { echo " $(generate_history_json "${file}")" echo "}" } +#+END_SRC +#+BEGIN_SRC bash :tangle scripts/history.sh :tangle-mode (identity #o755) FILE=`cat` tmp_file=$(mktemp) |