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>
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.
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.
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>
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 ed619ca0 2022-12-14 op #include <imsg.h>
32 43d421de 2023-01-05 op #include "got_object.h"
34 ed619ca0 2022-12-14 op #include "proc.h"
36 ed619ca0 2022-12-14 op #include "gotwebd.h"
37 ed619ca0 2022-12-14 op #include "tmpl.h"
39 298f95fb 2023-01-05 op static int gotweb_render_blob_line(struct template *, const char *, size_t);
40 43d421de 2023-01-05 op static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
42 587550a5 2023-01-10 op static inline int diff_line(struct template *, char *);
43 067396e6 2023-01-09 op static inline int tag_item(struct template *, struct repo_tag *);
44 1abb18e1 2022-12-20 op static inline int rss_tag_item(struct template *, struct repo_tag *);
45 1abb18e1 2022-12-20 op static inline int rss_author(struct template *, char *);
48 ed619ca0 2022-12-14 op gotweb_render_age(struct template *tp, time_t time, int ref_tm)
50 ed619ca0 2022-12-14 op const struct got_error *err;
54 ed619ca0 2022-12-14 op err = gotweb_get_time_str(&age, time, ref_tm);
57 ed619ca0 2022-12-14 op r = tp->tp_puts(tp, age);
64 ed619ca0 2022-12-14 op {{ define gotweb_render_header(struct template *tp) }}
66 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
67 ed619ca0 2022-12-14 op struct server *srv = c->srv;
68 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
69 ed619ca0 2022-12-14 op struct gotweb_url u_path;
70 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
71 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
73 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
74 ed619ca0 2022-12-14 op u_path.index_page = -1;
75 ed619ca0 2022-12-14 op u_path.page = -1;
76 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
78 ed619ca0 2022-12-14 op <!doctype html>
81 ed619ca0 2022-12-14 op <meta charset="utf-8" />
82 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
83 ed619ca0 2022-12-14 op <meta name="viewport" content="initial-scale=.75" />
84 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
85 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
86 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
87 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
88 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
89 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
90 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
91 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
94 ed619ca0 2022-12-14 op <div id="gw_body">
95 ed619ca0 2022-12-14 op <div id="header">
96 ed619ca0 2022-12-14 op <div id="got_link">
97 ed619ca0 2022-12-14 op <a href="{{ srv->logo_url }}" target="_blank">
98 ed619ca0 2022-12-14 op <img src="{{ prfx }}{{ srv->logo }}" />
102 ed619ca0 2022-12-14 op <div id="site_path">
103 ed619ca0 2022-12-14 op <div id="site_link">
104 ed619ca0 2022-12-14 op <a href="?index_page={{ printf "%d", qs->index_page }}">
105 ed619ca0 2022-12-14 op {{ srv->site_link }}
107 ed619ca0 2022-12-14 op {{ if qs->path }}
108 ed619ca0 2022-12-14 op {! u_path.path = qs->path; !}
110 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
111 ed619ca0 2022-12-14 op {{ qs->path }}
114 ed619ca0 2022-12-14 op {{ if qs->action != INDEX }}
115 ed619ca0 2022-12-14 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
119 ed619ca0 2022-12-14 op <div id="content">
122 ed619ca0 2022-12-14 op {{ define gotweb_render_footer(struct template *tp) }}
124 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
125 ed619ca0 2022-12-14 op struct server *srv = c->srv;
127 ed619ca0 2022-12-14 op <div id="site_owner_wrapper">
128 ed619ca0 2022-12-14 op <div id="site_owner">
129 ed619ca0 2022-12-14 op {{ if srv->show_site_owner }}
130 ed619ca0 2022-12-14 op {{ srv->site_owner }}
140 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
142 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
143 ed619ca0 2022-12-14 op struct server *srv = c->srv;
145 ed619ca0 2022-12-14 op <div id="index_header">
146 ed619ca0 2022-12-14 op <div id="index_header_project">
149 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
150 ed619ca0 2022-12-14 op <div id="index_header_description">
154 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
155 ed619ca0 2022-12-14 op <div id="index_header_owner">
159 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
160 ed619ca0 2022-12-14 op <div id="index_header_age">
167 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
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,
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,
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,
185 ed619ca0 2022-12-14 op .path = repo_dir->name,
187 ed619ca0 2022-12-14 op .action = TAGS,
188 ed619ca0 2022-12-14 op .index_page = -1,
190 ed619ca0 2022-12-14 op .path = repo_dir->name,
192 ed619ca0 2022-12-14 op .action = TREE,
193 ed619ca0 2022-12-14 op .index_page = -1,
195 ed619ca0 2022-12-14 op .path = repo_dir->name,
197 1abb18e1 2022-12-20 op .action = RSS,
198 1abb18e1 2022-12-20 op .index_page = -1,
200 1abb18e1 2022-12-20 op .path = repo_dir->name,
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>
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 }}
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 }}
217 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
218 ed619ca0 2022-12-14 op <div class="index_project_age">
219 ed619ca0 2022-12-14 op {{ repo_dir->age }}
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>
226 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
228 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
230 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
232 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
234 1abb18e1 2022-12-20 op <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
236 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
241 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
243 ed619ca0 2022-12-14 op const struct got_error *error;
244 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
245 ed619ca0 2022-12-14 op struct server *srv = c->srv;
246 ed619ca0 2022-12-14 op struct transport *t = c->t;
247 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
248 ed619ca0 2022-12-14 op struct repo_commit *rc;
249 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
250 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
253 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
254 ed619ca0 2022-12-14 op .action = DIFF,
255 ed619ca0 2022-12-14 op .index_page = -1,
257 ed619ca0 2022-12-14 op .path = repo_dir->name,
258 ed619ca0 2022-12-14 op .headref = qs->headref,
260 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
261 ed619ca0 2022-12-14 op .action = TREE,
262 ed619ca0 2022-12-14 op .index_page = -1,
264 ed619ca0 2022-12-14 op .path = repo_dir->name,
265 ed619ca0 2022-12-14 op .headref = qs->headref,
268 ed619ca0 2022-12-14 op if (qs->action == SUMMARY) {
269 ed619ca0 2022-12-14 op qs->action = BRIEFS;
270 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
272 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, srv->max_commits_display);
276 ed619ca0 2022-12-14 op <div id="briefs_title_wrapper">
277 ed619ca0 2022-12-14 op <div id="briefs_title">Commit Briefs</div>
279 ed619ca0 2022-12-14 op <div id="briefs_content">
280 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
282 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
283 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
285 6c3d3263 2023-01-10 op tmp = strchr(rc->committer, '<');
289 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
293 ed619ca0 2022-12-14 op <div class="briefs_age">
294 ed619ca0 2022-12-14 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
296 ed619ca0 2022-12-14 op <div class="briefs_author">
297 6c3d3263 2023-01-10 op {{ rc->committer }}
299 ed619ca0 2022-12-14 op <div class="briefs_log">
300 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
301 ed619ca0 2022-12-14 op {{ rc->commit_msg }}
303 ed619ca0 2022-12-14 op {{ if rc->refs_str }}
304 ed619ca0 2022-12-14 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
308 ed619ca0 2022-12-14 op <div class="navs_wrapper">
309 ed619ca0 2022-12-14 op <div class="navs">
310 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
312 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
315 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
317 ed619ca0 2022-12-14 op {{ if t->next_id || t->prev_id }}
318 b4c0bd72 2022-12-17 op {{ render gotweb_render_navs(tp) }}
323 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
325 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
326 b4c0bd72 2022-12-17 op struct transport *t = c->t;
327 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
328 b4c0bd72 2022-12-17 op int have_prev, have_next;
330 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
332 b4c0bd72 2022-12-17 op <div id="np_wrapper">
333 b4c0bd72 2022-12-17 op <div id="nav_prev">
334 b4c0bd72 2022-12-17 op {{ if have_prev }}
335 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
340 b4c0bd72 2022-12-17 op <div id="nav_next">
341 b4c0bd72 2022-12-17 op {{ if have_next }}
342 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
348 b4c0bd72 2022-12-17 op {{ finally }}
350 b4c0bd72 2022-12-17 op free(t->next_id);
351 b4c0bd72 2022-12-17 op t->next_id = NULL;
352 b4c0bd72 2022-12-17 op free(t->prev_id);
353 b4c0bd72 2022-12-17 op t->prev_id = NULL;
357 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
359 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
360 156a1144 2022-12-17 op struct transport *t = c->t;
361 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
362 156a1144 2022-12-17 op struct repo_commit *rc;
363 156a1144 2022-12-17 op struct gotweb_url diff, tree;
365 156a1144 2022-12-17 op diff = (struct gotweb_url){
366 156a1144 2022-12-17 op .action = DIFF,
367 156a1144 2022-12-17 op .index_page = -1,
369 156a1144 2022-12-17 op .path = repo_dir->name,
371 156a1144 2022-12-17 op tree = (struct gotweb_url){
372 156a1144 2022-12-17 op .action = TREE,
373 156a1144 2022-12-17 op .index_page = -1,
375 156a1144 2022-12-17 op .path = repo_dir->name,
378 156a1144 2022-12-17 op <div class="commits_title_wrapper">
379 156a1144 2022-12-17 op <div class="commits_title">Commits</div>
381 156a1144 2022-12-17 op <div class="commits_content">
382 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
384 156a1144 2022-12-17 op diff.commit = rc->commit_id;
385 156a1144 2022-12-17 op tree.commit = rc->commit_id;
387 156a1144 2022-12-17 op <div class="commits_header_wrapper">
388 156a1144 2022-12-17 op <div class="commits_header">
389 156a1144 2022-12-17 op <div class="header_commit_title">Commit:</div>
390 156a1144 2022-12-17 op <div class="header_commit">{{ rc->commit_id }}</div>
391 af800df5 2023-01-10 op <div class="header_author_title">From:</div>
392 156a1144 2022-12-17 op <div class="header_author">{{ rc->author }}</div>
393 af800df5 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
394 af800df5 2023-01-10 op <div class="header_author_title">Via:</div>
395 af800df5 2023-01-10 op <div class="header_author">{{ rc->committer }}</div>
397 156a1144 2022-12-17 op <div class="header_age_title">Date:</div>
398 156a1144 2022-12-17 op <div class="header_age">
399 156a1144 2022-12-17 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
403 cf536071 2022-12-31 op <div class="dotted_line"></div>
404 cf536071 2022-12-31 op <div class="commit">
406 cf536071 2022-12-31 op {{ rc->commit_msg }}
408 156a1144 2022-12-17 op <div class="navs_wrapper">
409 156a1144 2022-12-17 op <div class="navs">
410 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
412 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
415 156a1144 2022-12-17 op <div class="dotted_line"></div>
417 156a1144 2022-12-17 op {{ if t->next_id || t->prev_id }}
418 156a1144 2022-12-17 op {{ render gotweb_render_navs(tp) }}
423 298f95fb 2023-01-05 op {{ define gotweb_render_blob(struct template *tp,
424 298f95fb 2023-01-05 op struct got_blob_object *blob) }}
426 298f95fb 2023-01-05 op struct request *c = tp->tp_arg;
427 298f95fb 2023-01-05 op struct transport *t = c->t;
428 298f95fb 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
430 298f95fb 2023-01-05 op <div id="blob_title_wrapper">
431 298f95fb 2023-01-05 op <div id="blob_title">Blob</div>
433 298f95fb 2023-01-05 op <div id="blob_content">
434 298f95fb 2023-01-05 op <div id="blob_header_wrapper">
435 298f95fb 2023-01-05 op <div id="blob_header">
436 298f95fb 2023-01-05 op <div class="header_age_title">Date:</div>
437 298f95fb 2023-01-05 op <div class="header_age">
438 298f95fb 2023-01-05 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
440 298f95fb 2023-01-05 op <div id="header_commit_msg_title">Message:</div>
441 298f95fb 2023-01-05 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
444 298f95fb 2023-01-05 op <div class="dotted_line"></div>
445 298f95fb 2023-01-05 op <div id="blob">
447 298f95fb 2023-01-05 op {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
453 298f95fb 2023-01-05 op {{ define gotweb_render_blob_line(struct template *tp, const char *line,
454 298f95fb 2023-01-05 op size_t no) }}
456 298f95fb 2023-01-05 op char lineno[16];
459 298f95fb 2023-01-05 op r = snprintf(lineno, sizeof(lineno), "%zu", no);
460 298f95fb 2023-01-05 op if (r < 0 || (size_t)r >= sizeof(lineno))
463 298f95fb 2023-01-05 op <div class="blob_line" id="line{{ lineno }}">
464 298f95fb 2023-01-05 op <div class="blob_number">
465 298f95fb 2023-01-05 op <a href="#line{{ lineno }}">{{ lineno }}</a>
467 298f95fb 2023-01-05 op <div class="blob_code">{{ line }}</div>
471 43d421de 2023-01-05 op {{ define gotweb_render_tree(struct template *tp) }}
473 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
474 43d421de 2023-01-05 op struct transport *t = c->t;
475 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
477 43d421de 2023-01-05 op <div id="tree_title_wrapper">
478 43d421de 2023-01-05 op <div id="tree_title">Tree</div>
480 43d421de 2023-01-05 op <div id="tree_content">
481 43d421de 2023-01-05 op <div id="tree_header_wrapper">
482 43d421de 2023-01-05 op <div id="tree_header">
483 43d421de 2023-01-05 op <div id="header_tree_title">Tree:</div>
484 43d421de 2023-01-05 op <div id="header_tree">{{ rc->tree_id }}</div>
485 43d421de 2023-01-05 op <div class="header_age_title">Date:</div>
486 43d421de 2023-01-05 op <div class="header_age">
487 43d421de 2023-01-05 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
489 43d421de 2023-01-05 op <div id="header_commit_msg_title">Message:</div>
490 43d421de 2023-01-05 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
493 43d421de 2023-01-05 op <div class="dotted_line"></div>
494 43d421de 2023-01-05 op <div id="tree">
495 43d421de 2023-01-05 op {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
500 43d421de 2023-01-05 op {{ define gotweb_render_tree_item(struct template *tp,
501 43d421de 2023-01-05 op struct got_tree_entry *te) }}
503 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
504 43d421de 2023-01-05 op struct transport *t = c->t;
505 43d421de 2023-01-05 op struct querystring *qs = t->qs;
506 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
507 43d421de 2023-01-05 op const char *modestr = "";
508 43d421de 2023-01-05 op const char *name;
509 43d421de 2023-01-05 op const char *folder;
510 43d421de 2023-01-05 op char *dir = NULL;
512 43d421de 2023-01-05 op struct gotweb_url url = {
513 43d421de 2023-01-05 op .index_page = -1,
515 43d421de 2023-01-05 op .commit = rc->commit_id,
516 43d421de 2023-01-05 op .path = qs->path,
519 43d421de 2023-01-05 op name = got_tree_entry_get_name(te);
520 43d421de 2023-01-05 op mode = got_tree_entry_get_mode(te);
522 43d421de 2023-01-05 op folder = qs->folder ? qs->folder : "";
523 43d421de 2023-01-05 op if (S_ISDIR(mode)) {
524 43d421de 2023-01-05 op if (asprintf(&dir, "%s/%s", folder, name) == -1)
527 43d421de 2023-01-05 op url.action = TREE;
528 43d421de 2023-01-05 op url.folder = dir;
530 43d421de 2023-01-05 op url.action = BLOB;
531 43d421de 2023-01-05 op url.folder = folder;
532 43d421de 2023-01-05 op url.file = name;
535 43d421de 2023-01-05 op if (got_object_tree_entry_is_submodule(te))
536 43d421de 2023-01-05 op modestr = "$";
537 43d421de 2023-01-05 op else if (S_ISLNK(mode))
538 43d421de 2023-01-05 op modestr = "@";
539 43d421de 2023-01-05 op else if (S_ISDIR(mode))
540 43d421de 2023-01-05 op modestr = "/";
541 43d421de 2023-01-05 op else if (mode & S_IXUSR)
542 43d421de 2023-01-05 op modestr = "*";
544 43d421de 2023-01-05 op <div class="tree_wrapper">
545 43d421de 2023-01-05 op {{ if S_ISDIR(mode) }}
546 43d421de 2023-01-05 op <div class="tree_line">
547 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
548 43d421de 2023-01-05 op {{ name }}{{ modestr }}
551 43d421de 2023-01-05 op <div class="tree_line_blank"> </div>
553 43d421de 2023-01-05 op <div class="tree_line">
554 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
555 43d421de 2023-01-05 op {{ name }}{{ modestr }}
558 43d421de 2023-01-05 op <div class="tree_line_blank">
559 43d421de 2023-01-05 op {! url.action = COMMITS; !}
560 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
564 43d421de 2023-01-05 op {! url.action = BLAME; !}
565 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
571 43d421de 2023-01-05 op {{ finally }}
577 067396e6 2023-01-09 op {{ define gotweb_render_tags_tmpl(struct template *tp) }}
579 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
580 067396e6 2023-01-09 op struct transport *t = c->t;
581 067396e6 2023-01-09 op struct querystring *qs = t->qs;
582 067396e6 2023-01-09 op struct repo_tag *rt;
583 067396e6 2023-01-09 op int commit_found;
585 067396e6 2023-01-09 op commit_found = qs->commit == NULL;
587 067396e6 2023-01-09 op <div id="tags_title_wrapper">
588 067396e6 2023-01-09 op <div id="tags_title">Tags</div>
590 067396e6 2023-01-09 op <div id="tags_content">
591 067396e6 2023-01-09 op {{ if t->tag_count == 0 }}
592 067396e6 2023-01-09 op <div id="err_content">
593 067396e6 2023-01-09 op This repository contains no tags
596 067396e6 2023-01-09 op {{ tailq-foreach rt &t->repo_tags entry }}
597 067396e6 2023-01-09 op {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
598 067396e6 2023-01-09 op {! commit_found = 1; !}
599 067396e6 2023-01-09 op {{ render tag_item(tp, rt) }}
602 067396e6 2023-01-09 op {{ if t->next_id || t->prev_id }}
603 067396e6 2023-01-09 op {{ render gotweb_render_navs(tp) }}
609 067396e6 2023-01-09 op {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
611 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
612 067396e6 2023-01-09 op struct transport *t = c->t;
613 067396e6 2023-01-09 op struct repo_dir *repo_dir = t->repo_dir;
614 067396e6 2023-01-09 op char *tag_name = rt->tag_name;
615 067396e6 2023-01-09 op char *msg = rt->tag_commit;
617 067396e6 2023-01-09 op struct gotweb_url url = {
618 067396e6 2023-01-09 op .action = TAG,
619 067396e6 2023-01-09 op .index_page = -1,
621 067396e6 2023-01-09 op .path = repo_dir->name,
622 067396e6 2023-01-09 op .commit = rt->commit_id,
625 067396e6 2023-01-09 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
626 067396e6 2023-01-09 op tag_name += 10;
629 067396e6 2023-01-09 op nl = strchr(msg, '\n');
634 067396e6 2023-01-09 op <div class="tag_age">
635 067396e6 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
637 067396e6 2023-01-09 op <div class="tag">{{ tag_name }}</div>
638 067396e6 2023-01-09 op <div class="tag_log">
639 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">
643 067396e6 2023-01-09 op <div class="navs_wrapper">
644 067396e6 2023-01-09 op <div class="navs">
645 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
647 067396e6 2023-01-09 op {! url.action = BRIEFS; !}
648 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
650 067396e6 2023-01-09 op {! url.action = COMMITS; !}
651 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
654 067396e6 2023-01-09 op <div class="dotted_line"></div>
657 dc07f76c 2023-01-09 op {{ define gotweb_render_tag(struct template *tp) }}
659 dc07f76c 2023-01-09 op struct request *c = tp->tp_arg;
660 dc07f76c 2023-01-09 op struct transport *t = c->t;
661 dc07f76c 2023-01-09 op struct repo_tag *rt;
662 dc07f76c 2023-01-09 op const char *tag_name;
664 dc07f76c 2023-01-09 op rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
665 dc07f76c 2023-01-09 op tag_name = rt->tag_name;
667 dc07f76c 2023-01-09 op if (strncmp(tag_name, "refs/", 5) == 0)
668 dc07f76c 2023-01-09 op tag_name += 5;
670 dc07f76c 2023-01-09 op <div id="tags_title_wrapper">
671 dc07f76c 2023-01-09 op <div id="tags_title">Tag</div>
673 dc07f76c 2023-01-09 op <div id="tags_content">
674 dc07f76c 2023-01-09 op <div id="tag_header_wrapper">
675 dc07f76c 2023-01-09 op <div id="tag_header">
676 dc07f76c 2023-01-09 op <div class="header_commit_title">Commit:</div>
677 dc07f76c 2023-01-09 op <div class="header_commit">
678 dc07f76c 2023-01-09 op {{ rt->commit_id }}
680 dc07f76c 2023-01-09 op <span class="refs_str">({{ tag_name }})</span>
682 dc07f76c 2023-01-09 op <div class="header_author_title">Tagger:</div>
683 dc07f76c 2023-01-09 op <div class="header_author">{{ rt->tagger }}</div>
684 dc07f76c 2023-01-09 op <div class="header_age_title">Date:</div>
685 dc07f76c 2023-01-09 op <div class="header_age">
686 dc07f76c 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
688 dc07f76c 2023-01-09 op <div id="header_commit_msg_title">Message:</div>
689 dc07f76c 2023-01-09 op <div id="header_commit_msg">{{ rt->commit_msg }}</div>
691 dc07f76c 2023-01-09 op <div class="dotted_line"></div>
692 dc07f76c 2023-01-09 op <div id="tag_commit">
694 dc07f76c 2023-01-09 op {{ rt->tag_commit }}
700 587550a5 2023-01-10 op {{ define gotweb_render_diff(struct template *tp, FILE *fp) }}
702 587550a5 2023-01-10 op struct request *c = tp->tp_arg;
703 587550a5 2023-01-10 op struct transport *t = c->t;
704 587550a5 2023-01-10 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
705 587550a5 2023-01-10 op char *line = NULL;
706 587550a5 2023-01-10 op size_t linesize = 0;
707 587550a5 2023-01-10 op ssize_t linelen;
709 587550a5 2023-01-10 op <div id="diff_title_wrapper">
710 587550a5 2023-01-10 op <div id="diff_title">Commit Diff</div>
712 587550a5 2023-01-10 op <div id="diff_content">
713 587550a5 2023-01-10 op <div id="diff_header_wrapper">
714 587550a5 2023-01-10 op <div id="diff_header">
715 587550a5 2023-01-10 op <div class="header_commit_title">Commit:</div>
716 587550a5 2023-01-10 op <div class="header_commit">{{ rc->commit_id }}</div>
717 49632cd3 2023-01-10 op <div class="header_author_title">From:</div>
718 587550a5 2023-01-10 op <div class="header_author">{{ rc->author }}</div>
719 49632cd3 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
720 49632cd3 2023-01-10 op <div class="header_author_title">Via:</div>
721 49632cd3 2023-01-10 op <div class="header_author">{{ rc->committer }}</div>
723 587550a5 2023-01-10 op <div class="header_age_title">Date:</div>
724 587550a5 2023-01-10 op <div class="header_age">
725 587550a5 2023-01-10 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
727 587550a5 2023-01-10 op <div id="header_commit_msg_title">Message</div>
728 587550a5 2023-01-10 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
731 587550a5 2023-01-10 op <div class="dotted_line"></div>
732 587550a5 2023-01-10 op <div id="diff">
734 587550a5 2023-01-10 op {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
735 587550a5 2023-01-10 op {{ render diff_line(tp, line) }}
739 587550a5 2023-01-10 op {{ finally }}
740 587550a5 2023-01-10 op {! free(line); !}
743 587550a5 2023-01-10 op {{ define diff_line(struct template *tp, char *line )}}
745 587550a5 2023-01-10 op const char *color = NULL;
748 587550a5 2023-01-10 op if (!strncmp(line, "-", 1))
749 587550a5 2023-01-10 op color = "diff_minus";
750 587550a5 2023-01-10 op else if (!strncmp(line, "+", 1))
751 587550a5 2023-01-10 op color = "diff_plus";
752 587550a5 2023-01-10 op else if (!strncmp(line, "@@", 2))
753 587550a5 2023-01-10 op color = "diff_chunk_header";
754 587550a5 2023-01-10 op else if (!strncmp(line, "commit +", 8) ||
755 587550a5 2023-01-10 op !strncmp(line, "commit -", 8) ||
756 587550a5 2023-01-10 op !strncmp(line, "blob +", 6) ||
757 587550a5 2023-01-10 op !strncmp(line, "blob -", 6) ||
758 587550a5 2023-01-10 op !strncmp(line, "file +", 6) ||
759 587550a5 2023-01-10 op !strncmp(line, "file -", 6))
760 587550a5 2023-01-10 op color = "diff_meta";
761 587550a5 2023-01-10 op else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
762 587550a5 2023-01-10 op color = "diff_author";
763 587550a5 2023-01-10 op else if (!strncmp(line, "date:", 5))
764 587550a5 2023-01-10 op color = "diff_date";
766 587550a5 2023-01-10 op nl = strchr(line, '\n');
770 587550a5 2023-01-10 op <div class="diff_line {{ color }}">{{ line }}</div>
773 1abb18e1 2022-12-20 op {{ define gotweb_render_rss(struct template *tp) }}
775 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
776 1abb18e1 2022-12-20 op struct server *srv = c->srv;
777 1abb18e1 2022-12-20 op struct transport *t = c->t;
778 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
779 1abb18e1 2022-12-20 op struct repo_tag *rt;
780 1abb18e1 2022-12-20 op struct gotweb_url summary = {
781 1abb18e1 2022-12-20 op .action = SUMMARY,
782 1abb18e1 2022-12-20 op .index_page = -1,
784 1abb18e1 2022-12-20 op .path = repo_dir->name,
787 1abb18e1 2022-12-20 op <?xml version="1.0" encoding="UTF-8"?>
788 1abb18e1 2022-12-20 op <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
790 1abb18e1 2022-12-20 op <title>Tags of {{ repo_dir->name }}</title>
793 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &summary) }}
796 1abb18e1 2022-12-20 op {{ if srv->show_repo_description }}
797 1abb18e1 2022-12-20 op <description>{{ repo_dir->description }}</description>
799 1abb18e1 2022-12-20 op {{ tailq-foreach rt &t->repo_tags entry }}
800 1abb18e1 2022-12-20 op {{ render rss_tag_item(tp, rt) }}
806 1abb18e1 2022-12-20 op {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
808 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
809 1abb18e1 2022-12-20 op struct transport *t = c->t;
810 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
811 1abb18e1 2022-12-20 op char *tag_name = rt->tag_name;
812 1abb18e1 2022-12-20 op struct gotweb_url tag = {
813 1abb18e1 2022-12-20 op .action = TAG,
814 1abb18e1 2022-12-20 op .index_page = -1,
816 1abb18e1 2022-12-20 op .path = repo_dir->name,
817 1abb18e1 2022-12-20 op .commit = rt->commit_id,
820 1abb18e1 2022-12-20 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
821 1abb18e1 2022-12-20 op tag_name += 10;
824 1abb18e1 2022-12-20 op <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
827 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &tag) }}
830 1abb18e1 2022-12-20 op <description>
831 1abb18e1 2022-12-20 op <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
832 1abb18e1 2022-12-20 op </description>
833 1abb18e1 2022-12-20 op {{ render rss_author(tp, rt->tagger) }}
834 1abb18e1 2022-12-20 op <guid isPermaLink="false">{{ rt->commit_id }}</guid>
836 1abb18e1 2022-12-20 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
841 1abb18e1 2022-12-20 op {{ define rss_author(struct template *tp, char *author) }}
843 1abb18e1 2022-12-20 op char *t, *mail;
845 1abb18e1 2022-12-20 op /* what to do if the author name contains a paren? */
846 1abb18e1 2022-12-20 op if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
849 1abb18e1 2022-12-20 op t = strchr(author, '<');
850 1abb18e1 2022-12-20 op if (t == NULL)
855 1abb18e1 2022-12-20 op while (isspace((unsigned char)*--t))
858 1abb18e1 2022-12-20 op t = strchr(mail, '>');
859 1abb18e1 2022-12-20 op if (t == NULL)
864 1abb18e1 2022-12-20 op {{ mail }} {{" "}} ({{ author }})