dot

packages and services management
Log | Files | Refs | README

commit c2b7c9bc9d7dca80c1062fd99ad67ee8132b4a6d
parent 9f4bc19493620b5467f504d55647958a6107cb33
Author: Josuah Demangeon <mail@josuah.net>
Date:   Thu,  9 Nov 2017 17:01:59 +0100

better and simpler git-index

Diffstat:
Mbin/git-index | 123+++++++++++++++++++++----------------------------------------------------------
Abin/pree | 44++++++++++++++++++++++++++++++++++++++++++++
Dbin/printree | 59-----------------------------------------------------------
3 files changed, 76 insertions(+), 150 deletions(-)

diff --git a/bin/git-index b/bin/git-index @@ -1,109 +1,50 @@ #!/bin/sh -NAME="${1##*/}" -HEADER='<!doctype html><html> -<head> +# add index.html and commit/%H.html inside of a git bare repository + +type pree > /dev/null && PREE=pree || PREE=tee + +NAME=${1%/} +NAME=${NAME##*/} + +HEADER='<!doctype html> +<title>'$NAME'</title> <meta charset="utf-8"/> <style> pre { float: left; margin: 4em 0 4em 4em; } </style> -</head> -<body> <pre> -<h1><a href="..">&lt;</a> '"$NAME"'</h1> - -' - -FOOTER=' -</pre> -</body> -</html>' +<h1><a href="..">&lt;</a> '$NAME'</h1>' export LC_COLLATE=C -mkdir -p "$NAME/commit" "$NAME/file" -cd "$NAME" || exit 1 - -# --- ./index.html --------------------------------------------------------------- - { printf '%s\n' "$HEADER" - git -C "$1" ls-tree -r --name-only master | sort | awk '{ - gsub("&", "\&amp;"); gsub("<", "\&lt;") - do { print } while (sub("/[^/]*$", "")) - }' | sort -u | awk '{ - count = split($0, line, "/") - for (i = 1; i <= count; i++) { - lines[NR"]["0] = $0 - lines[NR"]["i] = "| " - prev[i] = line[i] - } - lines[NR"]["i - 1] = "|-- " - prev[i] = "" - } END { - for (i = 1; !stop; i++) { - stop = tail = 1 - for (l = NR - 1; l > 0; l--) { - if (lines[l"]["i] == "| " && tail) { - lines[l"]["i] = " " - stop = 0 - - } else if (lines[l"]["i] == "|-- " && tail) { - lines[l"]["i] = "`-- " - tail = stop = 0 - - } else if (!lines[l"]["i]) { - tail = 1 - } - } - } - - for (l = 1; l < NR; l++) { - for (i = 1; lines[l"]["i]; i++) - printf "%s", lines[l"]["i] - printf "<a href=\"file/%s\">", lines[l"]["0] - sub(".*/|^", "", lines[l"]["0]) - printf "%s</a>\n", lines[l"]["0] - } - }' - - printf '</pre><pre>' + git -C "$1" ls-tree -r --name-only master | sort | $PREE + printf '</pre><pre>\n' git -C "$1" log --graph --date=short --format='%H %cd %cn <%ce>%n%s%n' | - sed -r ' - s|&|\&amp;|g - s|<|\&lt;|g - s|([0-9a-f]{8})([0-9a-f]{32})|<a href="commit/\1\2.html">\1</a>| - ' - - printf %s "$FOOTER" + sed -r -e 's|&|\&amp;|g' \ + -e 's|<|\&lt;|g' \ + -e 's|([0-9a-f]{8})[0-9a-f]{32}|<a href="commit/&.html">\1</a>|' + printf '</pre>\n' -} > index.html - -# --- ./file/ ------------------------------------------------------------------ - -git -C "$1" ls-tree -r --name-only master | while IFS='' read -r file -do - [ "$1/$file" -ot "file/$file" ] && continue - echo "file $file" - mkdir -p "file/$(dirname "$file")" - git -C "$1" show master:"$file" > "file/$file" -done +} > "$1/index.html" -# --- ./commit/ ------------------------------------------------------------------- +mkdir -p "$1/commit" for commit in $(git -C "$1" log --format='%H') do - [ -f "commit/$commit.html" ] && continue - echo "commit $commit" - echo "$HEADER" > "commit/$commit.html" - git -C "$1" show -U3 "$commit" | sed ' - s|&|\&amp;|g - s|<|\&lt;|g - s|^[A-Z][a-z]*:|<b>&</b>| - /^commit/ s|.*|<b>&</b>| - /^diff/ s|.*|<b>&</b>| - /^+/ s|.*|<span style="color: green;">&</span>| - /^-/ s|.*|<span style="color: red ;">&</span>| - /^@/ s|.*|<span style="color: blue ;">&</span>| - ' >> "commit/$commit.html" - echo "$FOOTER" >> "commit/$commit.html" + [ -f "$1/commit/$commit.html" ] && continue + printf '%s\n' "$1/commit $commit" + printf '%s\n' "$HEADER" > "$1/commit/$commit.html" + git -C "$1" show -U3 "$commit" | + sed -e 's|&|\&amp;|g' \ + -e 's|<|\&lt;|g' \ + -e 's|^[A-Z][a-z]*:|<b>&</b>|' \ + -e '/^commit/ s|.*|<b>&</b>|' \ + -e '/^diff/ s|.*|<b>&</b>|' \ + -e '/^+/ s|.*|<span style="color: green;">&</span>|' \ + -e '/^-/ s|.*|<span style="color: red ;">&</span>|' \ + -e '/^@/ s|.*|<span style="color: blue ;">&</span>|' + >> "$1/commit/$commit.html" + printf '</pre>\n' >> "$1/commit/$commit.html" done diff --git a/bin/pree b/bin/pree @@ -0,0 +1,44 @@ +#!/bin/sh +# convert find(1)-style listing to tree(1)-style listing + +LC_COLLATE=C + +awk '{ do { print } while (sub("/[^/]*$", "")) }' | sort -u | +awk -v LINE='| ' -v NODE='|-- ' -v TAIL='`-- ' -v VOID=' ' ' +{ + count = split($0, line, "/") + lines[NR"]["0] = $0 + for (i = 1; i <= count; i++) + lines[NR"]["i] = LINE + + lines[NR"]["i - 1] = NODE +} + +END { + for (i = 1; !stop; i++) { + stop = tail = 1 + + for (l = NR; l > 0; l--) { + if (lines[l"]["i] == LINE && tail) { + lines[l"]["i] = VOID + stop = 0 + + } else if (lines[l"]["i] == NODE && tail) { + lines[l"]["i] = TAIL + tail = stop = 0 + + } else if (!lines[l"]["i]) { + tail = 1 + } + } + } + + for (l = 1; l <= NR; l++) { + for (i = 1; lines[l"]["i]; i++) + printf "%s", lines[l"]["i] + + name = lines[l"]["0] + sub(".*/", "", lines[l"]["0]) + print lines[l"]["0] + } +}' diff --git a/bin/printree b/bin/printree @@ -1,59 +0,0 @@ -#!/bin/sh - -LC_COLLATE=C - -awk '{ do { print } while (sub("/[^/]*$", "")) }' | sort -u | -awk -v LINE='| ' -v NODE='|-- ' -v TAIL='`-- ' -v VOID=' ' -v HTML="$1" ' -BEGIN { - if (HTML) - print "<pre>" -} - -{ - count = split($0, line, "/") - if (HTML) { - gsub("&", "\\&amp;"); - gsub("<", "\\&gt;"); - } - lines[NR"]["0] = $0 - for (i = 1; i <= count; i++) - lines[NR"]["i] = LINE - - lines[NR"]["i - 1] = NODE -} - -END { - for (i = 1; !stop; i++) { - stop = tail = 1 - - for (l = NR; l > 0; l--) { - if (lines[l"]["i] == LINE && tail) { - lines[l"]["i] = VOID - stop = 0 - - } else if (lines[l"]["i] == NODE && tail) { - lines[l"]["i] = TAIL - tail = stop = 0 - - } else if (!lines[l"]["i]) { - tail = 1 - } - } - } - - for (l = 1; l <= NR; l++) { - for (i = 1; lines[l"]["i]; i++) - printf "%s", lines[l"]["i] - - name = lines[l"]["0] - sub(".*/", "", lines[l"]["0]) - - if (HTML) - print "<a href=\"" name "\">" lines[l"]["0] "</a>" - else - print lines[l"]["0] - } - - if (HTML) - print "</pre>" -}'