dot

packages and services management
Log | Files | Refs | README

commit 4bf86d07bac895ed9badc7e1b4cde821834f4c36
parent 0178186084a71dc3517e24140dfa616b9ed54215
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Wed, 22 Feb 2017 13:19:53 +0100

Mostly finished gix

Diffstat:
Mbin/gix | 87+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 45 insertions(+), 42 deletions(-)

diff --git a/bin/gix b/bin/gix @@ -1,5 +1,5 @@ #!/bin/sh -# Static Git index generator inspired from stagit +# Static Git index generator inspired from git.2f30.org/stagit # 1: path to the parent root @@ -27,12 +27,17 @@ header() { printf '<pre> <a href="%s/..">&lt;</a> <b>%s</b> - <span style="color: grey;">%s</span> -<a href="%s/index.html">Log</a> | <a href="%s/files.html">Files</a> -</pre> -<hr>' "$1" "${PWD##*/}" "$(cat .git/description)" "$1" "$1" +<a href="%s/files.html">Files</a> | <a href="%s/commits.html">Commits</a>' \ + "$1" "${PWD##*/}" "$(cat .git/description)" "$1" "$1" - [ -f "$1/files/README" ] && printf ' | <a href="files/README.html">' - [ -f "$1/files/LICENCE" ] && printf ' | <a href="files/LICENCE.html">' + [ -f .gitmodules ] && + printf ' | <a href="file/.gitmodules.html">Submodules</a>' + [ -f README ] && + printf ' | <a href="file/README.html">README</a>' + [ -f LICENSE ] && + printf ' | <a href="file/LICENSE.html">LICENSE</a>' + + printf '</pre>\n<hr>\n' } @@ -44,21 +49,6 @@ foot() } -log() -{ - printf '<table>\n<thead>\n<tr>' - printf '<th>%s</th>' 'Date' 'Hash' 'Commit message' 'Author' - printf '</tr>\n</thead>\n<tbody>\n' - - git log --format="<tr>$( - printf '<td>%s</td>' \ - '%ad' '<a href="commit/%H.html">%h</a>' '%s' '%an' - )</tr>" --date='short' - - printf '\n</tbody>\n</table>\n' -} - - # 1: long hash of the commit commit() @@ -85,8 +75,8 @@ commit() s|&|\&amp;|g s|<|\&lt;|g /^diff/ { - s|a/\([^ ]*\)|a/<a href="../files/\1.html">\1</a>| - s|b/\([^ ]*\)|b/<a href="../files/\1.html">\1</a>| + s|a/\([^ ]*\)|a/<a href="../file/\1.html">\1</a>| + s|b/\([^ ]*\)|b/<a href="../file/\1.html">\1</a>| s|.*|<b>&</b>| } /^+/ s|.*|<span style="color: green;">&</span>| @@ -103,6 +93,10 @@ commits() { mkdir -p "$1/commit" + printf '<table>\n<thead>\n<tr>' + printf '<th>%s</th>' 'Date' 'Commit message' 'Author' + printf '</tr>\n</thead>\n<tbody>\n' + for hash in $(git log --format='%H') do { @@ -111,7 +105,14 @@ commits() commit "$hash" foot } > "$1/commit/$hash.html" + + git log --format="<tr>$( + printf '<td>%s</td>' \ + '%ad' '<a href="commit/%H.html">%s</a>' '%an' + )</tr>" --date='short' "$hash" done + + printf '\n</tbody>\n</table>\n' } @@ -142,7 +143,7 @@ file() files() { - mkdir -p "$1/files" + mkdir -p "$1/file" printf '<table>\n<thead>\n<tr>' printf '<th>%s</th>' 'Mode' 'Name' 'Size' @@ -150,7 +151,7 @@ files() git ls-files | while IFS='' read -r file do - [ -z "${file##*/*}" ] && mkdir -p "$1/files/${file%/*}" + [ -z "${file##*/*}" ] && mkdir -p "$1/file/${file%/*}" root="$(printf %s "$file" | sed 's|[^/]*||g; s|.|../|g').." @@ -160,13 +161,13 @@ files() header "$root" file "$file" foot - } > "$1/files/$file.html" + } > "$1/file/$file.html" printf '<tr>' printf '<td>%s</td>' \ "$(stat -c %A "$file")" \ - "<a href=\"files/$file.html\">$file</a>" \ + "<a href=\"file/$file.html\">$file</a>" \ "$(wc -l < "$file")L" printf '</tr>\n' done @@ -180,11 +181,11 @@ files() repo() { { - head '..' "Log - ${1##*/}" + head '..' "Commits - ${1##*/}" header '.' - log + commits "$1" foot - } > $1/index.html + } > $1/commits.html { head '..' "Files - ${1##*/}" @@ -193,13 +194,20 @@ repo() foot } > $1/files.html - commits "$1" + ln -s files.html "$1/index.html" + + printf '<tr>' + printf '<td>%s</td>' \ + "$(git -C "$repo" log -1 --format='%cd' --date='short')" \ + "<a href=\"${repo##*/}\">${repo##*/}</a>" \ + "$(cat "$repo/.git/description")" + printf '</tr>\n' } # 1: source git directory -list() +repos() { printf '<table>\n<thead>\n<tr>' printf '<th>%s</th>' 'Last commit' 'Name' 'Description' @@ -211,16 +219,11 @@ list() printf '%s\n' "$repo" 1>&2 mkdir -p "${repo##*/}" - (pwd="$PWD"; cd "$repo" && repo "$pwd/${repo##*/}" || exit 1) - printf '<tr>' - printf '<td>%s</td>' \ - "$(git -C "$repo" log -1 \ - --format='%cd' \ - --date='short')" \ - "<a href=\"${repo##*/}\">${repo##*/}</a>" \ - "$(cat "$repo/.git/description")" - printf '</tr>\n' + ( + pwd="$PWD" + cd "$repo" && repo "$pwd/${repo##*/}" || exit 1 + ) done printf '</tbody>\n</table>\n' @@ -232,7 +235,7 @@ main() { head '.' 'Repositories' printf '<a href="..">&lt;</a>\n<hr/>' - list "${1%/}" + repos "${1%/}" foot } > index.html }