ref: 68e2a143ca8976c543348fcd208966ef0367129b
dir: /common.rc/
. /sys/lib/hlfw/config.rc nl=' ' fn htcat { sed ' s/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/''/\'/g ' $* } fn resolveref { if(~ $refname HEAD) echo $refname if not if(test -d $gitfs/branch/heads/$refname/tree) echo branch/heads/$refname if not if(test -d $gitfs/object/$refname/tree) echo object/$refname if not status='bad ref' } fn repons { mntgen mntgen /mnt/mnt dir=/mnt/r.$repo repodir=$dir/.git gitfs=/mnt/$dir/.git/fs ramfs -m /mnt/tmp bind /bin /mnt/bin bind /rc /mnt/rc bind /sys /mnt/sys bind -c /env /mnt/env bind /dev /mnt/dev bind $1/$2 $dir bind /mnt / cd $dir git/fs mntgen /mnt/scratch rfork m } fn formatcommit { puser=$1 prepo=$2 phash=$3 message=`{htcat $gitfs/object/$phash/msg | sed 1q} date=`{date -f 'YYYY/MM/DD hh:mm' `{mtime $gitfs/object/$phash/msg | awk '{print $1}'}} author=`"{htcat $gitfs/object/$phash/author} shorthash=`{echo $phash | awk '{print substr($0, 0, 8)}'} if (test -f $gitfs/object/$phash/committer) committer=`"{htcat $gitfs/object/$phash/committer} echo ' <div id="commit"> <a href=/git/'$puser/$prepo/$phash'/commit.html>'$shorthash'</a> – '$author' authored' if (! ~ $#committer 0 && ! ~ $committer $author) echo ' and '^$committer^' committed' echo ' on '$"date' <pre>'$"message'</pre> </div>' } fn shortlog { puser=$1 prepo=$2 pref=$3 pcount=$4 d=`{pwd} commithash=`{cat $gitfs/$pref/hash | sed 1q} count=() git/log -sc $commithash | while(commithash=`{read} && ! ~ $#count $pcount){ count=($count 1) formatcommit $puser $prepo $commithash(1) echo '<br/>' } if(! ~ $#commithash 0) echo '<a href="/git/'$puser/$prepo/$commithash(1)^'/log.html">Next</a>' cd $d } fn difftohtml { awk ' function printpre(id, text) { printf "<pre id='%s'>%s</pre>", id, text } BEGIN { started = 0; diff = 0; } /^---$/ { diff = 1; next } /^diff .*$/ && diff && !started { started = 1; next } /^\+\+\+ .*$/ && started { printpre("files", $0); next } /^--- .*$/ && started { printpre("files", $0); next } /^@@ .*$/ && started { printpre("sep", $0); next } /^\+.*$/ && started { printpre("add", $0); next } /^-.*$/ && started { printpre("del", $0); next } started { printpre("ctx", $0); next } ' } fn prelude { puser=$1 prepo=$2 echo ' <!DOCTYPE html> <html> <head> <style type="text/css"> body{ padding: 3rem; margin: auto; width: 90%; max-width: 1114px; font-family: sans-serif; tab-space: 8; } a { all: unset; color: #3333bc; } img { display: block; margin-left: auto; margin-right: auto; width: 95%; max-width: 1024px; } h1{ font-size: 1.5em; } h2{ font-size: 1.3em; } h3{ font-size: 1em; } header{ display: flex; justify-content: space-between; align-items: center; gap: 1rem; } header nav{ display: flex; } header nav a{ all: unset; padding: 15px 5px; } #code{ background: #ffffea; border: 1px solid #99994c; overflow: auto; padding: 4px; } #commit{ font-family: sans-serif; background: #eeeeee; border: 1px solid #cccccc; padding: 4px; } #diff{ font-family: monospace; border: 2px solid #efefef; } #diff #files{ background: #efefef; margin: 0em; } #diff #sep{ background: #eaffff; margin: 0em; } #diff #add{ background: #e6ffed; margin: 0em; } #diff #del{ background: #ffeef0; margin: 0em; } #diff #ctx{ margin: 0em; } @media (prefers-color-scheme: dark){ body{ background-color: #333; color: #eee; h1 { color: #9090fc; } h2 { color: #9090fc; } h3 { color: #9090fc; } a { color: #9090fc; } #code{ background: #000011; } #commit{ background: #111111; } #diff{ border: 2px solid #101010; } #diff #files{ background: #101010; } #diff #sep{ background: #120000; } #diff #add{ background: #36453a; } #diff #del{ background: #7d0211; } #diff #ctx{ background: #000000; } } } </style>' if(! ~ $puser '') echo '<link rel="alternate" type="application/rss+xml" href="/git/'$puser/$prepo'/HEAD/feed.rss" title="rss">' echo ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>'$title': '$"prepo'</title> </head> <body> <header> <h1>hlfw.ca</h1> <nav> <a href="/">home</a> <a href="/git/index.html">code</a> <a href="/blog/index.html">blog</a> <nav> </header> ' } fn user_prelude { puser=$1 prepo=$2 phash=$3 prelude $puser $prepo echo '<h2><a href="/git/'$puser/$prepo'/HEAD/info.html">'$prepo'</a></h2> <div id="linkbar"> <a href="/git/'$puser/$prepo'/HEAD/info.html">Info</a> • <a href="/git/'$puser/$prepo/$phash'/files.html">Files</a> • <a href="/git/'$puser/$prepo/$phash'/log.html">Log</a> • <a href="/git/'$puser/$prepo/$phash'/branches.html">Branches</a> </div>' }