about summary refs log tree commit diff stats
path: root/git/gitls
blob: 8a0c904cd77e9f8ab3faa94034c994252117cac3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/rc -e

cd $1
shift
url=fulton.software
rfork ne
nl='
'

fn htcat {
	sed '
		s/&/\&/g;
		s/</\&lt;/g;
		s/>/\&gt;/g;
		s/"/\&quot;/g;
		s/''/\&#39;/g
	' $*
}

fn resolveref {
	if(~ $refname HEAD)
		echo $refname
	if not if(test -d /mnt/git/branch/$refname/tree)
		echo branch/$refname
	if not if(test -d /mnt/git/object/$refname/tree)
		echo object/$refname
	if not
		status='bad ref'
}

fn repons {
	mntgen
	mntgen /mnt/mnt
	bind /bin /mnt/bin
	bind /tmp /mnt/tmp
	bind -c /env /mnt/env
	bind $1 /mnt/$repo
	bind /mnt /
	cd /mnt/$repo
	git/fs
	rfork m
}


fn prelude {
	echo '
	<!DOCTYPE html>
	<html>
	
	<head>
		<style type="text/css">
			body{
				margin: 3em auto;
				max-width: 50em;
				font-family: sans-serif;
			}
			h1,h2{
				font-size: 1.3em;
				color: #4c4c99;
			}
			h3{
				font-size: 1em;
				color: #4c4c99;
			}
			#desc{
			}
			#code{
				background: #ffffea;
				border: #99994cff
			}
		</style>
	 	<link rel="alternate" type="application/rss+xml" href="feed.rss" title="rss">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>git webls</title>
	</head>
	<body>
	'
}

switch($1){
case 'tar'
	repo=$2
	refname=$3
	@{
	repons $2
	if(! ref=`{resolveref $refname}){
		echo '<b>invalid ref '$refname'</b>'
		exit
	}
	bind /mnt/git/$ref/tree /mnt/$repo
	cd /mnt
	tar cz $repo
	}

case 'list'
	rfork m
	prelude
	echo '	<h1>Repos</h1>
		<dl>'
	for(repo in `$nl{ls}){
		if(test -e $repo/.git/webpublish){
			echo '<dt><a href="/git/'$repo'/HEAD/info.html">'$repo'</a></dt>'
			echo '<dd>'
			if(test -f $repo/.git/desc)
				htcat $repo/.git/desc
			if not
				echo 'code some guy wrote'
			echo '</dd>'
		}
	}
	echo '</dl>'

case 'info'
	repo=$2
	repodir=/mnt/$repo/.git
	refname=$3
	@{
	repons $repo
	if(! ref=`{resolveref $refname}){
		echo '<b>invalid ref '$refname'</b>'
		exit
	}
	cd /mnt/git/$ref/tree
	hash=`{cat /mnt/git/$ref/hash}

	prelude $repo $ref $repo
	echo '	<h1><a href="/git/repos.html">Git</a>: <a
		href=/git/'$repo'/'$ref'/info.html>'$repo'</a></h1>
		<p>'$repo' @ <a href='/git/$repo/$hash/f.html'>'$hash'</a>
		<pre id="desc">'
	htcat /mnt/git/object/$hash/msg
	echo '	</pre>
		<h2>Code</h2>
		<p>
		<b>clone:</b> git://'$url'/'$repo', gits://'$url'/'$repo'<br>
		<b>push:</b> hjgit://'$url'/'$repo'<br>
		<b>tar:</b> <a href="'/git/$repo/$hash/snap.tar.gz'">snap.tar.gz</a><br>'
	if(test -f $repodir/contact)
		echo '<b>patches to: </b>'^`$nl{cat $repodir/contact}^'<br>
			</p>
			<pre 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>'
	}		
	echo '</pre>
		<h2>About This Repo</h2>
		<pre id="desc">'
	if(test -f $repodir/README)
		htcat $repodir/README
	if not if(test -f README)
		htcat README
	if not if (test -f README.md)
		htcat README.md
	if not if(test -f $repodir/desc)
		htcat $repodir/desc
	if not
		echo 'this repo has no description'
	echo '
		</pre>
		</body>
		</html>
	'
	}

case 'view'
	repo=$2
	repodir=/mnt/$repo/.git
	refname=$3
	file=$4
	@{
	repons $repo
	if(! ref=`{resolveref $refname}){
		echo '<b>invalid ref '$refname'</b>'
		exit
	}
	cd /mnt/git/$ref/tree
	if(~ $file '')
		file='.'
	hash=`{cat /mnt/git/$ref/hash}

	prelude
	echo '	<h1><a href="/git/repos.html">Git</a>: <a
		href='/git/$repo/$ref/info.html'>'$repo'</a></h1>
		<p>'$repo' @ <a href="'/git/$repo/$hash/f.html'">'$hash'</a>
		<pre id="code">'
	if(test -f $file){
		htcat $file
	}
	if not if(test -d $file){
		cd $file
		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>'
		}
	}
	echo '	</pre>
		</body>
		</html>'
	}
}