Blame


1 ed619ca0 2022-12-14 op {!
2 ed619ca0 2022-12-14 op /*
3 ed619ca0 2022-12-14 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 ed619ca0 2022-12-14 op * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 ed619ca0 2022-12-14 op *
6 ed619ca0 2022-12-14 op * Permission to use, copy, modify, and distribute this software for any
7 ed619ca0 2022-12-14 op * purpose with or without fee is hereby granted, provided that the above
8 ed619ca0 2022-12-14 op * copyright notice and this permission notice appear in all copies.
9 ed619ca0 2022-12-14 op *
10 ed619ca0 2022-12-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 ed619ca0 2022-12-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 ed619ca0 2022-12-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ed619ca0 2022-12-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 ed619ca0 2022-12-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ed619ca0 2022-12-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 ed619ca0 2022-12-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ed619ca0 2022-12-14 op */
18 ed619ca0 2022-12-14 op
19 ed619ca0 2022-12-14 op #include <sys/types.h>
20 ed619ca0 2022-12-14 op #include <sys/queue.h>
21 43d421de 2023-01-05 op #include <sys/stat.h>
22 ed619ca0 2022-12-14 op
23 1abb18e1 2022-12-20 op #include <ctype.h>
24 ed619ca0 2022-12-14 op #include <event.h>
25 ed619ca0 2022-12-14 op #include <stdint.h>
26 43d421de 2023-01-05 op #include <stdio.h>
27 ed619ca0 2022-12-14 op #include <stdlib.h>
28 ed619ca0 2022-12-14 op #include <string.h>
29 43d421de 2023-01-05 op #include <sha1.h>
30 5822e79e 2023-02-23 op #include <sha2.h>
31 ed619ca0 2022-12-14 op #include <imsg.h>
32 ed619ca0 2022-12-14 op
33 3ab2c914 2023-01-11 op #include "got_error.h"
34 43d421de 2023-01-05 op #include "got_object.h"
35 3ab2c914 2023-01-11 op #include "got_reference.h"
36 43d421de 2023-01-05 op
37 ed619ca0 2022-12-14 op #include "proc.h"
38 ed619ca0 2022-12-14 op
39 ed619ca0 2022-12-14 op #include "gotwebd.h"
40 ed619ca0 2022-12-14 op #include "tmpl.h"
41 ed619ca0 2022-12-14 op
42 298f95fb 2023-01-05 op static int gotweb_render_blob_line(struct template *, const char *, size_t);
43 43d421de 2023-01-05 op static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
44 8319855f 2023-01-15 op static int blame_line(struct template *, const char *, struct blame_line *,
45 8319855f 2023-01-15 op int, int);
46 e3662697 2023-02-03 op
47 e3662697 2023-02-03 op static inline int gotweb_render_more(struct template *, int);
48 298f95fb 2023-01-05 op
49 587550a5 2023-01-10 op static inline int diff_line(struct template *, char *);
50 067396e6 2023-01-09 op static inline int tag_item(struct template *, struct repo_tag *);
51 3ab2c914 2023-01-11 op static inline int branch(struct template *, struct got_reflist_entry *);
52 1abb18e1 2022-12-20 op static inline int rss_tag_item(struct template *, struct repo_tag *);
53 1abb18e1 2022-12-20 op static inline int rss_author(struct template *, char *);
54 1abb18e1 2022-12-20 op
55 ed619ca0 2022-12-14 op !}
56 ed619ca0 2022-12-14 op
57 df2d3cd2 2023-03-11 op {{ define gotweb_render_page(struct template *tp,
58 df2d3cd2 2023-03-11 op int (*body)(struct template *)) }}
59 ed619ca0 2022-12-14 op {!
60 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
61 ed619ca0 2022-12-14 op struct server *srv = c->srv;
62 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
63 ed619ca0 2022-12-14 op struct gotweb_url u_path;
64 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
65 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
66 ed619ca0 2022-12-14 op
67 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
68 ed619ca0 2022-12-14 op u_path.index_page = -1;
69 ed619ca0 2022-12-14 op u_path.page = -1;
70 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
71 ed619ca0 2022-12-14 op !}
72 ed619ca0 2022-12-14 op <!doctype html>
73 ed619ca0 2022-12-14 op <html>
74 ed619ca0 2022-12-14 op <head>
75 ed619ca0 2022-12-14 op <meta charset="utf-8" />
76 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
77 424803ac 2023-09-12 op <meta name="viewport" content="initial-scale=1.0" />
78 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
79 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
80 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
81 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
82 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
83 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
84 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
85 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
86 ed619ca0 2022-12-14 op </head>
87 ed619ca0 2022-12-14 op <body>
88 424803ac 2023-09-12 op <header id="header">
89 424803ac 2023-09-12 op <div id="got_link">
90 424803ac 2023-09-12 op <a href="{{ srv->logo_url }}" target="_blank">
91 424803ac 2023-09-12 op <img src="{{ prfx }}{{ srv->logo }}" />
92 424803ac 2023-09-12 op </a>
93 ed619ca0 2022-12-14 op </div>
94 424803ac 2023-09-12 op </header>
95 424803ac 2023-09-12 op <nav id="site_path">
96 424803ac 2023-09-12 op <div id="site_link">
97 424803ac 2023-09-12 op <a href="?index_page={{ printf "%d", qs->index_page }}">
98 424803ac 2023-09-12 op {{ srv->site_link }}
99 424803ac 2023-09-12 op </a>
100 424803ac 2023-09-12 op {{ if qs->path }}
101 424803ac 2023-09-12 op {! u_path.path = qs->path; !}
102 424803ac 2023-09-12 op {{ " / " }}
103 424803ac 2023-09-12 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
104 424803ac 2023-09-12 op {{ qs->path }}
105 ed619ca0 2022-12-14 op </a>
106 424803ac 2023-09-12 op {{ end }}
107 424803ac 2023-09-12 op {{ if qs->action != INDEX }}
108 424803ac 2023-09-12 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
109 424803ac 2023-09-12 op {{ end }}
110 ed619ca0 2022-12-14 op </div>
111 424803ac 2023-09-12 op </nav>
112 424803ac 2023-09-12 op <main>
113 424803ac 2023-09-12 op {{ render body(tp) }}
114 424803ac 2023-09-12 op </main>
115 424803ac 2023-09-12 op <footer id="site_owner_wrapper">
116 424803ac 2023-09-12 op <p id="site_owner">
117 424803ac 2023-09-12 op {{ if srv->show_site_owner }}
118 424803ac 2023-09-12 op {{ srv->site_owner }}
119 424803ac 2023-09-12 op {{ end }}
120 424803ac 2023-09-12 op </p>
121 424803ac 2023-09-12 op </footer>
122 ed619ca0 2022-12-14 op </body>
123 ed619ca0 2022-12-14 op </html>
124 8f37175d 2023-03-11 op {{ end }}
125 8f37175d 2023-03-11 op
126 8f37175d 2023-03-11 op {{ define gotweb_render_error(struct template *tp) }}
127 8f37175d 2023-03-11 op {!
128 8f37175d 2023-03-11 op struct request *c = tp->tp_arg;
129 8f37175d 2023-03-11 op struct transport *t = c->t;
130 8f37175d 2023-03-11 op !}
131 8f37175d 2023-03-11 op <div id="err_content">
132 8f37175d 2023-03-11 op {{ if t->error }}
133 8f37175d 2023-03-11 op {{ t->error->msg }}
134 8f37175d 2023-03-11 op {{ else }}
135 8f37175d 2023-03-11 op See daemon logs for details
136 8f37175d 2023-03-11 op {{ end }}
137 8f37175d 2023-03-11 op </div>
138 ed619ca0 2022-12-14 op {{ end }}
139 ed619ca0 2022-12-14 op
140 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
141 ed619ca0 2022-12-14 op {!
142 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
143 ed619ca0 2022-12-14 op struct server *srv = c->srv;
144 ed619ca0 2022-12-14 op !}
145 ed619ca0 2022-12-14 op <div id="index_header">
146 424803ac 2023-09-12 op <div class="index_project">
147 ed619ca0 2022-12-14 op Project
148 ed619ca0 2022-12-14 op </div>
149 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
150 424803ac 2023-09-12 op <div class="index_project_description">
151 ed619ca0 2022-12-14 op Description
152 ed619ca0 2022-12-14 op </div>
153 ed619ca0 2022-12-14 op {{ end }}
154 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
155 424803ac 2023-09-12 op <div class="index_project_owner">
156 ed619ca0 2022-12-14 op Owner
157 ed619ca0 2022-12-14 op </div>
158 ed619ca0 2022-12-14 op {{ end }}
159 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
160 424803ac 2023-09-12 op <div class="index_project_age">
161 ed619ca0 2022-12-14 op Last Change
162 ed619ca0 2022-12-14 op </div>
163 ed619ca0 2022-12-14 op {{ end }}
164 ed619ca0 2022-12-14 op </div>
165 ed619ca0 2022-12-14 op {{ end }}
166 ed619ca0 2022-12-14 op
167 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
168 ed619ca0 2022-12-14 op {!
169 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
170 ed619ca0 2022-12-14 op struct server *srv = c->srv;
171 ed619ca0 2022-12-14 op struct gotweb_url summary = {
172 ed619ca0 2022-12-14 op .action = SUMMARY,
173 ed619ca0 2022-12-14 op .index_page = -1,
174 ed619ca0 2022-12-14 op .page = -1,
175 ed619ca0 2022-12-14 op .path = repo_dir->name,
176 ed619ca0 2022-12-14 op }, briefs = {
177 ed619ca0 2022-12-14 op .action = BRIEFS,
178 ed619ca0 2022-12-14 op .index_page = -1,
179 ed619ca0 2022-12-14 op .page = -1,
180 ed619ca0 2022-12-14 op .path = repo_dir->name,
181 ed619ca0 2022-12-14 op }, commits = {
182 ed619ca0 2022-12-14 op .action = COMMITS,
183 ed619ca0 2022-12-14 op .index_page = -1,
184 ed619ca0 2022-12-14 op .page = -1,
185 ed619ca0 2022-12-14 op .path = repo_dir->name,
186 ed619ca0 2022-12-14 op }, tags = {
187 ed619ca0 2022-12-14 op .action = TAGS,
188 ed619ca0 2022-12-14 op .index_page = -1,
189 ed619ca0 2022-12-14 op .page = -1,
190 ed619ca0 2022-12-14 op .path = repo_dir->name,
191 ed619ca0 2022-12-14 op }, tree = {
192 ed619ca0 2022-12-14 op .action = TREE,
193 ed619ca0 2022-12-14 op .index_page = -1,
194 ed619ca0 2022-12-14 op .page = -1,
195 ed619ca0 2022-12-14 op .path = repo_dir->name,
196 1abb18e1 2022-12-20 op }, rss = {
197 1abb18e1 2022-12-20 op .action = RSS,
198 1abb18e1 2022-12-20 op .index_page = -1,
199 1abb18e1 2022-12-20 op .page = -1,
200 1abb18e1 2022-12-20 op .path = repo_dir->name,
201 ed619ca0 2022-12-14 op };
202 ed619ca0 2022-12-14 op !}
203 ed619ca0 2022-12-14 op <div class="index_wrapper">
204 ed619ca0 2022-12-14 op <div class="index_project">
205 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
206 ed619ca0 2022-12-14 op </div>
207 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
208 ed619ca0 2022-12-14 op <div class="index_project_description">
209 ed619ca0 2022-12-14 op {{ repo_dir->description }}
210 ed619ca0 2022-12-14 op </div>
211 ed619ca0 2022-12-14 op {{ end }}
212 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
213 ed619ca0 2022-12-14 op <div class="index_project_owner">
214 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
215 ed619ca0 2022-12-14 op </div>
216 ed619ca0 2022-12-14 op {{ end }}
217 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
218 ed619ca0 2022-12-14 op <div class="index_project_age">
219 cb93ab40 2023-01-22 op {{ render gotweb_render_age(tp, repo_dir->age, TM_DIFF) }}
220 ed619ca0 2022-12-14 op </div>
221 ed619ca0 2022-12-14 op {{ end }}
222 ed619ca0 2022-12-14 op <div class="navs_wrapper">
223 ed619ca0 2022-12-14 op <div class="navs">
224 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
225 ed619ca0 2022-12-14 op {{ " | " }}
226 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
227 ed619ca0 2022-12-14 op {{ " | " }}
228 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
229 ed619ca0 2022-12-14 op {{ " | " }}
230 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
231 ed619ca0 2022-12-14 op {{ " | " }}
232 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
233 1abb18e1 2022-12-20 op {{ " | " }}
234 1abb18e1 2022-12-20 op <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
235 ed619ca0 2022-12-14 op </div>
236 424803ac 2023-09-12 op <hr />
237 ed619ca0 2022-12-14 op </div>
238 ed619ca0 2022-12-14 op </div>
239 ed619ca0 2022-12-14 op {{ end }}
240 ed619ca0 2022-12-14 op
241 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
242 ed619ca0 2022-12-14 op {!
243 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
244 ed619ca0 2022-12-14 op struct transport *t = c->t;
245 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
246 ed619ca0 2022-12-14 op struct repo_commit *rc;
247 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
248 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
249 ed619ca0 2022-12-14 op char *tmp;
250 ed619ca0 2022-12-14 op
251 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
252 ed619ca0 2022-12-14 op .action = DIFF,
253 ed619ca0 2022-12-14 op .index_page = -1,
254 ed619ca0 2022-12-14 op .page = -1,
255 ed619ca0 2022-12-14 op .path = repo_dir->name,
256 ed619ca0 2022-12-14 op .headref = qs->headref,
257 ed619ca0 2022-12-14 op };
258 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
259 ed619ca0 2022-12-14 op .action = TREE,
260 ed619ca0 2022-12-14 op .index_page = -1,
261 ed619ca0 2022-12-14 op .page = -1,
262 ed619ca0 2022-12-14 op .path = repo_dir->name,
263 ed619ca0 2022-12-14 op .headref = qs->headref,
264 ed619ca0 2022-12-14 op };
265 ed619ca0 2022-12-14 op !}
266 424803ac 2023-09-12 op <header class='subtitle'>
267 424803ac 2023-09-12 op <h2>Commit Briefs</h2>
268 424803ac 2023-09-12 op </header>
269 ed619ca0 2022-12-14 op <div id="briefs_content">
270 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
271 ed619ca0 2022-12-14 op {!
272 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
273 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
274 ed619ca0 2022-12-14 op
275 6c3d3263 2023-01-10 op tmp = strchr(rc->committer, '<');
276 ed619ca0 2022-12-14 op if (tmp)
277 ed619ca0 2022-12-14 op *tmp = '\0';
278 ed619ca0 2022-12-14 op
279 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
280 ed619ca0 2022-12-14 op if (tmp)
281 ed619ca0 2022-12-14 op *tmp = '\0';
282 ed619ca0 2022-12-14 op !}
283 424803ac 2023-09-12 op <div class='brief'>
284 424803ac 2023-09-12 op <p class='brief_meta'>
285 424803ac 2023-09-12 op <span class='briefs_age'>
286 424803ac 2023-09-12 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
287 424803ac 2023-09-12 op </span>
288 424803ac 2023-09-12 op {{" "}}
289 424803ac 2023-09-12 op <span class="briefs_author">
290 424803ac 2023-09-12 op {{ rc->committer }}
291 424803ac 2023-09-12 op </span>
292 424803ac 2023-09-12 op </p>
293 424803ac 2023-09-12 op <p class="briefs_log">
294 424803ac 2023-09-12 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
295 424803ac 2023-09-12 op {{ rc->commit_msg }}
296 424803ac 2023-09-12 op </a>
297 424803ac 2023-09-12 op {{ if rc->refs_str }}
298 424803ac 2023-09-12 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
299 424803ac 2023-09-12 op {{ end }}
300 424803ac 2023-09-12 op </a>
301 424803ac 2023-09-12 op </p>
302 ed619ca0 2022-12-14 op </div>
303 ed619ca0 2022-12-14 op <div class="navs_wrapper">
304 ed619ca0 2022-12-14 op <div class="navs">
305 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
306 ed619ca0 2022-12-14 op {{ " | " }}
307 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
308 ed619ca0 2022-12-14 op </div>
309 ed619ca0 2022-12-14 op </div>
310 424803ac 2023-09-12 op <hr />
311 ed619ca0 2022-12-14 op {{ end }}
312 e3662697 2023-02-03 op {{ render gotweb_render_more(tp, BRIEFS) }}
313 b4c0bd72 2022-12-17 op </div>
314 b4c0bd72 2022-12-17 op {{ end }}
315 b4c0bd72 2022-12-17 op
316 e3662697 2023-02-03 op {{ define gotweb_render_more(struct template *tp, int action) }}
317 e3662697 2023-02-03 op {!
318 e3662697 2023-02-03 op struct request *c = tp->tp_arg;
319 e3662697 2023-02-03 op struct transport *t = c->t;
320 e3662697 2023-02-03 op struct querystring *qs = t->qs;
321 e3662697 2023-02-03 op struct gotweb_url more = {
322 e3662697 2023-02-03 op .action = action,
323 e3662697 2023-02-03 op .index_page = -1,
324 e3662697 2023-02-03 op .path = qs->path,
325 e3662697 2023-02-03 op .commit = t->more_id,
326 e3662697 2023-02-03 op .headref = qs->headref,
327 de8c0409 2023-09-12 op .file = qs->file,
328 e3662697 2023-02-03 op };
329 e3662697 2023-02-03 op !}
330 e3662697 2023-02-03 op {{ if t->more_id }}
331 e3662697 2023-02-03 op <div id="np_wrapper">
332 e3662697 2023-02-03 op <div id="nav_more">
333 e3662697 2023-02-03 op <a href="{{ render gotweb_render_url(c, &more) }}">
334 0af50e04 2023-02-03 op More&nbsp;&darr;
335 e3662697 2023-02-03 op </a>
336 e3662697 2023-02-03 op </div>
337 e3662697 2023-02-03 op </div>
338 e3662697 2023-02-03 op {{ end }}
339 e3662697 2023-02-03 op {{ end }}
340 e3662697 2023-02-03 op
341 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
342 b4c0bd72 2022-12-17 op {!
343 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
344 b4c0bd72 2022-12-17 op struct transport *t = c->t;
345 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
346 b4c0bd72 2022-12-17 op int have_prev, have_next;
347 b4c0bd72 2022-12-17 op
348 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
349 b4c0bd72 2022-12-17 op !}
350 b4c0bd72 2022-12-17 op <div id="np_wrapper">
351 b4c0bd72 2022-12-17 op <div id="nav_prev">
352 b4c0bd72 2022-12-17 op {{ if have_prev }}
353 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
354 b4c0bd72 2022-12-17 op Previous
355 b4c0bd72 2022-12-17 op </a>
356 b4c0bd72 2022-12-17 op {{ end }}
357 b4c0bd72 2022-12-17 op </div>
358 b4c0bd72 2022-12-17 op <div id="nav_next">
359 b4c0bd72 2022-12-17 op {{ if have_next }}
360 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
361 b4c0bd72 2022-12-17 op Next
362 b4c0bd72 2022-12-17 op </a>
363 b4c0bd72 2022-12-17 op {{ end }}
364 b4c0bd72 2022-12-17 op </div>
365 ed619ca0 2022-12-14 op </div>
366 b4c0bd72 2022-12-17 op {{ finally }}
367 b4c0bd72 2022-12-17 op {!
368 b4c0bd72 2022-12-17 op free(t->next_id);
369 b4c0bd72 2022-12-17 op t->next_id = NULL;
370 b4c0bd72 2022-12-17 op free(t->prev_id);
371 b4c0bd72 2022-12-17 op t->prev_id = NULL;
372 b4c0bd72 2022-12-17 op !}
373 ed619ca0 2022-12-14 op {{ end }}
374 156a1144 2022-12-17 op
375 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
376 156a1144 2022-12-17 op {!
377 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
378 156a1144 2022-12-17 op struct transport *t = c->t;
379 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
380 156a1144 2022-12-17 op struct repo_commit *rc;
381 156a1144 2022-12-17 op struct gotweb_url diff, tree;
382 156a1144 2022-12-17 op
383 156a1144 2022-12-17 op diff = (struct gotweb_url){
384 156a1144 2022-12-17 op .action = DIFF,
385 156a1144 2022-12-17 op .index_page = -1,
386 156a1144 2022-12-17 op .page = -1,
387 156a1144 2022-12-17 op .path = repo_dir->name,
388 156a1144 2022-12-17 op };
389 156a1144 2022-12-17 op tree = (struct gotweb_url){
390 156a1144 2022-12-17 op .action = TREE,
391 156a1144 2022-12-17 op .index_page = -1,
392 156a1144 2022-12-17 op .page = -1,
393 156a1144 2022-12-17 op .path = repo_dir->name,
394 156a1144 2022-12-17 op };
395 156a1144 2022-12-17 op !}
396 424803ac 2023-09-12 op <header class="subtitle">
397 424803ac 2023-09-12 op <h2>Commits</h2>
398 424803ac 2023-09-12 op </header>
399 156a1144 2022-12-17 op <div class="commits_content">
400 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
401 156a1144 2022-12-17 op {!
402 156a1144 2022-12-17 op diff.commit = rc->commit_id;
403 156a1144 2022-12-17 op tree.commit = rc->commit_id;
404 156a1144 2022-12-17 op !}
405 156a1144 2022-12-17 op <div class="commits_header_wrapper">
406 424803ac 2023-09-12 op <dl class="commits_header">
407 424803ac 2023-09-12 op <dt>Commit:</dt>
408 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
409 424803ac 2023-09-12 op <dt>From:</dt>
410 424803ac 2023-09-12 op <dd>{{ rc->author }}</dd>
411 af800df5 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
412 424803ac 2023-09-12 op <dt>Via:</dt>
413 424803ac 2023-09-12 op <dd>{{ rc->committer }}</dd>
414 af800df5 2023-01-10 op {{ end }}
415 424803ac 2023-09-12 op <dt>Date:</dt>
416 424803ac 2023-09-12 op <dd>
417 156a1144 2022-12-17 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
418 424803ac 2023-09-12 op </dd>
419 424803ac 2023-09-12 op </dl>
420 156a1144 2022-12-17 op </div>
421 424803ac 2023-09-12 op <hr />
422 cf536071 2022-12-31 op <div class="commit">
423 cf536071 2022-12-31 op {{ "\n" }}
424 cf536071 2022-12-31 op {{ rc->commit_msg }}
425 cf536071 2022-12-31 op </div>
426 156a1144 2022-12-17 op <div class="navs_wrapper">
427 156a1144 2022-12-17 op <div class="navs">
428 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
429 156a1144 2022-12-17 op {{ " | " }}
430 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
431 156a1144 2022-12-17 op </div>
432 156a1144 2022-12-17 op </div>
433 424803ac 2023-09-12 op <hr />
434 156a1144 2022-12-17 op {{ end }}
435 e3662697 2023-02-03 op {{ render gotweb_render_more(tp, COMMITS) }}
436 298f95fb 2023-01-05 op </div>
437 298f95fb 2023-01-05 op {{ end }}
438 298f95fb 2023-01-05 op
439 df2d3cd2 2023-03-11 op {{ define gotweb_render_blob(struct template *tp) }}
440 298f95fb 2023-01-05 op {!
441 298f95fb 2023-01-05 op struct request *c = tp->tp_arg;
442 298f95fb 2023-01-05 op struct transport *t = c->t;
443 df2d3cd2 2023-03-11 op struct got_blob_object *blob = t->blob;
444 298f95fb 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
445 298f95fb 2023-01-05 op !}
446 424803ac 2023-09-12 op <header class="subtitle">
447 424803ac 2023-09-12 op <h2>Blob</h2>
448 424803ac 2023-09-12 op </header>
449 298f95fb 2023-01-05 op <div id="blob_content">
450 298f95fb 2023-01-05 op <div id="blob_header_wrapper">
451 424803ac 2023-09-12 op <dl id="blob_header">
452 424803ac 2023-09-12 op <dt>Date:</dt>
453 424803ac 2023-09-12 op <dd>
454 424803ac 2023-09-12 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
455 424803ac 2023-09-12 op </dd>
456 424803ac 2023-09-12 op <dt>Message:</dt>
457 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
458 424803ac 2023-09-12 op </dl>
459 298f95fb 2023-01-05 op </div>
460 424803ac 2023-09-12 op <hr />
461 298f95fb 2023-01-05 op <div id="blob">
462 298f95fb 2023-01-05 op <pre>
463 298f95fb 2023-01-05 op {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
464 298f95fb 2023-01-05 op </pre>
465 298f95fb 2023-01-05 op </div>
466 156a1144 2022-12-17 op </div>
467 1abb18e1 2022-12-20 op {{ end }}
468 1abb18e1 2022-12-20 op
469 298f95fb 2023-01-05 op {{ define gotweb_render_blob_line(struct template *tp, const char *line,
470 298f95fb 2023-01-05 op size_t no) }}
471 298f95fb 2023-01-05 op {!
472 298f95fb 2023-01-05 op char lineno[16];
473 298f95fb 2023-01-05 op int r;
474 298f95fb 2023-01-05 op
475 298f95fb 2023-01-05 op r = snprintf(lineno, sizeof(lineno), "%zu", no);
476 298f95fb 2023-01-05 op if (r < 0 || (size_t)r >= sizeof(lineno))
477 298f95fb 2023-01-05 op return -1;
478 298f95fb 2023-01-05 op !}
479 298f95fb 2023-01-05 op <div class="blob_line" id="line{{ lineno }}">
480 424803ac 2023-09-12 op <a href="#line{{ lineno }}">{{ lineno }}</a>
481 424803ac 2023-09-12 op <span class="blob_code">{{ line }}</span>
482 43d421de 2023-01-05 op </div>
483 43d421de 2023-01-05 op {{ end }}
484 43d421de 2023-01-05 op
485 43d421de 2023-01-05 op {{ define gotweb_render_tree(struct template *tp) }}
486 43d421de 2023-01-05 op {!
487 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
488 43d421de 2023-01-05 op struct transport *t = c->t;
489 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
490 43d421de 2023-01-05 op !}
491 424803ac 2023-09-12 op <header class='subtitle'>
492 424803ac 2023-09-12 op <h2>Tree</h2>
493 424803ac 2023-09-12 op </header>
494 43d421de 2023-01-05 op <div id="tree_content">
495 43d421de 2023-01-05 op <div id="tree_header_wrapper">
496 424803ac 2023-09-12 op <dl id="tree_header">
497 424803ac 2023-09-12 op <dt>Tree:</dt>
498 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
499 424803ac 2023-09-12 op <dt>Date:</dt>
500 424803ac 2023-09-12 op <dd>
501 43d421de 2023-01-05 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
502 424803ac 2023-09-12 op </dd>
503 424803ac 2023-09-12 op <dt>Message:</dt>
504 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</d>
505 424803ac 2023-09-12 op </dl>
506 43d421de 2023-01-05 op </div>
507 424803ac 2023-09-12 op <hr />
508 424803ac 2023-09-12 op <table id="tree">
509 43d421de 2023-01-05 op {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
510 424803ac 2023-09-12 op </table>
511 43d421de 2023-01-05 op </div>
512 43d421de 2023-01-05 op {{ end }}
513 43d421de 2023-01-05 op
514 43d421de 2023-01-05 op {{ define gotweb_render_tree_item(struct template *tp,
515 43d421de 2023-01-05 op struct got_tree_entry *te) }}
516 43d421de 2023-01-05 op {!
517 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
518 43d421de 2023-01-05 op struct transport *t = c->t;
519 43d421de 2023-01-05 op struct querystring *qs = t->qs;
520 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
521 43d421de 2023-01-05 op const char *modestr = "";
522 43d421de 2023-01-05 op const char *name;
523 43d421de 2023-01-05 op const char *folder;
524 43d421de 2023-01-05 op char *dir = NULL;
525 43d421de 2023-01-05 op mode_t mode;
526 43d421de 2023-01-05 op struct gotweb_url url = {
527 43d421de 2023-01-05 op .index_page = -1,
528 43d421de 2023-01-05 op .page = -1,
529 43d421de 2023-01-05 op .commit = rc->commit_id,
530 43d421de 2023-01-05 op .path = qs->path,
531 43d421de 2023-01-05 op };
532 43d421de 2023-01-05 op
533 43d421de 2023-01-05 op name = got_tree_entry_get_name(te);
534 43d421de 2023-01-05 op mode = got_tree_entry_get_mode(te);
535 43d421de 2023-01-05 op
536 43d421de 2023-01-05 op folder = qs->folder ? qs->folder : "";
537 43d421de 2023-01-05 op if (S_ISDIR(mode)) {
538 43d421de 2023-01-05 op if (asprintf(&dir, "%s/%s", folder, name) == -1)
539 43d421de 2023-01-05 op return (-1);
540 43d421de 2023-01-05 op
541 43d421de 2023-01-05 op url.action = TREE;
542 43d421de 2023-01-05 op url.folder = dir;
543 43d421de 2023-01-05 op } else {
544 43d421de 2023-01-05 op url.action = BLOB;
545 43d421de 2023-01-05 op url.folder = folder;
546 43d421de 2023-01-05 op url.file = name;
547 43d421de 2023-01-05 op }
548 43d421de 2023-01-05 op
549 43d421de 2023-01-05 op if (got_object_tree_entry_is_submodule(te))
550 43d421de 2023-01-05 op modestr = "$";
551 43d421de 2023-01-05 op else if (S_ISLNK(mode))
552 43d421de 2023-01-05 op modestr = "@";
553 43d421de 2023-01-05 op else if (S_ISDIR(mode))
554 43d421de 2023-01-05 op modestr = "/";
555 43d421de 2023-01-05 op else if (mode & S_IXUSR)
556 43d421de 2023-01-05 op modestr = "*";
557 43d421de 2023-01-05 op !}
558 424803ac 2023-09-12 op <tr class="tree_wrapper">
559 43d421de 2023-01-05 op {{ if S_ISDIR(mode) }}
560 424803ac 2023-09-12 op <td class="tree_line" colspan=2>
561 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
562 43d421de 2023-01-05 op {{ name }}{{ modestr }}
563 43d421de 2023-01-05 op </a>
564 424803ac 2023-09-12 op </td>
565 43d421de 2023-01-05 op {{ else }}
566 424803ac 2023-09-12 op <td class="tree_line">
567 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
568 43d421de 2023-01-05 op {{ name }}{{ modestr }}
569 43d421de 2023-01-05 op </a>
570 424803ac 2023-09-12 op </td>
571 424803ac 2023-09-12 op <td class="tree_line_blank">
572 43d421de 2023-01-05 op {! url.action = COMMITS; !}
573 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
574 43d421de 2023-01-05 op commits
575 43d421de 2023-01-05 op </a>
576 43d421de 2023-01-05 op {{ " | " }}
577 43d421de 2023-01-05 op {! url.action = BLAME; !}
578 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
579 43d421de 2023-01-05 op blame
580 43d421de 2023-01-05 op </a>
581 424803ac 2023-09-12 op </td>
582 43d421de 2023-01-05 op {{ end }}
583 424803ac 2023-09-12 op </tr>
584 43d421de 2023-01-05 op {{ finally }}
585 43d421de 2023-01-05 op {!
586 43d421de 2023-01-05 op free(dir);
587 067396e6 2023-01-09 op !}
588 067396e6 2023-01-09 op {{ end }}
589 067396e6 2023-01-09 op
590 d60961d2 2023-01-13 op {{ define gotweb_render_tags(struct template *tp) }}
591 067396e6 2023-01-09 op {!
592 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
593 067396e6 2023-01-09 op struct transport *t = c->t;
594 067396e6 2023-01-09 op struct querystring *qs = t->qs;
595 067396e6 2023-01-09 op struct repo_tag *rt;
596 067396e6 2023-01-09 op int commit_found;
597 067396e6 2023-01-09 op
598 067396e6 2023-01-09 op commit_found = qs->commit == NULL;
599 43d421de 2023-01-05 op !}
600 424803ac 2023-09-12 op <header class='subtitle'>
601 424803ac 2023-09-12 op <h2>Tags</h2>
602 424803ac 2023-09-12 op </header>
603 067396e6 2023-01-09 op <div id="tags_content">
604 067396e6 2023-01-09 op {{ if t->tag_count == 0 }}
605 067396e6 2023-01-09 op <div id="err_content">
606 067396e6 2023-01-09 op This repository contains no tags
607 067396e6 2023-01-09 op </div>
608 067396e6 2023-01-09 op {{ else }}
609 067396e6 2023-01-09 op {{ tailq-foreach rt &t->repo_tags entry }}
610 067396e6 2023-01-09 op {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
611 067396e6 2023-01-09 op {! commit_found = 1; !}
612 067396e6 2023-01-09 op {{ render tag_item(tp, rt) }}
613 067396e6 2023-01-09 op {{ end }}
614 067396e6 2023-01-09 op {{ end }}
615 067396e6 2023-01-09 op {{ if t->next_id || t->prev_id }}
616 e3662697 2023-02-03 op {! qs->action = TAGS; !}
617 067396e6 2023-01-09 op {{ render gotweb_render_navs(tp) }}
618 067396e6 2023-01-09 op {{ end }}
619 067396e6 2023-01-09 op {{ end }}
620 067396e6 2023-01-09 op </div>
621 298f95fb 2023-01-05 op {{ end }}
622 298f95fb 2023-01-05 op
623 067396e6 2023-01-09 op {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
624 067396e6 2023-01-09 op {!
625 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
626 067396e6 2023-01-09 op struct transport *t = c->t;
627 067396e6 2023-01-09 op struct repo_dir *repo_dir = t->repo_dir;
628 067396e6 2023-01-09 op char *tag_name = rt->tag_name;
629 067396e6 2023-01-09 op char *msg = rt->tag_commit;
630 067396e6 2023-01-09 op char *nl;
631 067396e6 2023-01-09 op struct gotweb_url url = {
632 067396e6 2023-01-09 op .action = TAG,
633 067396e6 2023-01-09 op .index_page = -1,
634 067396e6 2023-01-09 op .page = -1,
635 067396e6 2023-01-09 op .path = repo_dir->name,
636 067396e6 2023-01-09 op .commit = rt->commit_id,
637 067396e6 2023-01-09 op };
638 067396e6 2023-01-09 op
639 067396e6 2023-01-09 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
640 067396e6 2023-01-09 op tag_name += 10;
641 067396e6 2023-01-09 op
642 067396e6 2023-01-09 op if (msg) {
643 067396e6 2023-01-09 op nl = strchr(msg, '\n');
644 067396e6 2023-01-09 op if (nl)
645 067396e6 2023-01-09 op *nl = '\0';
646 067396e6 2023-01-09 op }
647 067396e6 2023-01-09 op !}
648 067396e6 2023-01-09 op <div class="tag_age">
649 067396e6 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
650 067396e6 2023-01-09 op </div>
651 424803ac 2023-09-12 op <div class="tag_name">{{ tag_name }}</div>
652 067396e6 2023-01-09 op <div class="tag_log">
653 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">
654 067396e6 2023-01-09 op {{ msg }}
655 067396e6 2023-01-09 op </a>
656 067396e6 2023-01-09 op </div>
657 067396e6 2023-01-09 op <div class="navs_wrapper">
658 067396e6 2023-01-09 op <div class="navs">
659 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
660 067396e6 2023-01-09 op {{ " | " }}
661 067396e6 2023-01-09 op {! url.action = BRIEFS; !}
662 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
663 067396e6 2023-01-09 op {{ " | " }}
664 067396e6 2023-01-09 op {! url.action = COMMITS; !}
665 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
666 067396e6 2023-01-09 op </div>
667 067396e6 2023-01-09 op </div>
668 424803ac 2023-09-12 op <hr />
669 067396e6 2023-01-09 op {{ end }}
670 dc07f76c 2023-01-09 op
671 dc07f76c 2023-01-09 op {{ define gotweb_render_tag(struct template *tp) }}
672 dc07f76c 2023-01-09 op {!
673 dc07f76c 2023-01-09 op struct request *c = tp->tp_arg;
674 dc07f76c 2023-01-09 op struct transport *t = c->t;
675 dc07f76c 2023-01-09 op struct repo_tag *rt;
676 dc07f76c 2023-01-09 op const char *tag_name;
677 067396e6 2023-01-09 op
678 dc07f76c 2023-01-09 op rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
679 dc07f76c 2023-01-09 op tag_name = rt->tag_name;
680 dc07f76c 2023-01-09 op
681 dc07f76c 2023-01-09 op if (strncmp(tag_name, "refs/", 5) == 0)
682 dc07f76c 2023-01-09 op tag_name += 5;
683 dc07f76c 2023-01-09 op !}
684 424803ac 2023-09-12 op <header class="subtitle">
685 424803ac 2023-09-12 op <h2>Tag</h2>
686 424803ac 2023-09-12 op </header>
687 dc07f76c 2023-01-09 op <div id="tags_content">
688 dc07f76c 2023-01-09 op <div id="tag_header_wrapper">
689 424803ac 2023-09-12 op <dl id="tag_header">
690 424803ac 2023-09-12 op <dt>Commit:</dt>
691 424803ac 2023-09-12 op <dd>
692 424803ac 2023-09-12 op <code class="commit-id">{{ rt->commit_id }}</code>
693 dc07f76c 2023-01-09 op {{ " " }}
694 dc07f76c 2023-01-09 op <span class="refs_str">({{ tag_name }})</span>
695 424803ac 2023-09-12 op </dd>
696 424803ac 2023-09-12 op <dt>Tagger:</dt>
697 424803ac 2023-09-12 op <dd>{{ rt->tagger }}</dd>
698 424803ac 2023-09-12 op <dt>Date:</dt>
699 424803ac 2023-09-12 op <dd>
700 dc07f76c 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
701 424803ac 2023-09-12 op </dd>
702 424803ac 2023-09-12 op <dt>Message:</dt>
703 424803ac 2023-09-12 op <dd class="commit-msg">{{ rt->commit_msg }}</dd>
704 424803ac 2023-09-12 op </dl>
705 424803ac 2023-09-12 op <hr />
706 424803ac 2023-09-12 op <pre id="tag_commit">
707 dc07f76c 2023-01-09 op {{ rt->tag_commit }}
708 424803ac 2023-09-12 op </pre>
709 587550a5 2023-01-10 op </div>
710 587550a5 2023-01-10 op </div>
711 587550a5 2023-01-10 op {{ end }}
712 587550a5 2023-01-10 op
713 df2d3cd2 2023-03-11 op {{ define gotweb_render_diff(struct template *tp) }}
714 587550a5 2023-01-10 op {!
715 587550a5 2023-01-10 op struct request *c = tp->tp_arg;
716 587550a5 2023-01-10 op struct transport *t = c->t;
717 df2d3cd2 2023-03-11 op FILE *fp = t->fp;
718 587550a5 2023-01-10 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
719 587550a5 2023-01-10 op char *line = NULL;
720 587550a5 2023-01-10 op size_t linesize = 0;
721 587550a5 2023-01-10 op ssize_t linelen;
722 587550a5 2023-01-10 op !}
723 424803ac 2023-09-12 op <header class="subtitle">
724 424803ac 2023-09-12 op <h2>Commit Diff</h2>
725 424803ac 2023-09-12 op </header>
726 587550a5 2023-01-10 op <div id="diff_content">
727 587550a5 2023-01-10 op <div id="diff_header_wrapper">
728 424803ac 2023-09-12 op <dl id="diff_header">
729 424803ac 2023-09-12 op <dt>Commit:</dt>
730 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
731 424803ac 2023-09-12 op <dt>From:</dt>
732 424803ac 2023-09-12 op <dd>{{ rc->author }}</dd>
733 49632cd3 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
734 424803ac 2023-09-12 op <dt>Via:</dt>
735 424803ac 2023-09-12 op <dd>{{ rc->committer }}</dd>
736 49632cd3 2023-01-10 op {{ end }}
737 424803ac 2023-09-12 op <dt>Date:</dt>
738 424803ac 2023-09-12 op <dd>
739 587550a5 2023-01-10 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
740 424803ac 2023-09-12 op </dd>
741 424803ac 2023-09-12 op <dt>Message:</dt>
742 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
743 424803ac 2023-09-12 op </dl>
744 dc07f76c 2023-01-09 op </div>
745 424803ac 2023-09-12 op <hr />
746 424803ac 2023-09-12 op <pre id="diff">
747 587550a5 2023-01-10 op {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
748 587550a5 2023-01-10 op {{ render diff_line(tp, line) }}
749 587550a5 2023-01-10 op {{ end }}
750 424803ac 2023-09-12 op </pre>
751 dc07f76c 2023-01-09 op </div>
752 587550a5 2023-01-10 op {{ finally }}
753 587550a5 2023-01-10 op {! free(line); !}
754 dc07f76c 2023-01-09 op {{ end }}
755 dc07f76c 2023-01-09 op
756 587550a5 2023-01-10 op {{ define diff_line(struct template *tp, char *line )}}
757 587550a5 2023-01-10 op {!
758 587550a5 2023-01-10 op const char *color = NULL;
759 587550a5 2023-01-10 op char *nl;
760 587550a5 2023-01-10 op
761 587550a5 2023-01-10 op if (!strncmp(line, "-", 1))
762 587550a5 2023-01-10 op color = "diff_minus";
763 587550a5 2023-01-10 op else if (!strncmp(line, "+", 1))
764 587550a5 2023-01-10 op color = "diff_plus";
765 587550a5 2023-01-10 op else if (!strncmp(line, "@@", 2))
766 587550a5 2023-01-10 op color = "diff_chunk_header";
767 587550a5 2023-01-10 op else if (!strncmp(line, "commit +", 8) ||
768 587550a5 2023-01-10 op !strncmp(line, "commit -", 8) ||
769 587550a5 2023-01-10 op !strncmp(line, "blob +", 6) ||
770 587550a5 2023-01-10 op !strncmp(line, "blob -", 6) ||
771 587550a5 2023-01-10 op !strncmp(line, "file +", 6) ||
772 587550a5 2023-01-10 op !strncmp(line, "file -", 6))
773 587550a5 2023-01-10 op color = "diff_meta";
774 587550a5 2023-01-10 op else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
775 587550a5 2023-01-10 op color = "diff_author";
776 587550a5 2023-01-10 op else if (!strncmp(line, "date:", 5))
777 587550a5 2023-01-10 op color = "diff_date";
778 587550a5 2023-01-10 op
779 587550a5 2023-01-10 op nl = strchr(line, '\n');
780 587550a5 2023-01-10 op if (nl)
781 587550a5 2023-01-10 op *nl = '\0';
782 587550a5 2023-01-10 op !}
783 424803ac 2023-09-12 op <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
784 3ab2c914 2023-01-11 op {{ end }}
785 3ab2c914 2023-01-11 op
786 3ab2c914 2023-01-11 op {{ define gotweb_render_branches(struct template *tp,
787 3ab2c914 2023-01-11 op struct got_reflist_head *refs) }}
788 3ab2c914 2023-01-11 op {!
789 3ab2c914 2023-01-11 op struct got_reflist_entry *re;
790 3ab2c914 2023-01-11 op !}
791 424803ac 2023-09-12 op <header class='subtitle'>
792 424803ac 2023-09-12 op <h2>Branches</h2>
793 424803ac 2023-09-12 op </header>
794 3ab2c914 2023-01-11 op <div id="branches_content">
795 3ab2c914 2023-01-11 op {{ tailq-foreach re refs entry }}
796 3ab2c914 2023-01-11 op {{ if !got_ref_is_symbolic(re->ref) }}
797 3ab2c914 2023-01-11 op {{ render branch(tp, re) }}
798 3ab2c914 2023-01-11 op {{ end }}
799 3ab2c914 2023-01-11 op {{ end }}
800 3ab2c914 2023-01-11 op </div>
801 3ab2c914 2023-01-11 op {{ end }}
802 3ab2c914 2023-01-11 op
803 3ab2c914 2023-01-11 op {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
804 3ab2c914 2023-01-11 op {!
805 3ab2c914 2023-01-11 op const struct got_error *err;
806 3ab2c914 2023-01-11 op struct request *c = tp->tp_arg;
807 3ab2c914 2023-01-11 op struct querystring *qs = c->t->qs;
808 3ab2c914 2023-01-11 op const char *refname;
809 cb93ab40 2023-01-22 op time_t age;
810 3ab2c914 2023-01-11 op struct gotweb_url url = {
811 3ab2c914 2023-01-11 op .action = SUMMARY,
812 3ab2c914 2023-01-11 op .index_page = -1,
813 3ab2c914 2023-01-11 op .page = -1,
814 3ab2c914 2023-01-11 op .path = qs->path,
815 3ab2c914 2023-01-11 op };
816 3ab2c914 2023-01-11 op
817 3ab2c914 2023-01-11 op refname = got_ref_get_name(re->ref);
818 3ab2c914 2023-01-11 op
819 cb93ab40 2023-01-22 op err = got_get_repo_age(&age, c, refname);
820 3ab2c914 2023-01-11 op if (err) {
821 3ab2c914 2023-01-11 op log_warnx("%s: %s", __func__, err->msg);
822 3ab2c914 2023-01-11 op return -1;
823 3ab2c914 2023-01-11 op }
824 3ab2c914 2023-01-11 op
825 3ab2c914 2023-01-11 op if (strncmp(refname, "refs/heads/", 11) == 0)
826 3ab2c914 2023-01-11 op refname += 11;
827 3ab2c914 2023-01-11 op
828 3ab2c914 2023-01-11 op url.headref = refname;
829 3ab2c914 2023-01-11 op !}
830 424803ac 2023-09-12 op <section class="branches_wrapper">
831 cb93ab40 2023-01-22 op <div class="branches_age">
832 cb93ab40 2023-01-22 op {{ render gotweb_render_age(tp, age, TM_DIFF) }}
833 cb93ab40 2023-01-22 op </div>
834 3ab2c914 2023-01-11 op <div class="branch">
835 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
836 3ab2c914 2023-01-11 op </div>
837 3ab2c914 2023-01-11 op <div class="navs_wrapper">
838 3ab2c914 2023-01-11 op <div class="navs">
839 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
840 3ab2c914 2023-01-11 op {{" | "}}
841 3ab2c914 2023-01-11 op {! url.action = BRIEFS; !}
842 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
843 3ab2c914 2023-01-11 op {{" | "}}
844 3ab2c914 2023-01-11 op {! url.action = COMMITS; !}
845 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
846 3ab2c914 2023-01-11 op </div>
847 3ab2c914 2023-01-11 op </div>
848 424803ac 2023-09-12 op <hr />
849 424803ac 2023-09-12 op </section>
850 69525b4e 2023-01-13 op {{ end }}
851 69525b4e 2023-01-13 op
852 df2d3cd2 2023-03-11 op {{ define gotweb_render_summary(struct template *tp) }}
853 69525b4e 2023-01-13 op {!
854 69525b4e 2023-01-13 op struct request *c = tp->tp_arg;
855 69525b4e 2023-01-13 op struct server *srv = c->srv;
856 69525b4e 2023-01-13 op struct transport *t = c->t;
857 df2d3cd2 2023-03-11 op struct got_reflist_head *refs = &t->refs;
858 69525b4e 2023-01-13 op !}
859 424803ac 2023-09-12 op <dl id="summary_wrapper">
860 69525b4e 2023-01-13 op {{ if srv->show_repo_description }}
861 424803ac 2023-09-12 op <dt>Description:</dt>
862 424803ac 2023-09-12 op <dd>{{ t->repo_dir->description }}</dd>
863 69525b4e 2023-01-13 op {{ end }}
864 69525b4e 2023-01-13 op {{ if srv->show_repo_owner }}
865 424803ac 2023-09-12 op <dt>Owner:</dt>
866 424803ac 2023-09-12 op <dd>{{ t->repo_dir->owner }}</dd>
867 69525b4e 2023-01-13 op {{ end }}
868 69525b4e 2023-01-13 op {{ if srv->show_repo_age }}
869 424803ac 2023-09-12 op <dt>Last Change:</dt>
870 424803ac 2023-09-12 op <dd>
871 cb93ab40 2023-01-22 op {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
872 424803ac 2023-09-12 op </dd>
873 69525b4e 2023-01-13 op {{ end }}
874 69525b4e 2023-01-13 op {{ if srv->show_repo_cloneurl }}
875 424803ac 2023-09-12 op <dt>Clone URL:</dt>
876 424803ac 2023-09-12 op <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
877 69525b4e 2023-01-13 op {{ end }}
878 424803ac 2023-09-12 op </dl>
879 69525b4e 2023-01-13 op {{ render gotweb_render_briefs(tp) }}
880 69525b4e 2023-01-13 op {{ render gotweb_render_tags(tp) }}
881 69525b4e 2023-01-13 op {{ render gotweb_render_branches(tp, refs) }}
882 587550a5 2023-01-10 op {{ end }}
883 587550a5 2023-01-10 op
884 8319855f 2023-01-15 op {{ define gotweb_render_blame(struct template *tp) }}
885 8319855f 2023-01-15 op {!
886 8319855f 2023-01-15 op const struct got_error *err;
887 8319855f 2023-01-15 op struct request *c = tp->tp_arg;
888 8319855f 2023-01-15 op struct transport *t = c->t;
889 8319855f 2023-01-15 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
890 8319855f 2023-01-15 op !}
891 424803ac 2023-09-12 op <header class="subtitle">
892 424803ac 2023-09-12 op <h2>Blame</h2>
893 424803ac 2023-09-12 op </header>
894 8319855f 2023-01-15 op <div id="blame_content">
895 8319855f 2023-01-15 op <div id="blame_header_wrapper">
896 424803ac 2023-09-12 op <dl id="blame_header">
897 424803ac 2023-09-12 op <dt>Date:</dt>
898 424803ac 2023-09-12 op <dd>
899 8319855f 2023-01-15 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
900 424803ac 2023-09-12 op </dd>
901 424803ac 2023-09-12 op <dt>Message:</dt>
902 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
903 424803ac 2023-09-12 op </dl>
904 8319855f 2023-01-15 op </div>
905 424803ac 2023-09-12 op <hr />
906 424803ac 2023-09-12 op <pre id="blame">
907 8319855f 2023-01-15 op {!
908 8319855f 2023-01-15 op err = got_output_file_blame(c, &blame_line);
909 8a078d7f 2023-05-17 op if (err && err->code != GOT_ERR_CANCELLED)
910 8319855f 2023-01-15 op log_warnx("%s: got_output_file_blame: %s", __func__,
911 8319855f 2023-01-15 op err->msg);
912 8a078d7f 2023-05-17 op if (err)
913 8319855f 2023-01-15 op return (-1);
914 8319855f 2023-01-15 op !}
915 424803ac 2023-09-12 op </pre>
916 8319855f 2023-01-15 op </div>
917 8319855f 2023-01-15 op {{ end }}
918 8319855f 2023-01-15 op
919 8319855f 2023-01-15 op {{ define blame_line(struct template *tp, const char *line,
920 8319855f 2023-01-15 op struct blame_line *bline, int lprec, int lcur) }}
921 8319855f 2023-01-15 op {!
922 8319855f 2023-01-15 op struct request *c = tp->tp_arg;
923 8319855f 2023-01-15 op struct transport *t = c->t;
924 8319855f 2023-01-15 op struct repo_dir *repo_dir = t->repo_dir;
925 8319855f 2023-01-15 op char *committer, *s;
926 8319855f 2023-01-15 op struct gotweb_url url = {
927 8319855f 2023-01-15 op .action = DIFF,
928 8319855f 2023-01-15 op .index_page = -1,
929 8319855f 2023-01-15 op .page = -1,
930 8319855f 2023-01-15 op .path = repo_dir->name,
931 8319855f 2023-01-15 op .commit = bline->id_str,
932 8319855f 2023-01-15 op };
933 8319855f 2023-01-15 op
934 8319855f 2023-01-15 op s = strchr(bline->committer, '<');
935 8319855f 2023-01-15 op committer = s ? s + 1 : bline->committer;
936 8319855f 2023-01-15 op
937 8319855f 2023-01-15 op s = strchr(committer, '@');
938 8319855f 2023-01-15 op if (s)
939 8319855f 2023-01-15 op *s = '\0';
940 8319855f 2023-01-15 op !}
941 8319855f 2023-01-15 op <div class="blame_wrapper">
942 8319855f 2023-01-15 op <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
943 8319855f 2023-01-15 op <div class="blame_hash">
944 8319855f 2023-01-15 op <a href="{{ render gotweb_render_url(c, &url) }}">
945 8319855f 2023-01-15 op {{ printf "%.8s", bline->id_str }}
946 8319855f 2023-01-15 op </a>
947 8319855f 2023-01-15 op </div>
948 8319855f 2023-01-15 op <div class="blame_date">{{ bline->datebuf }}</div>
949 8319855f 2023-01-15 op <div class="blame_author">{{ printf "%.9s", committer }}</div>
950 8319855f 2023-01-15 op <div class="blame_code">{{ line }}</div>
951 8319855f 2023-01-15 op </div>
952 8319855f 2023-01-15 op {{ end }}
953 8319855f 2023-01-15 op
954 1abb18e1 2022-12-20 op {{ define gotweb_render_rss(struct template *tp) }}
955 1abb18e1 2022-12-20 op {!
956 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
957 1abb18e1 2022-12-20 op struct server *srv = c->srv;
958 1abb18e1 2022-12-20 op struct transport *t = c->t;
959 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
960 1abb18e1 2022-12-20 op struct repo_tag *rt;
961 1abb18e1 2022-12-20 op struct gotweb_url summary = {
962 1abb18e1 2022-12-20 op .action = SUMMARY,
963 1abb18e1 2022-12-20 op .index_page = -1,
964 1abb18e1 2022-12-20 op .page = -1,
965 1abb18e1 2022-12-20 op .path = repo_dir->name,
966 1abb18e1 2022-12-20 op };
967 1abb18e1 2022-12-20 op !}
968 1abb18e1 2022-12-20 op <?xml version="1.0" encoding="UTF-8"?>
969 1abb18e1 2022-12-20 op <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
970 1abb18e1 2022-12-20 op <channel>
971 1abb18e1 2022-12-20 op <title>Tags of {{ repo_dir->name }}</title>
972 1abb18e1 2022-12-20 op <link>
973 1abb18e1 2022-12-20 op <![CDATA[
974 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &summary) }}
975 1abb18e1 2022-12-20 op ]]>
976 1abb18e1 2022-12-20 op </link>
977 1abb18e1 2022-12-20 op {{ if srv->show_repo_description }}
978 1abb18e1 2022-12-20 op <description>{{ repo_dir->description }}</description>
979 1abb18e1 2022-12-20 op {{ end }}
980 1abb18e1 2022-12-20 op {{ tailq-foreach rt &t->repo_tags entry }}
981 1abb18e1 2022-12-20 op {{ render rss_tag_item(tp, rt) }}
982 1abb18e1 2022-12-20 op {{ end }}
983 1abb18e1 2022-12-20 op </channel>
984 1abb18e1 2022-12-20 op </rss>
985 1abb18e1 2022-12-20 op {{ end }}
986 1abb18e1 2022-12-20 op
987 1abb18e1 2022-12-20 op {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
988 1abb18e1 2022-12-20 op {!
989 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
990 1abb18e1 2022-12-20 op struct transport *t = c->t;
991 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
992 1abb18e1 2022-12-20 op char *tag_name = rt->tag_name;
993 1abb18e1 2022-12-20 op struct gotweb_url tag = {
994 1abb18e1 2022-12-20 op .action = TAG,
995 1abb18e1 2022-12-20 op .index_page = -1,
996 1abb18e1 2022-12-20 op .page = -1,
997 1abb18e1 2022-12-20 op .path = repo_dir->name,
998 1abb18e1 2022-12-20 op .commit = rt->commit_id,
999 1abb18e1 2022-12-20 op };
1000 1abb18e1 2022-12-20 op
1001 1abb18e1 2022-12-20 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
1002 1abb18e1 2022-12-20 op tag_name += 10;
1003 1abb18e1 2022-12-20 op !}
1004 1abb18e1 2022-12-20 op <item>
1005 1abb18e1 2022-12-20 op <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1006 1abb18e1 2022-12-20 op <link>
1007 1abb18e1 2022-12-20 op <![CDATA[
1008 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &tag) }}
1009 1abb18e1 2022-12-20 op ]]>
1010 1abb18e1 2022-12-20 op </link>
1011 1abb18e1 2022-12-20 op <description>
1012 1abb18e1 2022-12-20 op <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1013 1abb18e1 2022-12-20 op </description>
1014 1abb18e1 2022-12-20 op {{ render rss_author(tp, rt->tagger) }}
1015 1abb18e1 2022-12-20 op <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1016 1abb18e1 2022-12-20 op <pubDate>
1017 1abb18e1 2022-12-20 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
1018 1abb18e1 2022-12-20 op </pubDate>
1019 1abb18e1 2022-12-20 op </item>
1020 156a1144 2022-12-17 op {{ end }}
1021 1abb18e1 2022-12-20 op
1022 1abb18e1 2022-12-20 op {{ define rss_author(struct template *tp, char *author) }}
1023 1abb18e1 2022-12-20 op {!
1024 1abb18e1 2022-12-20 op char *t, *mail;
1025 1abb18e1 2022-12-20 op
1026 1abb18e1 2022-12-20 op /* what to do if the author name contains a paren? */
1027 1abb18e1 2022-12-20 op if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1028 1abb18e1 2022-12-20 op return 0;
1029 1abb18e1 2022-12-20 op
1030 1abb18e1 2022-12-20 op t = strchr(author, '<');
1031 1abb18e1 2022-12-20 op if (t == NULL)
1032 1abb18e1 2022-12-20 op return 0;
1033 1abb18e1 2022-12-20 op *t = '\0';
1034 1abb18e1 2022-12-20 op mail = t+1;
1035 1abb18e1 2022-12-20 op
1036 1abb18e1 2022-12-20 op while (isspace((unsigned char)*--t))
1037 1abb18e1 2022-12-20 op *t = '\0';
1038 1abb18e1 2022-12-20 op
1039 1abb18e1 2022-12-20 op t = strchr(mail, '>');
1040 1abb18e1 2022-12-20 op if (t == NULL)
1041 1abb18e1 2022-12-20 op return 0;
1042 1abb18e1 2022-12-20 op *t = '\0';
1043 1abb18e1 2022-12-20 op !}
1044 1abb18e1 2022-12-20 op <author>
1045 1abb18e1 2022-12-20 op {{ mail }} {{" "}} ({{ author }})
1046 1abb18e1 2022-12-20 op </author>
1047 1abb18e1 2022-12-20 op {{ end }}