ref: fc07fd71cbf7f537cb0762ab07b19f2769ea4607
dir: /view/
#!/bin/rc -e
. /sys/lib/shithub/common.rc
cd $1
shift
rfork ne
nl='
'
gituser=$1
repo=$2
refname=$3
file=$4
repons $gituser $repo
if(! ref=`{resolveref $refname}){
echo '<b>invalid ref '$refname'</b>'
exit
}
cd $gitfs/$ref/tree
if(~ $file '')
file='.'
hash=`{cat $gitfs/$ref/hash}
user_prelude $gituser $repo $hash
echo ' <p>
<b>ref:</b> <a href="'/$gituser/$repo/$hash/files.html'">'$hash'</a><br/>
</p>'
if(test -f $file){
echo ' <a href="'/$gituser/$repo/$hash/$file'/raw">View raw version</a>'
type=`{file -m $file}
switch($type){
case text/*
echo ' <pre id="code">'
htcat $file
echo ' </pre>'
case image/*
echo ' <br/><div><img src="'/$gituser/$repo/$hash/$file'/raw" /></div>'
case *
echo ' <p>Binary file not displayed</p>'
}
}
if not if(test -d $file){
cd $file
echo ' <div id="code">'
for(f in `$nl{ls}){
url=`$nl{echo -n $f/f.html | urlencode}
fname=`$nl{echo -n $f | htcat}
echo '<a href="'$url'">'$fname'</a><br/>'
}
echo ' </div>'
}
echo ' </body>
</html>'