home readme diff tree note docs

0commit 0e2e1e89629cfa1c4d3ab445e66fa76037778705
1Author: lakefox <mason@lakefox.net>
2Date:   Tue Jan 13 20:36:49 2026 -0700
3
4    Docs
5
6diff --git a/cgi-bin/git.awk b/cgi-bin/git.awk
7index 963561c..a19177b 100755
8--- a/cgi-bin/git.awk
9+++ b/cgi-bin/git.awk
10@@ -1,130 +1,155 @@
11 #!/bin/awk -f
12 
13 # /var/git
14+# Requires mandoc, git
15 
16 BEGIN {
17+        split(ENVIRON["QUERY_STRING"], pairs, "&")
18+        for (i in pairs) {
19+                split(pairs[i], kv, "=")
20 
21-		
22-	split(ENVIRON["QUERY_STRING"], pairs, "&")
23-	for (i in pairs) {
24-		split(pairs[i], kv, "=")
25-
26-		if (kv[1] == "action") {
27-			action = kv[2]
28-		} else if (kv[1] == "name") {
29-			name = kv[2]
30-		} else if (kv[1] == "hash") {
31-			hash = kv[2]
32-		} else if (kv[1] == "path") {
33-			path = kv[2]
34-		}
35-	}
36-
37-	print "Content-Type: text/html\r\n"
38-	print "<!DOCTYPE html>"
39-	print "<html>"
40-	print "<head>"
41-
42-	if (name == "") name = "all"
43-	if (hash == "") hash = "HEAD"
44-
45-	print "<title>Git: " name "</title>"
46-	print "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>"
47-	print "<meta name='viewport' content='width=device-width, initial-scale=1'>"
48-	print "</head>"
49-	print "<body>"
50-
51-	if (name != "all") {
52-		print "<a href='?name=" name "'>home</a>"
53-		print "<a href='?name=" name "&hash=" hash "&action=readme'>readme</a>"
54-		print "<a href='?name=" name "&hash=" hash "&action=diff'>diff</a>"
55-		print "<a href='?name=" name "&hash=" hash "&action=tree'>tree</a>"
56-		print "<a href='?name=" name "&hash=" hash "&action=notes'>note</a>"
57-	}
58-
59-	if (action == "") {
60-		if (name == "all") {
61-			cmd = "ls /var/git/"
62-			print "<h1>Git</h1>"
63-			print "<p>Select a repo to view.</p>"
64-		
65-			print "<ul>"
66-			while (cmd | getline file) {
67-				split(file, k, ".")
68-				print "<li><a href='/cgi-bin/git.awk?name=" k[1] "'>/" k[1] "</a></li>"
69-			}
70-			close(cmd)
71-			print "</ul>"
72-		} else {
73-			cmd = "git --git-dir=/var/git/" name ".git/ log"
74-			print "<pre><code>"	
75-			while (cmd | getline line) {
76-
77-				if (line ~ /^commit/) {
78-					split(line, commit, " ")
79-					print "<a href='/cgi-bin/git.awk?name=" name "&hash=" commit[2] "&action=diff'>commit " commit[2] "</a>"
80-				} else {
81-					print line
82-				}
83-			}
84-			close(cmd)
85-			print "</code></pre>"
86-		}
87-	} else if (action == "tree") {
88-		cmd = "git --git-dir=/var/git/" name ".git/ show " hash ":" path
89-		print "<br/>"
90-		print "<b>" hash ":" path "</b>"
91-		print "<pre><code>"	
92-		if (substr(path, length(path), 1) == "/" || path == "") {
93-			while (cmd | getline line) {
94-				if (line !~ /^tree/) {
95-					print "<a href='/cgi-bin/git.awk?name=" name "&hash=" hash "&action=tree&path=" path line "'>" line "</a>"
96-				}
97-			}
98-		} else {
99-			while (cmd | getline line) {
100-				print escape_html(line)
101-			}
102-		}
103-		close(cmd)
104-		print "</code></pre>"
105-	} if (action == "diff") {
106-		cmd = "git --git-dir=/var/git/" name ".git/ show " hash
107-		print "<pre><code>"	
108-		while (cmd | getline line) {
109-			print escape_html(line)
110-		}
111-		close(cmd)
112-		print "</code></pre>"
113-
114-	} if (action == "readme") {
115-		# 1. discover the README file name (single match assumed)
116-		cmd = "git --git-dir=/var/git/" name ".git ls-tree -r " hash " --name-only | grep '^README\\.'"
117-		fn = ""
118-		while ((cmd | getline fn) > 0) break      # take first match
119-		close(cmd)
120-		if (fn == "") { print "<br/>README not found for: " hash; exit 1 }
121-
122-		cmd = "git --git-dir=/var/git/" name ".git show " hash ":" fn
123-		print "<pre><code>"
124-		while ((cmd | getline line) > 0) {
125-			print escape_html(line)
126-		}
127-		close(cmd)
128-		print "</code></pre>"	
129-	} else if (action == "notes") {
130-		cmd = "git --git-dir=/var/git/" name ".git/ notes show " hash
131-		
132-		print "<pre><code>"	
133-		while (cmd | getline line) {
134-			print escape_html(line)
135-		}
136-		close(cmd)
137-		print "</code></pre>"
138-	}
139-
140-	print "</body>"
141-	print "</html>"
142+                if (kv[1] == "action") {
143+                        action = kv[2]
144+                } else if (kv[1] == "name") {
145+                        name = kv[2]
146+                } else if (kv[1] == "hash") {
147+                        hash = kv[2]
148+                } else if (kv[1] == "path") {
149+                        path = kv[2]
150+                }
151+        }
152+
153+        print "Content-Type: text/html\r\n"
154+        print "<!DOCTYPE html>"
155+        print "<html>"
156+        print "<head>"
157+
158+        if (name == "") name = "all"
159+        if (hash == "") hash = "HEAD"
160+
161+        print "<title>Git: " name "</title>"
162+        print "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>"
163+        print "<meta name='viewport' content='width=device-width, initial-scale=1'>"
164+        print "</head>"
165+        print "<body>"
166+
167+        if (name != "all") {
168+                print "<a href='?name=" name "'>home</a>"
169+                print "<a href='?name=" name "&hash=" hash "&action=readme'>readme</a>"
170+                print "<a href='?name=" name "&hash=" hash "&action=diff'>diff</a>"
171+                print "<a href='?name=" name "&hash=" hash "&action=tree'>tree</a>"
172+                print "<a href='?name=" name "&hash=" hash "&action=notes'>note</a>"
173+                print "<a href='?name=" name "&hash=" hash "&action=docs'>docs</a>"
174+        }
175+
176+        if (action == "") {
177+                if (name == "all") {
178+                        cmd = "ls /var/git/"
179+                        print "<h1>Git</h1>"
180+                        print "<p>Select a repo to view.</p>"
181+                
182+                        print "<ul>"
183+                        while (cmd | getline file) {
184+                                split(file, k, ".")
185+                                print "<li><a href='/cgi-bin/git.awk?name=" k[1] "'>/" k[1] "</a></li>"
186+                        }
187+                        close(cmd)
188+                        print "</ul>"
189+                } else {
190+                        cmd = "git --git-dir=/var/git/" name ".git/ log"
191+                        print "<pre><code>"     
192+                        while (cmd | getline line) {
193+
194+                                if (line ~ /^commit/) {
195+                                        split(line, commit, " ")
196+                                        print "<a href='/cgi-bin/git.awk?name=" name "&hash=" commit[2] "&action=diff'>commit " commit[2] "</a>"
197+                                } else {
198+                                        print line
199+                                }
200+                        }
201+                        close(cmd)
202+                        print "</code></pre>"
203+                }
204+        } else if (action == "tree") {
205+                cmd = "git --git-dir=/var/git/" name ".git/ show " hash ":" path
206+                print "<br/>"
207+                print "<b>" hash ":" path "</b>"
208+                print "<pre><code>"     
209+                if (substr(path, length(path), 1) == "/" || path == "") {
210+                        while (cmd | getline line) {
211+                                if (line !~ /^tree/) {
212+                                        print "<a href='/cgi-bin/git.awk?name=" name "&hash=" hash "&action=tree&path=" path line "'>" line "</a>"
213+                                }
214+                        }
215+                } else {
216+                        while (cmd | getline line) {
217+                                print escape_html(line)
218+                        }
219+                }
220+                close(cmd)
221+                print "</code></pre>"
222+        } if (action == "diff") {
223+                cmd = "git --git-dir=/var/git/" name ".git/ show " hash
224+                print "<pre><code>"     
225+                while (cmd | getline line) {
226+                        print escape_html(line)
227+                }
228+                close(cmd)
229+                print "</code></pre>"
230+
231+        } if (action == "readme") {
232+                # 1. discover the README file name (single match assumed)
233+                cmd = "git --git-dir=/var/git/" name ".git ls-tree -r " hash " --name-only | grep '^README\\.'"
234+                fn = ""
235+                while ((cmd | getline fn) > 0) break      # take first match
236+                close(cmd)
237+                if (fn == "") { print "<br/>README not found for: " hash; exit 1 }
238+
239+                cmd = "git --git-dir=/var/git/" name ".git show " hash ":" fn
240+                print "<pre><code>"
241+                while ((cmd | getline line) > 0) {
242+                        print escape_html(line)
243+                }
244+                close(cmd)
245+                print "</code></pre>"   
246+        } else if (action == "notes") {
247+                cmd = "git --git-dir=/var/git/" name ".git/ notes show " hash
248+                
249+                print "<pre><code>"     
250+                while (cmd | getline line) {
251+                        print escape_html(line)
252+                }
253+                close(cmd)
254+                print "</code></pre>"
255+        } else if (action == "docs") {
256+                if (path == "") {
257+                        cmd = "git --git-dir=/var/git/" name ".git/ ls-tree -r --name-only " hash ":docs/";
258+                   
259+                        print "<h1>Index</h1>"
260+                        print "<ul>"    
261+                        while ((cmd | getline) > 0) {
262+                                print "<li><a href=\"/cgi-bin/git.awk?name=" name "&hash=" hash "&action=docs&path=" $0 "\">" escape_html($0) "</a></li>";
263+                        }
264+                        print "</ul>"
265+
266+                        close(cmd);
267+                } else {
268+                        cmd = "git --git-dir=/var/git/" name ".git/ show " hash ":docs/" path " | mandoc -O width=120";
269+                    
270+                        print "<pre><code>"
271+                        while ((cmd | getline) > 0) {
272+				gsub(/.\010/, "", $0);
273+                                print escape_html($0);
274+                        }
275+                        print "</code></pre>"   
276+
277+                        close(cmd);
278+
279+                }
280+        }
281+
282+        print "</body>"
283+        print "</html>"
284 }
285 
286