shithub: shithub

Download patch

ref: c0cc6b7980e6edce32822857a6a34dea390c4e90
parent: 84f77d5a1673c5e2579c4d63d4062957753d91f0
author: sirjofri <sirjofri@sirjofri.de>
date: Wed Jun 12 03:58:35 EDT 2024

adds/fixes branch support

the short list of branches on the info page is ordered by last change (newest first). The separate branches page shows all branches ordered by name, with the last commit (same as on the info page).

--- /dev/null
+++ b/branches
@@ -1,0 +1,49 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+
+repons $gituser $repo
+if(! ref=`{resolveref $refname}){
+	echo '<b>invalid ref '$refname'</b>'
+	exit
+}
+
+if(test -f $gitfs/$ref/hash)
+	hash=`{cat $gitfs/$ref/hash}
+if not
+	hash=$ref
+
+user_prelude $gituser $repo $hash
+
+echo '	<h3>Branches</h3>
+	<div>'
+
+branches=`$nl{ls -Qp $gitfs/branch/heads}
+if(~ $#branches 0){
+	echo '<b>no branches found</b>'
+	exit
+}
+
+for(branch in $branches){
+	if(test -f $gitfs/branch/heads/$branch/hash){
+		bhash=`{cat $gitfs/branch/heads/$branch/hash}
+		echo '	<h4>'$branch'</h4>'
+		formatcommit $gituser $repo $bhash
+	}
+}
+
+echo '	</div>
+	</body>
+	</html>
+'
--- a/common.rc
+++ b/common.rc
@@ -16,8 +16,8 @@
 fn resolveref {
 	if(~ $refname HEAD)
 		echo $refname
-	if not if(test -d $gitfs/branch/$refname/tree)
-		echo branch/$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
@@ -194,5 +194,7 @@
 		<a href="/'$puser/$prepo/$phash'/files.html">Files</a>
 		&nbsp;•&nbsp;
 		<a href="/'$puser/$prepo/$phash'/log.html">Log</a>
+		&nbsp;•&nbsp;
+		<a href="/'$puser/$prepo/$phash'/branches.html">Branches</a>
 		</div>'
 }
--- a/gitrules
+++ b/gitrules
@@ -3,6 +3,7 @@
 (/.well-known/acme-challenge/([^'/]+))		/bin/cat		/usr/web/\1
 ([^'/]+)/([^'/]+)/([^'/]+)/info.html		/bin/shithub/info	/usr/git '\1' '\2' '\3'
 ([^'/]+)/([^'/]+)/([^'/]+)/files.html		/bin/shithub/files	/usr/git '\1' '\2' '\3'
+([^'/]+)/([^'/]+)/([^'/]+)/branches.html		/bin/shithub/branches	/usr/git '\1' '\2' '\3'
 ([^'/]+)/([^'/]+)/([^'/]+)/snap.tar.gz		/bin/shithub/tar	/usr/git '\1' '\2' '\3'
 ([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?f.html	/bin/shithub/view	/usr/git '\1' '\2' '\3' '\5'
 ([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?raw	/bin/shithub/viewraw	/usr/git '\1' '\2' '\3' '\5'
--- a/info
+++ b/info
@@ -24,7 +24,21 @@
 if not
 	hash=$ref
 
-user_prelude $gituser $repo $hash		
+user_prelude $gituser $repo $hash
+
+# list branches in order of last change
+branches=`$nl{ls -Qt $gitfs/branch/heads/*/msg}
+if(! ~ $#branches 0){
+	echo -n '	<br><b>branches:</b>'
+	for(b in $branches){
+		branch=`{basename `{basename -d $b}}
+		if(test -f $gitfs/branch/heads/$branch/hash){
+			echo -n ' <a href="'/$gituser/$repo/$branch/info.html'">'$branch'</a>'
+		}
+	}
+	echo ''
+}
+
 echo '	<h3>Clone</h3>
 	<div>
 	<b>clone:</b> git://'$host/$gituser/$repo' gits://'$host/$gituser/$repo'<br>
@@ -32,7 +46,6 @@
 if(test -f $repodir/contact)
 	echo '	<b>patches to: </b>'^`$nl{cat $repodir/contact}^'<br>'
 echo '	</div>'
-
 
 if(test -f $gitfs/object/$hash/msg){
 	echo '	<h3>Last commit</h3>'
--- a/mkfile
+++ b/mkfile
@@ -5,6 +5,7 @@
 	list\
 	info\
 	files\
+	branches\
 	tar\
 	view\
 	viewraw\