From 062e61f1ecc160a1256fcaab7cb4db12288a84d2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 6 Jan 2025 13:51:13 -0300 Subject: m --- src/gistatic.in | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 269 insertions(+), 5 deletions(-) (limited to 'src/gistatic.in') diff --git a/src/gistatic.in b/src/gistatic.in index f3cb2d6..fec517a 100755 --- a/src/gistatic.in +++ b/src/gistatic.in @@ -506,6 +506,42 @@ cached_run() { fi } +# FIXME: get from config? +# exts() { } + +# FIXME: emit signatures code +TAB="$(printf '\t')" +repo_tarballs_write2() { + git branch --format '%(refname:lstrip=2)' | while read -r branch; do + cat <<-EOF + all: $OUTDIR/tarballs/$NAME-$branch.$EXT + + $OUTDIR/tarballs/$NAME-$branch.$EXT: $CACHE_DIR/tarballs/$NAME-$branch.$EXT + ${TAB}\$(LN) \$? \$@ + + $CACHE_DIR/tarballs/$NAME-$branch.$EXT: $CACHE_DIR/branch-revisions/$branch + ${TAB}git -C "$REPO" archive --prefix $NAME-$branch/ -o \$@ $branch + + $CACHE_DIR/branch-revisions/$branch: ALWAYS + ${TAB}@git -C "$REPO" rev-parse $branch | ifnew \$@ + + EOF + done + + git tag | while read -r tag; do + cat <<-EOF + all: $OUTDIR/tarballs/$NAME-$tag.$EXT + + $OUTDIR/tarballs/$NAME-$tag.$EXT: $CACHE_DIR/tarballs/$NAME-$tag.$EXT + ${TAB}\$(LN) \$? \$@ + + $CACHE_DIR/tarballs/$NAME-$tag.$EXT: + ${TAB}git -C "$REPO" archive --prefix $NAME-$tag/ -o \$@ $tag + + EOF + done +} + repo_tarballs_write() { repo="$1" mkdir -p "$OUTDIR/tarballs" "$CACHE_DIR/tarballs" @@ -540,6 +576,189 @@ repo_tarballs_write() { wait } +print_repo_refs2() { + cat <<-EOF + all: $OUTDIR/refs.html + + $OUTDIR/refs.html: ALWAYS + ${TAB}$0 -x refs "$REPO" > \$@ + + EOF +} +exec_refs() { + repo_vars "$1" + cat <<-EOF + + + + + + + + + + + $(escape "$NAME") - $(escape "$MSG_TITLE_REFS") + + +
+
+ + + +
+

+ + $(escape "$NAME") + +

+

+ $(escape "$DESCRIPTION") +

+ + git clone $(escape "$CLONE_URL") + +
+
+ +
+
+
+ + + + + + + + + + + EOF + + for branch in $(git branch --format '%(refname:lstrip=2)'); do + sha="$(git rev-parse "$branch")" + cat < + + + + + +EOF + done + + cat < +
+ $(escape "$MSG_THEAD_BRANCH") + + $(escape "$MSG_THEAD_COMMITMSG") + + $(escape "$MSG_THEAD_AUTHOR") + + $(escape "$MSG_THEAD_DATE") +
+ + $(escape "$branch") + + + + $(escape "$(git log -1 --format=%s "$sha")") + + + $(escape "$(git log -1 --format=%an "$sha")") + + $(escape "$(git log -1 --format=%cd --date='format:%Y-%m:%d %H:%M' "$sha")") +
+EOF + PRINTED_TABLE_OPEN=false + + for tag in $(git tag | tac); do + if [ "$PRINTED_TABLE_OPEN" = false ]; then + PRINTED_TABLE_OPEN=true + cat < + + + + $(escape "$MSG_THEAD_TAG") + + + $(escape "$MSG_THEAD_AUTHOR") + + + $(escape "$MSG_THEAD_DATE") + + + + +EOF + fi + + if [ -e "$CACHE_DIR/tarballs/$repo-$tag.tar.gz.asc" ]; then + tarball_link="(tarball, + sig)" + else + tarball_link="(tarball)" + fi + + cat < + + + $(escape "$tag") + + $tarball_link + + + $(escape "$(git log -1 --format=%an "$tag")") + + + $(escape "$(git log -1 --format=%cd --date='format:%Y-%m:%d %H:%M' "$tag")") + + +EOF + done + + if [ "$PRINTED_TABLE_OPEN" = true ]; then + cat < + +EOF + fi + + cat < + + + +EOF +} + print_repo_refs() { repo="$1" description="$2" @@ -1177,6 +1396,44 @@ repo_trees_write() { echo } +preamble() { + cat <<-EOF + .POSIX: + + LN = $CMD + + default: all + + ALWAYS: + + + EOF +} + +repo_vars() { + EXT=tar.xz + REPO_DIR="${1%/}" + REPO="${1%/}" # FIXME: shesc + NAME="$(basename "$REPO" .git)" + CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/gistatic/$NAME" + GIT_DIR="$REPO/$(git -C "$REPO" rev-parse --git-dir)" + export GIT_DIR + DESCRIPTION="$(cat "$GIT_DIR"/description 2>/dev/null ||:)" +} + +repo_write2() { + repo_vars "$1" + mkdir -p \ + "$OUTDIR"/tarballs \ + "$CACHE_DIR"/tarballs \ + "$CACHE_DIR"/branch-revisions + { + preamble + repo_tarballs_write2 + print_repo_refs2 + } | tee f | make -f- +} + repo_write() { cd "$1" # FIXME: use $REPO and $DESCRIPTION @@ -1184,9 +1441,6 @@ repo_write() { description="$(cat "$1/description" 2>/dev/null ||:)" CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/gistatic/$repo" - print_logo > "$OUTDIR/logo.svg" - print_style > "$OUTDIR/style.css" - repo_tarballs_write "$repo" print_repo_refs "$repo" "$description" > "$OUTDIR/refs.html" repo_commits_write "$repo" "$description" @@ -1229,7 +1483,8 @@ MAIN_BRANCH_SET=false REPO= DESCRIPTION= CMD='ln' -while getopts 'b:o:t:u:j:isqhV' flag; do +EXEC= +while getopts 'b:o:t:u:j:isqx:hV' flag; do case "$flag" in b) MAIN_BRANCH="$OPTARG" @@ -1256,6 +1511,9 @@ while getopts 'b:o:t:u:j:isqhV' flag; do s) CMD='ln -s' ;; + x) + EXEC="$OPTARG" + ;; h) usage help @@ -1280,6 +1538,11 @@ assert_arg() { exit 2 fi } + +if [ -n "$EXEC" ]; then + "exec_$EXEC" "$@" + exit +fi assert_arg "$OUTDIR" '-o DIRECTORY' if [ "$INDEX" = false ]; then @@ -1308,5 +1571,6 @@ mkdir -p "$OUTDIR" if [ "$INDEX" = true ]; then index_write "$@" else - repo_write "$1" + # repo_write "$1" + repo_write2 "$1" fi -- cgit v1.2.3