shithub: shithub

ref: 1a51231062636c8de1324d2fa1ffa573c2e04ef7
dir: /view/

View raw version
#!/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/>'
echo $file | htcat | awk -F/ '{
	user = ENVIRON["gituser"]
	repo = ENVIRON["repo"]
	hash = ENVIRON["hash"]
	url="/" user "/" repo "/" hash
	printf("<b>dir:</b> <a href=\"%s/f.html\">/</a>", url);
	for(i = 1; i <= NF; i++){
		if($i != "."){
			url=url"/"$i
			printf("<a href=\"%s/f.html\">%s</a>/", url, $i)
		}
	}
	printf("</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 -n '<a href="'$url'">'$fname
		if (test -d $f) echo '/'
		echo '</a><br/>'
	}		
	echo '	</div>'
}
echo '	</body>
	</html>'