shithub: shithub

Download patch

ref: a8c2817d19386af12adeb1a57f0f70ad7bef3e2d
parent: da9ed9b14e04f67be47a83889945e05ecd6366a6
author: phil9 <telephil9@gmail.com>
date: Sun Jan 31 07:54:46 EST 2021

add log page to browse history

--- a/gitrules
+++ b/gitrules
@@ -4,3 +4,4 @@
 /([^'/]+)/([^'/]+)/([^'/]+)/snap.tar.gz		/bin/shithub /usr/git tar '\1' '\2' '\3'
 /([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?f.html	/bin/shithub /usr/git view '\1' '\2' '\3' '\5'
 /([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?raw	/bin/shithub /usr/git viewraw '\1' '\2' '\3' '\5'
+/([^'/]+)/([^'/]+)/([^'/]+)/log.html		/bin/shithub /usr/git log '\1' '\2' '\3'
--- a/shithub
+++ b/shithub
@@ -42,7 +42,36 @@
 	rfork m
 }
 
+fn formatcommit {
+	phash=$1
 
+	message=`{htcat /mnt/git/object/$phash/msg | sed 1q}
+	date=`{date -t `{mtime /mnt/git/object/$phash/msg | awk '{print $1}'}}
+	author=`"{htcat /mnt/git/object/$phash/author | awk '{print $1}'}
+	shorthash=`{echo $phash | awk '{print substr($0, 0, 8)}'}
+	echo '	<div id="commit">
+		'$shorthash' – '$author' – '$"date'
+		<pre>
+		'$"message'</pre>
+		</div>'
+}
+
+fn shortlog {
+	ref=$1
+	commitcount=$2
+
+	d=`{pwd}
+	commithash=`{cat /mnt/git/$ref/hash | sed 1q}
+	count=()
+	while (! ~ $#commithash 0 && ! ~ $#count $commitcount) {
+		count=($count 1)
+		formatcommit $commithash
+		echo '<br/>'
+		commithash=`{cat /mnt/git/object/$commithash/parent | sed 1q}
+	}
+	cd $d
+}
+
 fn prelude {
 	echo '
 	<!DOCTYPE html>
@@ -75,6 +104,14 @@
 				overflow: auto;
 				padding: 4px;
 			}
+
+			#commit{
+				font-family: sans-serif;
+				background: #eeeeee;
+				border: 1px solid #cccccc;
+				padding: 4px;
+			}
+
 		</style>
 	 	<link rel="alternate" type="application/rss+xml" href="feed.rss" title="rss">
 		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@@ -97,6 +134,8 @@
 		<a href="/git/'$puser/$prepo/$phash'/info.html">Info</a>
 		&nbsp;•&nbsp;
 		<a href="/git/'$puser/$prepo/$phash'/files.html">Files</a>
+		&nbsp;•&nbsp;
+		<a href="/git/'$puser/$prepo/$phash'/log.html">Log</a>
 		</div>'
 }
 
@@ -299,5 +338,37 @@
 	}
 	cd /mnt/git/$ref/tree
 	cat $file
+
+case 'log'
+	gituser=$2
+	repo=$3
+	refname=$4
+
+	repons $gituser $repo
+	repodir=/mnt/$repo/.git
+	if(! ref=`{resolveref $refname}){
+		echo '<b>invalid ref '$refname'</b>'
+		exit
+	}
+
+	if(test -f /mnt/git/$ref/hash)
+		hash=`{cat /mnt/git/$ref/hash}
+	if not
+		hash=$ref
+
+	user_prelude $gituser $repo $hash
+
+	if(! test -d /mnt/git/$ref/tree){
+		echo '	<p>No commits yet.</p>
+			</body>
+			</html>
+		'
+		exit
+	}
+	cd /mnt/git/$ref/tree
+	echo '<br/>'
+	shortlog $ref 100
+	echo '	</body>
+		</html>'
 
 }