shithub: gitonline

Download patch

ref: dcb7b6e458c412c7e7026e2e1974ab610febea15
parent: 93f12f1973aac3ff75f9c485105704c449e33fdb
author: glenda <glenda@9front.local>
date: Sun Nov 29 09:34:15 EST 2020

Update repo page to show last 5 commits, file listing, and readme

--- a/gitonline.rc
+++ b/gitonline.rc
@@ -102,18 +102,42 @@
 	html_emit_end
 }
 
+fn readme {
+	echo '
+	<b>Description</b>
+	<pre>'
+	htcat $1
+	echo '</pre>'
+}
+
 fn repo_view {
 	html_emit_start
-	reponame=$1
+	gitref=HEAD
+	repo=`{echo $1 | sed 's,^/,,'}
 	echo '
-	<h1>'$reponame'</h1>
-	<a href="'$reponame'/shortlog">'Shortlog'</a>
-	<a href="'$reponame'/browse">'browse'</a>'
+	<h1>'$repo'</h1>'
+
+	if (test -f $repo/README) {
+		readme $repo/README
+	}
+	if not if(test -f $repo/.git/README) {
+		readme $repo/.git/README
+	}
+
+	echo '<b>Last 5 commits</b> (<a href="/'$repo'/shortlog">shortlog</a>)'
+
+	shortlog 5
+	
+	echo '
+	<b>Files</b> (<a href="/'$repo'/browse">browse</a>)'
+	filepath=/
+	filetree
+
 	html_emit_end
 }
 
-fn repo_browse {
-	html_emit_start
+fn filetree {
+	pwd=`{pwd}
 	cd $repo
 	git/fs
 
@@ -121,69 +145,80 @@
 	if (! ref=`{resolveref $gitref}) {
 		`{resolveref $gitref}
 		echo '<b>'$status'</b>'
-		html_emit_end
-		exit
 	}
-
-	echo '<h2> Browsing '$repo' at commit '$gitref': '$filepath'</h2>'
-	gitpath=/mnt/git/$ref/tree$filepath
-	if (test -d $gitpath) {
-		cd $gitpath
-		files=`$nl{ls -F | sed 's/\*//g'}
-		echo '<pre>'
-		for (f in $files) {
-			echo '<a href="'$f'">'$f'</a>'
+	if not {
+		gitpath=/mnt/git/$ref/tree$filepath
+		if (test -d $gitpath) {
+			cd $gitpath
+			files=`$nl{ls -F | sed 's/\*//g'}
+			echo '<pre>'
+			for (f in $files) {
+				echo '<a href="'$f'">'$f'</a>'
+			}
+			echo '</pre>'
 		}
-		echo '</pre>'
+		if not if (test -f $gitpath) {
+			echo '<code><pre class="code">'
+			htcat $gitpath
+			echo '</pre></code>'
+		}
+		if not {
+			echo 'Sorry, could not find '$gitpath
+		}
 	}
-	if not if (test -f $gitpath) {
-		echo '<code><pre class="code">'
-		htcat $gitpath
-		echo '</pre></code>'
-	}
-	if not {
-		echo 'Sorry, could not find '$gitpath
-	}
-	html_emit_end
+	cd $pwd
 }
 
-fn repo_shortlog {
+fn repo_browse {
 	html_emit_start
+	echo '<h2> Browsing '$repo' at commit '$gitref': '$filepath'</h2>'
+	filetree
+	html_emit_end
+}
+
+fn shortlog {
+	commitcount=$1
+	pwd=`{pwd}
 	cd $repo
 	git/fs
 	if (! ref=`{resolveref $gitref}) {
 		`{resolveref $gitref}
 		echo '<b>'$status'</b>'
-		html_emit_end
-		exit
 	}
-
-	echo '
-	<b>Showing the last 100 commits</b>
-	<table>
-		<tr>
-			<th>Date</th>
-			<th>Author</th>
-			<th>Short message</th>
-			<th>Commit hash</th>
-		</tr>'
-	commithash=`{cat /mnt/git/$ref/hash | sed 1q}
-	count=()
-	while (! ~ $#commithash 0 && ! ~ $#count 100) {
-		count=($count 1)
-		message=`{htcat /mnt/git/object/$commithash/msg | sed 1q}
-		date=`{date -i `{mtime /mnt/git/object/$commithash/msg | awk '{print $1}'}}
-		author=`"{htcat /mnt/git/object/$commithash/author | awk '{print $1}'}
+	if not {
 		echo '
-		<tr>
-			<td>'$date'</td>
-			<td>'$author'</td>
-			<td>'$"message'</td>
-			<td><a href="/'$repo'/showcommit/'$commithash'">'$commithash'</a></td>
-		</tr>'
-		commithash=`{cat /mnt/git/object/$commithash/parent | sed 1q}
+		<table>
+			<tr>
+				<th>Date</th>
+				<th>Author</th>
+				<th>Short message</th>
+				<th>Commit hash</th>
+			</tr>'
+		commithash=`{cat /mnt/git/$ref/hash | sed 1q}
+		count=()
+		while (! ~ $#commithash 0 && ! ~ $#count $commitcount) {
+			count=($count 1)
+			message=`{htcat /mnt/git/object/$commithash/msg | sed 1q}
+			date=`{date -i `{mtime /mnt/git/object/$commithash/msg | awk '{print $1}'}}
+			author=`"{htcat /mnt/git/object/$commithash/author | awk '{print $1}'}
+			echo '
+			<tr>
+				<td>'$date'</td>
+				<td>'$author'</td>
+				<td>'$"message'</td>
+				<td><a href="/'$repo'/showcommit/'$commithash'">'$commithash'</a></td>
+			</tr>'
+			commithash=`{cat /mnt/git/object/$commithash/parent | sed 1q}
+		}
+		echo '</table>'
 	}
-	echo '</table>'
+	cd $pwd
+}
+
+fn repo_shortlog {
+	html_emit_start
+	echo '<b>Showing the last 100 commits</b>'
+	shortlog '100'
 	html_emit_end
 }