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 3ab2c914 2023-01-11 op #include "got_error.h"
33 43d421de 2023-01-05 op #include "got_object.h"
34 3ab2c914 2023-01-11 op #include "got_reference.h"
36 ed619ca0 2022-12-14 op #include "proc.h"
38 ed619ca0 2022-12-14 op #include "gotwebd.h"
39 ed619ca0 2022-12-14 op #include "tmpl.h"
41 298f95fb 2023-01-05 op static int gotweb_render_blob_line(struct template *, const char *, size_t);
42 43d421de 2023-01-05 op static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
44 587550a5 2023-01-10 op static inline int diff_line(struct template *, char *);
45 067396e6 2023-01-09 op static inline int tag_item(struct template *, struct repo_tag *);
46 3ab2c914 2023-01-11 op static inline int branch(struct template *, struct got_reflist_entry *);
47 1abb18e1 2022-12-20 op static inline int rss_tag_item(struct template *, struct repo_tag *);
48 1abb18e1 2022-12-20 op static inline int rss_author(struct template *, char *);
51 ed619ca0 2022-12-14 op gotweb_render_age(struct template *tp, time_t time, int ref_tm)
53 ed619ca0 2022-12-14 op const struct got_error *err;
57 ed619ca0 2022-12-14 op err = gotweb_get_time_str(&age, time, ref_tm);
60 ed619ca0 2022-12-14 op r = tp->tp_puts(tp, age);
67 ed619ca0 2022-12-14 op {{ define gotweb_render_header(struct template *tp) }}
69 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
70 ed619ca0 2022-12-14 op struct server *srv = c->srv;
71 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
72 ed619ca0 2022-12-14 op struct gotweb_url u_path;
73 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
74 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
76 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
77 ed619ca0 2022-12-14 op u_path.index_page = -1;
78 ed619ca0 2022-12-14 op u_path.page = -1;
79 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
81 ed619ca0 2022-12-14 op <!doctype html>
84 ed619ca0 2022-12-14 op <meta charset="utf-8" />
85 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
86 ed619ca0 2022-12-14 op <meta name="viewport" content="initial-scale=.75" />
87 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
88 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
89 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
90 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
91 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
92 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
93 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
94 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
97 ed619ca0 2022-12-14 op <div id="gw_body">
98 ed619ca0 2022-12-14 op <div id="header">
99 ed619ca0 2022-12-14 op <div id="got_link">
100 ed619ca0 2022-12-14 op <a href="{{ srv->logo_url }}" target="_blank">
101 ed619ca0 2022-12-14 op <img src="{{ prfx }}{{ srv->logo }}" />
105 ed619ca0 2022-12-14 op <div id="site_path">
106 ed619ca0 2022-12-14 op <div id="site_link">
107 ed619ca0 2022-12-14 op <a href="?index_page={{ printf "%d", qs->index_page }}">
108 ed619ca0 2022-12-14 op {{ srv->site_link }}
110 ed619ca0 2022-12-14 op {{ if qs->path }}
111 ed619ca0 2022-12-14 op {! u_path.path = qs->path; !}
113 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
114 ed619ca0 2022-12-14 op {{ qs->path }}
117 ed619ca0 2022-12-14 op {{ if qs->action != INDEX }}
118 ed619ca0 2022-12-14 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
122 ed619ca0 2022-12-14 op <div id="content">
125 ed619ca0 2022-12-14 op {{ define gotweb_render_footer(struct template *tp) }}
127 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
128 ed619ca0 2022-12-14 op struct server *srv = c->srv;
130 ed619ca0 2022-12-14 op <div id="site_owner_wrapper">
131 ed619ca0 2022-12-14 op <div id="site_owner">
132 ed619ca0 2022-12-14 op {{ if srv->show_site_owner }}
133 ed619ca0 2022-12-14 op {{ srv->site_owner }}
143 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
145 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
146 ed619ca0 2022-12-14 op struct server *srv = c->srv;
148 ed619ca0 2022-12-14 op <div id="index_header">
149 ed619ca0 2022-12-14 op <div id="index_header_project">
152 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
153 ed619ca0 2022-12-14 op <div id="index_header_description">
157 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
158 ed619ca0 2022-12-14 op <div id="index_header_owner">
162 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
163 ed619ca0 2022-12-14 op <div id="index_header_age">
170 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
172 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
173 ed619ca0 2022-12-14 op struct server *srv = c->srv;
174 ed619ca0 2022-12-14 op struct gotweb_url summary = {
175 ed619ca0 2022-12-14 op .action = SUMMARY,
176 ed619ca0 2022-12-14 op .index_page = -1,
178 ed619ca0 2022-12-14 op .path = repo_dir->name,
179 ed619ca0 2022-12-14 op }, briefs = {
180 ed619ca0 2022-12-14 op .action = BRIEFS,
181 ed619ca0 2022-12-14 op .index_page = -1,
183 ed619ca0 2022-12-14 op .path = repo_dir->name,
184 ed619ca0 2022-12-14 op }, commits = {
185 ed619ca0 2022-12-14 op .action = COMMITS,
186 ed619ca0 2022-12-14 op .index_page = -1,
188 ed619ca0 2022-12-14 op .path = repo_dir->name,
190 ed619ca0 2022-12-14 op .action = TAGS,
191 ed619ca0 2022-12-14 op .index_page = -1,
193 ed619ca0 2022-12-14 op .path = repo_dir->name,
195 ed619ca0 2022-12-14 op .action = TREE,
196 ed619ca0 2022-12-14 op .index_page = -1,
198 ed619ca0 2022-12-14 op .path = repo_dir->name,
200 1abb18e1 2022-12-20 op .action = RSS,
201 1abb18e1 2022-12-20 op .index_page = -1,
203 1abb18e1 2022-12-20 op .path = repo_dir->name,
206 ed619ca0 2022-12-14 op <div class="index_wrapper">
207 ed619ca0 2022-12-14 op <div class="index_project">
208 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
210 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
211 ed619ca0 2022-12-14 op <div class="index_project_description">
212 ed619ca0 2022-12-14 op {{ repo_dir->description }}
215 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
216 ed619ca0 2022-12-14 op <div class="index_project_owner">
217 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
220 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
221 ed619ca0 2022-12-14 op <div class="index_project_age">
222 ed619ca0 2022-12-14 op {{ repo_dir->age }}
225 ed619ca0 2022-12-14 op <div class="navs_wrapper">
226 ed619ca0 2022-12-14 op <div class="navs">
227 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
229 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
231 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
233 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
235 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
237 1abb18e1 2022-12-20 op <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
239 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
244 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
246 ed619ca0 2022-12-14 op const struct got_error *error;
247 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
248 ed619ca0 2022-12-14 op struct server *srv = c->srv;
249 ed619ca0 2022-12-14 op struct transport *t = c->t;
250 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
251 ed619ca0 2022-12-14 op struct repo_commit *rc;
252 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
253 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
256 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
257 ed619ca0 2022-12-14 op .action = DIFF,
258 ed619ca0 2022-12-14 op .index_page = -1,
260 ed619ca0 2022-12-14 op .path = repo_dir->name,
261 ed619ca0 2022-12-14 op .headref = qs->headref,
263 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
264 ed619ca0 2022-12-14 op .action = TREE,
265 ed619ca0 2022-12-14 op .index_page = -1,
267 ed619ca0 2022-12-14 op .path = repo_dir->name,
268 ed619ca0 2022-12-14 op .headref = qs->headref,
271 ed619ca0 2022-12-14 op if (qs->action == SUMMARY) {
272 ed619ca0 2022-12-14 op qs->action = BRIEFS;
273 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
275 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, srv->max_commits_display);
279 ed619ca0 2022-12-14 op <div id="briefs_title_wrapper">
280 ed619ca0 2022-12-14 op <div id="briefs_title">Commit Briefs</div>
282 ed619ca0 2022-12-14 op <div id="briefs_content">
283 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
285 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
286 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
288 6c3d3263 2023-01-10 op tmp = strchr(rc->committer, '<');
292 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
296 ed619ca0 2022-12-14 op <div class="briefs_age">
297 ed619ca0 2022-12-14 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
299 ed619ca0 2022-12-14 op <div class="briefs_author">
300 6c3d3263 2023-01-10 op {{ rc->committer }}
302 ed619ca0 2022-12-14 op <div class="briefs_log">
303 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
304 ed619ca0 2022-12-14 op {{ rc->commit_msg }}
306 ed619ca0 2022-12-14 op {{ if rc->refs_str }}
307 ed619ca0 2022-12-14 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
311 ed619ca0 2022-12-14 op <div class="navs_wrapper">
312 ed619ca0 2022-12-14 op <div class="navs">
313 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
315 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
318 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
320 ed619ca0 2022-12-14 op {{ if t->next_id || t->prev_id }}
321 b4c0bd72 2022-12-17 op {{ render gotweb_render_navs(tp) }}
326 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
328 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
329 b4c0bd72 2022-12-17 op struct transport *t = c->t;
330 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
331 b4c0bd72 2022-12-17 op int have_prev, have_next;
333 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
335 b4c0bd72 2022-12-17 op <div id="np_wrapper">
336 b4c0bd72 2022-12-17 op <div id="nav_prev">
337 b4c0bd72 2022-12-17 op {{ if have_prev }}
338 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
343 b4c0bd72 2022-12-17 op <div id="nav_next">
344 b4c0bd72 2022-12-17 op {{ if have_next }}
345 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
351 b4c0bd72 2022-12-17 op {{ finally }}
353 b4c0bd72 2022-12-17 op free(t->next_id);
354 b4c0bd72 2022-12-17 op t->next_id = NULL;
355 b4c0bd72 2022-12-17 op free(t->prev_id);
356 b4c0bd72 2022-12-17 op t->prev_id = NULL;
360 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
362 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
363 156a1144 2022-12-17 op struct transport *t = c->t;
364 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
365 156a1144 2022-12-17 op struct repo_commit *rc;
366 156a1144 2022-12-17 op struct gotweb_url diff, tree;
368 156a1144 2022-12-17 op diff = (struct gotweb_url){
369 156a1144 2022-12-17 op .action = DIFF,
370 156a1144 2022-12-17 op .index_page = -1,
372 156a1144 2022-12-17 op .path = repo_dir->name,
374 156a1144 2022-12-17 op tree = (struct gotweb_url){
375 156a1144 2022-12-17 op .action = TREE,
376 156a1144 2022-12-17 op .index_page = -1,
378 156a1144 2022-12-17 op .path = repo_dir->name,
381 156a1144 2022-12-17 op <div class="commits_title_wrapper">
382 156a1144 2022-12-17 op <div class="commits_title">Commits</div>
384 156a1144 2022-12-17 op <div class="commits_content">
385 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
387 156a1144 2022-12-17 op diff.commit = rc->commit_id;
388 156a1144 2022-12-17 op tree.commit = rc->commit_id;
390 156a1144 2022-12-17 op <div class="commits_header_wrapper">
391 156a1144 2022-12-17 op <div class="commits_header">
392 156a1144 2022-12-17 op <div class="header_commit_title">Commit:</div>
393 156a1144 2022-12-17 op <div class="header_commit">{{ rc->commit_id }}</div>
394 af800df5 2023-01-10 op <div class="header_author_title">From:</div>
395 156a1144 2022-12-17 op <div class="header_author">{{ rc->author }}</div>
396 af800df5 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
397 af800df5 2023-01-10 op <div class="header_author_title">Via:</div>
398 af800df5 2023-01-10 op <div class="header_author">{{ rc->committer }}</div>
400 156a1144 2022-12-17 op <div class="header_age_title">Date:</div>
401 156a1144 2022-12-17 op <div class="header_age">
402 156a1144 2022-12-17 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
406 cf536071 2022-12-31 op <div class="dotted_line"></div>
407 cf536071 2022-12-31 op <div class="commit">
409 cf536071 2022-12-31 op {{ rc->commit_msg }}
411 156a1144 2022-12-17 op <div class="navs_wrapper">
412 156a1144 2022-12-17 op <div class="navs">
413 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
415 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
418 156a1144 2022-12-17 op <div class="dotted_line"></div>
420 156a1144 2022-12-17 op {{ if t->next_id || t->prev_id }}
421 156a1144 2022-12-17 op {{ render gotweb_render_navs(tp) }}
426 298f95fb 2023-01-05 op {{ define gotweb_render_blob(struct template *tp,
427 298f95fb 2023-01-05 op struct got_blob_object *blob) }}
429 298f95fb 2023-01-05 op struct request *c = tp->tp_arg;
430 298f95fb 2023-01-05 op struct transport *t = c->t;
431 298f95fb 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
433 298f95fb 2023-01-05 op <div id="blob_title_wrapper">
434 298f95fb 2023-01-05 op <div id="blob_title">Blob</div>
436 298f95fb 2023-01-05 op <div id="blob_content">
437 298f95fb 2023-01-05 op <div id="blob_header_wrapper">
438 298f95fb 2023-01-05 op <div id="blob_header">
439 298f95fb 2023-01-05 op <div class="header_age_title">Date:</div>
440 298f95fb 2023-01-05 op <div class="header_age">
441 298f95fb 2023-01-05 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
443 298f95fb 2023-01-05 op <div id="header_commit_msg_title">Message:</div>
444 298f95fb 2023-01-05 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
447 298f95fb 2023-01-05 op <div class="dotted_line"></div>
448 298f95fb 2023-01-05 op <div id="blob">
450 298f95fb 2023-01-05 op {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
456 298f95fb 2023-01-05 op {{ define gotweb_render_blob_line(struct template *tp, const char *line,
457 298f95fb 2023-01-05 op size_t no) }}
459 298f95fb 2023-01-05 op char lineno[16];
462 298f95fb 2023-01-05 op r = snprintf(lineno, sizeof(lineno), "%zu", no);
463 298f95fb 2023-01-05 op if (r < 0 || (size_t)r >= sizeof(lineno))
466 298f95fb 2023-01-05 op <div class="blob_line" id="line{{ lineno }}">
467 298f95fb 2023-01-05 op <div class="blob_number">
468 298f95fb 2023-01-05 op <a href="#line{{ lineno }}">{{ lineno }}</a>
470 298f95fb 2023-01-05 op <div class="blob_code">{{ line }}</div>
474 43d421de 2023-01-05 op {{ define gotweb_render_tree(struct template *tp) }}
476 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
477 43d421de 2023-01-05 op struct transport *t = c->t;
478 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
480 43d421de 2023-01-05 op <div id="tree_title_wrapper">
481 43d421de 2023-01-05 op <div id="tree_title">Tree</div>
483 43d421de 2023-01-05 op <div id="tree_content">
484 43d421de 2023-01-05 op <div id="tree_header_wrapper">
485 43d421de 2023-01-05 op <div id="tree_header">
486 43d421de 2023-01-05 op <div id="header_tree_title">Tree:</div>
487 43d421de 2023-01-05 op <div id="header_tree">{{ rc->tree_id }}</div>
488 43d421de 2023-01-05 op <div class="header_age_title">Date:</div>
489 43d421de 2023-01-05 op <div class="header_age">
490 43d421de 2023-01-05 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
492 43d421de 2023-01-05 op <div id="header_commit_msg_title">Message:</div>
493 43d421de 2023-01-05 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
496 43d421de 2023-01-05 op <div class="dotted_line"></div>
497 43d421de 2023-01-05 op <div id="tree">
498 43d421de 2023-01-05 op {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
503 43d421de 2023-01-05 op {{ define gotweb_render_tree_item(struct template *tp,
504 43d421de 2023-01-05 op struct got_tree_entry *te) }}
506 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
507 43d421de 2023-01-05 op struct transport *t = c->t;
508 43d421de 2023-01-05 op struct querystring *qs = t->qs;
509 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
510 43d421de 2023-01-05 op const char *modestr = "";
511 43d421de 2023-01-05 op const char *name;
512 43d421de 2023-01-05 op const char *folder;
513 43d421de 2023-01-05 op char *dir = NULL;
515 43d421de 2023-01-05 op struct gotweb_url url = {
516 43d421de 2023-01-05 op .index_page = -1,
518 43d421de 2023-01-05 op .commit = rc->commit_id,
519 43d421de 2023-01-05 op .path = qs->path,
522 43d421de 2023-01-05 op name = got_tree_entry_get_name(te);
523 43d421de 2023-01-05 op mode = got_tree_entry_get_mode(te);
525 43d421de 2023-01-05 op folder = qs->folder ? qs->folder : "";
526 43d421de 2023-01-05 op if (S_ISDIR(mode)) {
527 43d421de 2023-01-05 op if (asprintf(&dir, "%s/%s", folder, name) == -1)
530 43d421de 2023-01-05 op url.action = TREE;
531 43d421de 2023-01-05 op url.folder = dir;
533 43d421de 2023-01-05 op url.action = BLOB;
534 43d421de 2023-01-05 op url.folder = folder;
535 43d421de 2023-01-05 op url.file = name;
538 43d421de 2023-01-05 op if (got_object_tree_entry_is_submodule(te))
539 43d421de 2023-01-05 op modestr = "$";
540 43d421de 2023-01-05 op else if (S_ISLNK(mode))
541 43d421de 2023-01-05 op modestr = "@";
542 43d421de 2023-01-05 op else if (S_ISDIR(mode))
543 43d421de 2023-01-05 op modestr = "/";
544 43d421de 2023-01-05 op else if (mode & S_IXUSR)
545 43d421de 2023-01-05 op modestr = "*";
547 43d421de 2023-01-05 op <div class="tree_wrapper">
548 43d421de 2023-01-05 op {{ if S_ISDIR(mode) }}
549 43d421de 2023-01-05 op <div class="tree_line">
550 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
551 43d421de 2023-01-05 op {{ name }}{{ modestr }}
554 43d421de 2023-01-05 op <div class="tree_line_blank"> </div>
556 43d421de 2023-01-05 op <div class="tree_line">
557 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
558 43d421de 2023-01-05 op {{ name }}{{ modestr }}
561 43d421de 2023-01-05 op <div class="tree_line_blank">
562 43d421de 2023-01-05 op {! url.action = COMMITS; !}
563 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
567 43d421de 2023-01-05 op {! url.action = BLAME; !}
568 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
574 43d421de 2023-01-05 op {{ finally }}
580 d60961d2 2023-01-13 op {{ define gotweb_render_tags(struct template *tp) }}
582 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
583 067396e6 2023-01-09 op struct transport *t = c->t;
584 067396e6 2023-01-09 op struct querystring *qs = t->qs;
585 067396e6 2023-01-09 op struct repo_tag *rt;
586 067396e6 2023-01-09 op int commit_found;
588 067396e6 2023-01-09 op commit_found = qs->commit == NULL;
590 067396e6 2023-01-09 op <div id="tags_title_wrapper">
591 067396e6 2023-01-09 op <div id="tags_title">Tags</div>
593 067396e6 2023-01-09 op <div id="tags_content">
594 067396e6 2023-01-09 op {{ if t->tag_count == 0 }}
595 067396e6 2023-01-09 op <div id="err_content">
596 067396e6 2023-01-09 op This repository contains no tags
599 067396e6 2023-01-09 op {{ tailq-foreach rt &t->repo_tags entry }}
600 067396e6 2023-01-09 op {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
601 067396e6 2023-01-09 op {! commit_found = 1; !}
602 067396e6 2023-01-09 op {{ render tag_item(tp, rt) }}
605 067396e6 2023-01-09 op {{ if t->next_id || t->prev_id }}
606 067396e6 2023-01-09 op {{ render gotweb_render_navs(tp) }}
612 067396e6 2023-01-09 op {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
614 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
615 067396e6 2023-01-09 op struct transport *t = c->t;
616 067396e6 2023-01-09 op struct repo_dir *repo_dir = t->repo_dir;
617 067396e6 2023-01-09 op char *tag_name = rt->tag_name;
618 067396e6 2023-01-09 op char *msg = rt->tag_commit;
620 067396e6 2023-01-09 op struct gotweb_url url = {
621 067396e6 2023-01-09 op .action = TAG,
622 067396e6 2023-01-09 op .index_page = -1,
624 067396e6 2023-01-09 op .path = repo_dir->name,
625 067396e6 2023-01-09 op .commit = rt->commit_id,
628 067396e6 2023-01-09 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
629 067396e6 2023-01-09 op tag_name += 10;
632 067396e6 2023-01-09 op nl = strchr(msg, '\n');
637 067396e6 2023-01-09 op <div class="tag_age">
638 067396e6 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
640 067396e6 2023-01-09 op <div class="tag">{{ tag_name }}</div>
641 067396e6 2023-01-09 op <div class="tag_log">
642 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">
646 067396e6 2023-01-09 op <div class="navs_wrapper">
647 067396e6 2023-01-09 op <div class="navs">
648 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
650 067396e6 2023-01-09 op {! url.action = BRIEFS; !}
651 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
653 067396e6 2023-01-09 op {! url.action = COMMITS; !}
654 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
657 067396e6 2023-01-09 op <div class="dotted_line"></div>
660 dc07f76c 2023-01-09 op {{ define gotweb_render_tag(struct template *tp) }}
662 dc07f76c 2023-01-09 op struct request *c = tp->tp_arg;
663 dc07f76c 2023-01-09 op struct transport *t = c->t;
664 dc07f76c 2023-01-09 op struct repo_tag *rt;
665 dc07f76c 2023-01-09 op const char *tag_name;
667 dc07f76c 2023-01-09 op rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
668 dc07f76c 2023-01-09 op tag_name = rt->tag_name;
670 dc07f76c 2023-01-09 op if (strncmp(tag_name, "refs/", 5) == 0)
671 dc07f76c 2023-01-09 op tag_name += 5;
673 dc07f76c 2023-01-09 op <div id="tags_title_wrapper">
674 dc07f76c 2023-01-09 op <div id="tags_title">Tag</div>
676 dc07f76c 2023-01-09 op <div id="tags_content">
677 dc07f76c 2023-01-09 op <div id="tag_header_wrapper">
678 dc07f76c 2023-01-09 op <div id="tag_header">
679 dc07f76c 2023-01-09 op <div class="header_commit_title">Commit:</div>
680 dc07f76c 2023-01-09 op <div class="header_commit">
681 dc07f76c 2023-01-09 op {{ rt->commit_id }}
683 dc07f76c 2023-01-09 op <span class="refs_str">({{ tag_name }})</span>
685 dc07f76c 2023-01-09 op <div class="header_author_title">Tagger:</div>
686 dc07f76c 2023-01-09 op <div class="header_author">{{ rt->tagger }}</div>
687 dc07f76c 2023-01-09 op <div class="header_age_title">Date:</div>
688 dc07f76c 2023-01-09 op <div class="header_age">
689 dc07f76c 2023-01-09 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
691 dc07f76c 2023-01-09 op <div id="header_commit_msg_title">Message:</div>
692 dc07f76c 2023-01-09 op <div id="header_commit_msg">{{ rt->commit_msg }}</div>
694 dc07f76c 2023-01-09 op <div class="dotted_line"></div>
695 dc07f76c 2023-01-09 op <div id="tag_commit">
697 dc07f76c 2023-01-09 op {{ rt->tag_commit }}
703 587550a5 2023-01-10 op {{ define gotweb_render_diff(struct template *tp, FILE *fp) }}
705 587550a5 2023-01-10 op struct request *c = tp->tp_arg;
706 587550a5 2023-01-10 op struct transport *t = c->t;
707 587550a5 2023-01-10 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
708 587550a5 2023-01-10 op char *line = NULL;
709 587550a5 2023-01-10 op size_t linesize = 0;
710 587550a5 2023-01-10 op ssize_t linelen;
712 587550a5 2023-01-10 op <div id="diff_title_wrapper">
713 587550a5 2023-01-10 op <div id="diff_title">Commit Diff</div>
715 587550a5 2023-01-10 op <div id="diff_content">
716 587550a5 2023-01-10 op <div id="diff_header_wrapper">
717 587550a5 2023-01-10 op <div id="diff_header">
718 587550a5 2023-01-10 op <div class="header_commit_title">Commit:</div>
719 587550a5 2023-01-10 op <div class="header_commit">{{ rc->commit_id }}</div>
720 49632cd3 2023-01-10 op <div class="header_author_title">From:</div>
721 587550a5 2023-01-10 op <div class="header_author">{{ rc->author }}</div>
722 49632cd3 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
723 49632cd3 2023-01-10 op <div class="header_author_title">Via:</div>
724 49632cd3 2023-01-10 op <div class="header_author">{{ rc->committer }}</div>
726 587550a5 2023-01-10 op <div class="header_age_title">Date:</div>
727 587550a5 2023-01-10 op <div class="header_age">
728 587550a5 2023-01-10 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
730 587550a5 2023-01-10 op <div id="header_commit_msg_title">Message</div>
731 587550a5 2023-01-10 op <div id="header_commit_msg">{{ rc->commit_msg }}</div>
734 587550a5 2023-01-10 op <div class="dotted_line"></div>
735 587550a5 2023-01-10 op <div id="diff">
737 587550a5 2023-01-10 op {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
738 587550a5 2023-01-10 op {{ render diff_line(tp, line) }}
742 587550a5 2023-01-10 op {{ finally }}
743 587550a5 2023-01-10 op {! free(line); !}
746 587550a5 2023-01-10 op {{ define diff_line(struct template *tp, char *line )}}
748 587550a5 2023-01-10 op const char *color = NULL;
751 587550a5 2023-01-10 op if (!strncmp(line, "-", 1))
752 587550a5 2023-01-10 op color = "diff_minus";
753 587550a5 2023-01-10 op else if (!strncmp(line, "+", 1))
754 587550a5 2023-01-10 op color = "diff_plus";
755 587550a5 2023-01-10 op else if (!strncmp(line, "@@", 2))
756 587550a5 2023-01-10 op color = "diff_chunk_header";
757 587550a5 2023-01-10 op else if (!strncmp(line, "commit +", 8) ||
758 587550a5 2023-01-10 op !strncmp(line, "commit -", 8) ||
759 587550a5 2023-01-10 op !strncmp(line, "blob +", 6) ||
760 587550a5 2023-01-10 op !strncmp(line, "blob -", 6) ||
761 587550a5 2023-01-10 op !strncmp(line, "file +", 6) ||
762 587550a5 2023-01-10 op !strncmp(line, "file -", 6))
763 587550a5 2023-01-10 op color = "diff_meta";
764 587550a5 2023-01-10 op else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
765 587550a5 2023-01-10 op color = "diff_author";
766 587550a5 2023-01-10 op else if (!strncmp(line, "date:", 5))
767 587550a5 2023-01-10 op color = "diff_date";
769 587550a5 2023-01-10 op nl = strchr(line, '\n');
773 587550a5 2023-01-10 op <div class="diff_line {{ color }}">{{ line }}</div>
776 3ab2c914 2023-01-11 op {{ define gotweb_render_branches(struct template *tp,
777 3ab2c914 2023-01-11 op struct got_reflist_head *refs) }}
779 3ab2c914 2023-01-11 op struct got_reflist_entry *re;
781 3ab2c914 2023-01-11 op <div id="branches_title_wrapper">
782 3ab2c914 2023-01-11 op <div id="branches_title">Branches</div>
784 3ab2c914 2023-01-11 op <div id="branches_content">
785 3ab2c914 2023-01-11 op {{ tailq-foreach re refs entry }}
786 3ab2c914 2023-01-11 op {{ if !got_ref_is_symbolic(re->ref) }}
787 3ab2c914 2023-01-11 op {{ render branch(tp, re) }}
793 3ab2c914 2023-01-11 op {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
795 3ab2c914 2023-01-11 op const struct got_error *err;
796 3ab2c914 2023-01-11 op struct request *c = tp->tp_arg;
797 3ab2c914 2023-01-11 op struct querystring *qs = c->t->qs;
798 3ab2c914 2023-01-11 op const char *refname;
799 3ab2c914 2023-01-11 op char *age = NULL;
800 3ab2c914 2023-01-11 op struct gotweb_url url = {
801 3ab2c914 2023-01-11 op .action = SUMMARY,
802 3ab2c914 2023-01-11 op .index_page = -1,
804 3ab2c914 2023-01-11 op .path = qs->path,
807 3ab2c914 2023-01-11 op refname = got_ref_get_name(re->ref);
809 3ab2c914 2023-01-11 op err = got_get_repo_age(&age, c, refname, TM_DIFF);
811 3ab2c914 2023-01-11 op log_warnx("%s: %s", __func__, err->msg);
815 3ab2c914 2023-01-11 op if (strncmp(refname, "refs/heads/", 11) == 0)
816 3ab2c914 2023-01-11 op refname += 11;
818 3ab2c914 2023-01-11 op url.headref = refname;
820 3ab2c914 2023-01-11 op <div class="branches_wrapper">
821 3ab2c914 2023-01-11 op <div class="branches_age">{{ age }}</div>
822 3ab2c914 2023-01-11 op <div class="branches_space"> </div>
823 3ab2c914 2023-01-11 op <div class="branch">
824 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
826 3ab2c914 2023-01-11 op <div class="navs_wrapper">
827 3ab2c914 2023-01-11 op <div class="navs">
828 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
830 3ab2c914 2023-01-11 op {! url.action = BRIEFS; !}
831 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
833 3ab2c914 2023-01-11 op {! url.action = COMMITS; !}
834 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
837 3ab2c914 2023-01-11 op <div class="dotted_line"></div>
839 3ab2c914 2023-01-11 op {{ finally }}
840 3ab2c914 2023-01-11 op {! free(age); !}
843 69525b4e 2023-01-13 op {{ define gotweb_render_summary(struct template *tp,
844 69525b4e 2023-01-13 op struct got_reflist_head *refs) }}
846 69525b4e 2023-01-13 op struct request *c = tp->tp_arg;
847 69525b4e 2023-01-13 op struct server *srv = c->srv;
848 69525b4e 2023-01-13 op struct transport *t = c->t;
850 69525b4e 2023-01-13 op <div id="summary_wrapper">
851 69525b4e 2023-01-13 op {{ if srv->show_repo_description }}
852 69525b4e 2023-01-13 op <div id="description_title">Description:</div>
853 69525b4e 2023-01-13 op <div id="description">{{ t->repo_dir->description }}</div>
855 69525b4e 2023-01-13 op {{ if srv->show_repo_owner }}
856 69525b4e 2023-01-13 op <div id="repo_owner_title">Owner:</div>
857 69525b4e 2023-01-13 op <div id="repo_owner">{{ t->repo_dir->owner }}</div>
859 69525b4e 2023-01-13 op {{ if srv->show_repo_age }}
860 69525b4e 2023-01-13 op <div id="last_change_title">Last Change:</div>
861 69525b4e 2023-01-13 op <div id="last_change">{{ t->repo_dir->age }}</div>
863 69525b4e 2023-01-13 op {{ if srv->show_repo_cloneurl }}
864 69525b4e 2023-01-13 op <div id="cloneurl_title">Clone URL:</div>
865 69525b4e 2023-01-13 op <div id="cloneurl">{{ t->repo_dir->url }}</div>
868 69525b4e 2023-01-13 op {{ render gotweb_render_briefs(tp) }}
869 69525b4e 2023-01-13 op {{ render gotweb_render_tags(tp) }}
870 69525b4e 2023-01-13 op {{ render gotweb_render_branches(tp, refs) }}
873 1abb18e1 2022-12-20 op {{ define gotweb_render_rss(struct template *tp) }}
875 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
876 1abb18e1 2022-12-20 op struct server *srv = c->srv;
877 1abb18e1 2022-12-20 op struct transport *t = c->t;
878 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
879 1abb18e1 2022-12-20 op struct repo_tag *rt;
880 1abb18e1 2022-12-20 op struct gotweb_url summary = {
881 1abb18e1 2022-12-20 op .action = SUMMARY,
882 1abb18e1 2022-12-20 op .index_page = -1,
884 1abb18e1 2022-12-20 op .path = repo_dir->name,
887 1abb18e1 2022-12-20 op <?xml version="1.0" encoding="UTF-8"?>
888 1abb18e1 2022-12-20 op <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
890 1abb18e1 2022-12-20 op <title>Tags of {{ repo_dir->name }}</title>
893 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &summary) }}
896 1abb18e1 2022-12-20 op {{ if srv->show_repo_description }}
897 1abb18e1 2022-12-20 op <description>{{ repo_dir->description }}</description>
899 1abb18e1 2022-12-20 op {{ tailq-foreach rt &t->repo_tags entry }}
900 1abb18e1 2022-12-20 op {{ render rss_tag_item(tp, rt) }}
906 1abb18e1 2022-12-20 op {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
908 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
909 1abb18e1 2022-12-20 op struct transport *t = c->t;
910 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
911 1abb18e1 2022-12-20 op char *tag_name = rt->tag_name;
912 1abb18e1 2022-12-20 op struct gotweb_url tag = {
913 1abb18e1 2022-12-20 op .action = TAG,
914 1abb18e1 2022-12-20 op .index_page = -1,
916 1abb18e1 2022-12-20 op .path = repo_dir->name,
917 1abb18e1 2022-12-20 op .commit = rt->commit_id,
920 1abb18e1 2022-12-20 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
921 1abb18e1 2022-12-20 op tag_name += 10;
924 1abb18e1 2022-12-20 op <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
927 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &tag) }}
930 1abb18e1 2022-12-20 op <description>
931 1abb18e1 2022-12-20 op <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
932 1abb18e1 2022-12-20 op </description>
933 1abb18e1 2022-12-20 op {{ render rss_author(tp, rt->tagger) }}
934 1abb18e1 2022-12-20 op <guid isPermaLink="false">{{ rt->commit_id }}</guid>
936 1abb18e1 2022-12-20 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
941 1abb18e1 2022-12-20 op {{ define rss_author(struct template *tp, char *author) }}
943 1abb18e1 2022-12-20 op char *t, *mail;
945 1abb18e1 2022-12-20 op /* what to do if the author name contains a paren? */
946 1abb18e1 2022-12-20 op if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
949 1abb18e1 2022-12-20 op t = strchr(author, '<');
950 1abb18e1 2022-12-20 op if (t == NULL)
955 1abb18e1 2022-12-20 op while (isspace((unsigned char)*--t))
958 1abb18e1 2022-12-20 op t = strchr(mail, '>');
959 1abb18e1 2022-12-20 op if (t == NULL)
964 1abb18e1 2022-12-20 op {{ mail }} {{" "}} ({{ author }})