3 e7e5fa49 2022-12-30 thomas * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 e7e5fa49 2022-12-30 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
6 e7e5fa49 2022-12-30 thomas * Permission to use, copy, modify, and distribute this software for any
7 e7e5fa49 2022-12-30 thomas * purpose with or without fee is hereby granted, provided that the above
8 e7e5fa49 2022-12-30 thomas * copyright notice and this permission notice appear in all copies.
10 e7e5fa49 2022-12-30 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 e7e5fa49 2022-12-30 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 e7e5fa49 2022-12-30 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 e7e5fa49 2022-12-30 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 e7e5fa49 2022-12-30 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 e7e5fa49 2022-12-30 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 e7e5fa49 2022-12-30 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 4fccd2fe 2023-03-08 thomas #include "got_compat.h"
21 e7e5fa49 2022-12-30 thomas #include <sys/types.h>
22 e7e5fa49 2022-12-30 thomas #include <sys/queue.h>
23 3c14c1f2 2023-01-06 thomas #include <sys/stat.h>
25 d6795e9f 2022-12-30 thomas #include <ctype.h>
26 e7e5fa49 2022-12-30 thomas #include <event.h>
27 e7e5fa49 2022-12-30 thomas #include <stdint.h>
28 3c14c1f2 2023-01-06 thomas #include <stdio.h>
29 e7e5fa49 2022-12-30 thomas #include <stdlib.h>
30 e7e5fa49 2022-12-30 thomas #include <string.h>
31 e7e5fa49 2022-12-30 thomas #include <imsg.h>
33 00abe30b 2023-01-14 thomas #include "got_error.h"
34 3c14c1f2 2023-01-06 thomas #include "got_object.h"
35 00abe30b 2023-01-14 thomas #include "got_reference.h"
37 e7e5fa49 2022-12-30 thomas #include "proc.h"
39 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
40 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
42 4cc0851e 2023-10-08 thomas enum gotweb_ref_tm {
47 4cc0851e 2023-10-08 thomas static int datetime(struct template *, time_t, int);
48 b82440e1 2023-01-06 thomas static int gotweb_render_blob_line(struct template *, const char *, size_t);
49 3c14c1f2 2023-01-06 thomas static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
50 1cd5d437 2023-01-15 thomas static int blame_line(struct template *, const char *, struct blame_line *,
51 1cd5d437 2023-01-15 thomas int, int);
53 20bab626 2023-02-03 thomas static inline int gotweb_render_more(struct template *, int);
55 dccd05b4 2023-01-10 thomas static inline int diff_line(struct template *, char *);
56 617497a6 2023-01-09 thomas static inline int tag_item(struct template *, struct repo_tag *);
57 00abe30b 2023-01-14 thomas static inline int branch(struct template *, struct got_reflist_entry *);
58 d6795e9f 2022-12-30 thomas static inline int rss_tag_item(struct template *, struct repo_tag *);
59 d6795e9f 2022-12-30 thomas static inline int rss_author(struct template *, char *);
63 4cc0851e 2023-10-08 thomas {{ define datetime(struct template *tp, time_t t, int fmt) }}
65 4cc0851e 2023-10-08 thomas struct tm tm;
66 4cc0851e 2023-10-08 thomas char rfc3339[64];
67 4cc0851e 2023-10-08 thomas char datebuf[64];
69 4cc0851e 2023-10-08 thomas if (gmtime_r(&t, &tm) == NULL)
70 4cc0851e 2023-10-08 thomas return -1;
72 4cc0851e 2023-10-08 thomas if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
73 4cc0851e 2023-10-08 thomas return -1;
75 4cc0851e 2023-10-08 thomas if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
76 4cc0851e 2023-10-08 thomas return -1;
78 4cc0851e 2023-10-08 thomas <time datetime="{{ rfc3339 }}">
79 4cc0851e 2023-10-08 thomas {{ if fmt == TM_DIFF }}
80 4cc0851e 2023-10-08 thomas {{ render gotweb_render_age(tp, t) }}
81 4cc0851e 2023-10-08 thomas {{ else }}
82 4cc0851e 2023-10-08 thomas {{ datebuf }} {{ " UTC" }}
87 161663e7 2023-03-11 thomas {{ define gotweb_render_page(struct template *tp,
88 161663e7 2023-03-11 thomas int (*body)(struct template *)) }}
90 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
91 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
92 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
93 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
94 3191e256 2022-12-30 thomas const char *prfx = c->document_uri;
95 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
97 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
98 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
99 e7e5fa49 2022-12-30 thomas u_path.page = -1;
100 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
102 e7e5fa49 2022-12-30 thomas <!doctype html>
105 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
106 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
107 fdd79f2f 2023-09-12 thomas <meta name="viewport" content="initial-scale=1.0" />
108 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
109 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
110 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
111 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
112 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
113 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
114 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
115 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
118 fdd79f2f 2023-09-12 thomas <header id="header">
119 fdd79f2f 2023-09-12 thomas <div id="got_link">
120 fdd79f2f 2023-09-12 thomas <a href="{{ srv->logo_url }}" target="_blank">
121 fdd79f2f 2023-09-12 thomas <img src="{{ prfx }}{{ srv->logo }}" />
124 fdd79f2f 2023-09-12 thomas </header>
125 fdd79f2f 2023-09-12 thomas <nav id="site_path">
126 fdd79f2f 2023-09-12 thomas <div id="site_link">
127 fdd79f2f 2023-09-12 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
128 fdd79f2f 2023-09-12 thomas {{ srv->site_link }}
130 fdd79f2f 2023-09-12 thomas {{ if qs->path }}
131 fdd79f2f 2023-09-12 thomas {! u_path.path = qs->path; !}
132 fdd79f2f 2023-09-12 thomas {{ " / " }}
133 fdd79f2f 2023-09-12 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
134 fdd79f2f 2023-09-12 thomas {{ qs->path }}
136 fdd79f2f 2023-09-12 thomas {{ end }}
137 fdd79f2f 2023-09-12 thomas {{ if qs->action != INDEX }}
138 fdd79f2f 2023-09-12 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
139 fdd79f2f 2023-09-12 thomas {{ end }}
143 fdd79f2f 2023-09-12 thomas {{ render body(tp) }}
145 fdd79f2f 2023-09-12 thomas <footer id="site_owner_wrapper">
146 fdd79f2f 2023-09-12 thomas <p id="site_owner">
147 fdd79f2f 2023-09-12 thomas {{ if srv->show_site_owner }}
148 fdd79f2f 2023-09-12 thomas {{ srv->site_owner }}
149 fdd79f2f 2023-09-12 thomas {{ end }}
151 fdd79f2f 2023-09-12 thomas </footer>
154 164b5ddc 2023-03-11 thomas {{ end }}
156 164b5ddc 2023-03-11 thomas {{ define gotweb_render_error(struct template *tp) }}
158 164b5ddc 2023-03-11 thomas struct request *c = tp->tp_arg;
159 164b5ddc 2023-03-11 thomas struct transport *t = c->t;
161 164b5ddc 2023-03-11 thomas <div id="err_content">
162 164b5ddc 2023-03-11 thomas {{ if t->error }}
163 164b5ddc 2023-03-11 thomas {{ t->error->msg }}
164 164b5ddc 2023-03-11 thomas {{ else }}
165 164b5ddc 2023-03-11 thomas See daemon logs for details
166 164b5ddc 2023-03-11 thomas {{ end }}
168 e7e5fa49 2022-12-30 thomas {{ end }}
170 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
172 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
173 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
175 e7e5fa49 2022-12-30 thomas <div id="index_header">
176 fdd79f2f 2023-09-12 thomas <div class="index_project">
179 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
180 fdd79f2f 2023-09-12 thomas <div class="index_project_description">
181 e7e5fa49 2022-12-30 thomas Description
183 e7e5fa49 2022-12-30 thomas {{ end }}
184 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
185 fdd79f2f 2023-09-12 thomas <div class="index_project_owner">
188 e7e5fa49 2022-12-30 thomas {{ end }}
189 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
190 fdd79f2f 2023-09-12 thomas <div class="index_project_age">
191 e7e5fa49 2022-12-30 thomas Last Change
193 e7e5fa49 2022-12-30 thomas {{ end }}
195 e7e5fa49 2022-12-30 thomas {{ end }}
197 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
199 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
200 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
201 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
202 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
203 e7e5fa49 2022-12-30 thomas .index_page = -1,
204 e7e5fa49 2022-12-30 thomas .page = -1,
205 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
206 e7e5fa49 2022-12-30 thomas }, briefs = {
207 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
208 e7e5fa49 2022-12-30 thomas .index_page = -1,
209 e7e5fa49 2022-12-30 thomas .page = -1,
210 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
211 e7e5fa49 2022-12-30 thomas }, commits = {
212 e7e5fa49 2022-12-30 thomas .action = COMMITS,
213 e7e5fa49 2022-12-30 thomas .index_page = -1,
214 e7e5fa49 2022-12-30 thomas .page = -1,
215 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
216 e7e5fa49 2022-12-30 thomas }, tags = {
217 e7e5fa49 2022-12-30 thomas .action = TAGS,
218 e7e5fa49 2022-12-30 thomas .index_page = -1,
219 e7e5fa49 2022-12-30 thomas .page = -1,
220 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
221 e7e5fa49 2022-12-30 thomas }, tree = {
222 e7e5fa49 2022-12-30 thomas .action = TREE,
223 e7e5fa49 2022-12-30 thomas .index_page = -1,
224 e7e5fa49 2022-12-30 thomas .page = -1,
225 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
226 d6795e9f 2022-12-30 thomas }, rss = {
227 d6795e9f 2022-12-30 thomas .action = RSS,
228 d6795e9f 2022-12-30 thomas .index_page = -1,
229 d6795e9f 2022-12-30 thomas .page = -1,
230 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
233 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
234 e7e5fa49 2022-12-30 thomas <div class="index_project">
235 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
237 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
238 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
239 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
241 e7e5fa49 2022-12-30 thomas {{ end }}
242 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
243 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
244 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
246 e7e5fa49 2022-12-30 thomas {{ end }}
247 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
248 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
249 4cc0851e 2023-10-08 thomas {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
251 e7e5fa49 2022-12-30 thomas {{ end }}
252 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
253 e7e5fa49 2022-12-30 thomas <div class="navs">
254 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
255 e7e5fa49 2022-12-30 thomas {{ " | " }}
256 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
257 e7e5fa49 2022-12-30 thomas {{ " | " }}
258 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
259 e7e5fa49 2022-12-30 thomas {{ " | " }}
260 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
261 e7e5fa49 2022-12-30 thomas {{ " | " }}
262 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
263 d6795e9f 2022-12-30 thomas {{ " | " }}
264 d6795e9f 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
269 e7e5fa49 2022-12-30 thomas {{ end }}
271 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
273 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
274 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
275 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
276 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
277 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
278 e7e5fa49 2022-12-30 thomas struct gotweb_url diff_url, tree_url;
279 e7e5fa49 2022-12-30 thomas char *tmp;
281 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
282 e7e5fa49 2022-12-30 thomas .action = DIFF,
283 e7e5fa49 2022-12-30 thomas .index_page = -1,
284 e7e5fa49 2022-12-30 thomas .page = -1,
285 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
286 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
288 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
289 e7e5fa49 2022-12-30 thomas .action = TREE,
290 e7e5fa49 2022-12-30 thomas .index_page = -1,
291 e7e5fa49 2022-12-30 thomas .page = -1,
292 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
293 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
296 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
297 fdd79f2f 2023-09-12 thomas <h2>Commit Briefs</h2>
298 fdd79f2f 2023-09-12 thomas </header>
299 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
300 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
302 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
303 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
305 64d39587 2023-01-14 thomas tmp = strchr(rc->committer, '<');
307 e7e5fa49 2022-12-30 thomas *tmp = '\0';
309 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
311 e7e5fa49 2022-12-30 thomas *tmp = '\0';
313 fdd79f2f 2023-09-12 thomas <div class='brief'>
314 fdd79f2f 2023-09-12 thomas <p class='brief_meta'>
315 fdd79f2f 2023-09-12 thomas <span class='briefs_age'>
316 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
319 fdd79f2f 2023-09-12 thomas <span class="briefs_author">
320 fdd79f2f 2023-09-12 thomas {{ rc->committer }}
323 fdd79f2f 2023-09-12 thomas <p class="briefs_log">
324 fdd79f2f 2023-09-12 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
325 fdd79f2f 2023-09-12 thomas {{ rc->commit_msg }}
327 fdd79f2f 2023-09-12 thomas {{ if rc->refs_str }}
328 fdd79f2f 2023-09-12 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
329 fdd79f2f 2023-09-12 thomas {{ end }}
333 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
334 e7e5fa49 2022-12-30 thomas <div class="navs">
335 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
336 e7e5fa49 2022-12-30 thomas {{ " | " }}
337 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
341 e7e5fa49 2022-12-30 thomas {{ end }}
342 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, BRIEFS) }}
344 2f4f0731 2022-12-30 thomas {{ end }}
346 20bab626 2023-02-03 thomas {{ define gotweb_render_more(struct template *tp, int action) }}
348 20bab626 2023-02-03 thomas struct request *c = tp->tp_arg;
349 20bab626 2023-02-03 thomas struct transport *t = c->t;
350 20bab626 2023-02-03 thomas struct querystring *qs = t->qs;
351 20bab626 2023-02-03 thomas struct gotweb_url more = {
352 20bab626 2023-02-03 thomas .action = action,
353 20bab626 2023-02-03 thomas .index_page = -1,
354 20bab626 2023-02-03 thomas .path = qs->path,
355 20bab626 2023-02-03 thomas .commit = t->more_id,
356 20bab626 2023-02-03 thomas .headref = qs->headref,
357 882ee74d 2023-09-14 thomas .file = qs->file,
360 20bab626 2023-02-03 thomas {{ if t->more_id }}
361 20bab626 2023-02-03 thomas <div id="np_wrapper">
362 20bab626 2023-02-03 thomas <div id="nav_more">
363 20bab626 2023-02-03 thomas <a href="{{ render gotweb_render_url(c, &more) }}">
364 bd6e9c73 2023-02-03 thomas More ↓
368 20bab626 2023-02-03 thomas {{ end }}
369 20bab626 2023-02-03 thomas {{ end }}
371 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
373 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
374 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
375 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
376 2f4f0731 2022-12-30 thomas int have_prev, have_next;
378 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
380 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
381 2f4f0731 2022-12-30 thomas <div id="nav_prev">
382 2f4f0731 2022-12-30 thomas {{ if have_prev }}
383 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
386 2f4f0731 2022-12-30 thomas {{ end }}
388 2f4f0731 2022-12-30 thomas <div id="nav_next">
389 2f4f0731 2022-12-30 thomas {{ if have_next }}
390 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
393 2f4f0731 2022-12-30 thomas {{ end }}
396 2f4f0731 2022-12-30 thomas {{ finally }}
398 2f4f0731 2022-12-30 thomas free(t->next_id);
399 2f4f0731 2022-12-30 thomas t->next_id = NULL;
400 2f4f0731 2022-12-30 thomas free(t->prev_id);
401 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
403 e7e5fa49 2022-12-30 thomas {{ end }}
405 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
407 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
408 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
409 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
410 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
411 7ade8b27 2022-12-30 thomas struct gotweb_url diff, tree;
413 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
414 7ade8b27 2022-12-30 thomas .action = DIFF,
415 7ade8b27 2022-12-30 thomas .index_page = -1,
416 7ade8b27 2022-12-30 thomas .page = -1,
417 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
419 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
420 7ade8b27 2022-12-30 thomas .action = TREE,
421 7ade8b27 2022-12-30 thomas .index_page = -1,
422 7ade8b27 2022-12-30 thomas .page = -1,
423 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
426 fdd79f2f 2023-09-12 thomas <header class="subtitle">
427 fdd79f2f 2023-09-12 thomas <h2>Commits</h2>
428 fdd79f2f 2023-09-12 thomas </header>
429 7ade8b27 2022-12-30 thomas <div class="commits_content">
430 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
432 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
433 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
435 7ade8b27 2022-12-30 thomas <div class="commits_header_wrapper">
436 fdd79f2f 2023-09-12 thomas <dl class="commits_header">
437 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
438 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
439 fdd79f2f 2023-09-12 thomas <dt>From:</dt>
440 fdd79f2f 2023-09-12 thomas <dd>{{ rc->author }}</dd>
441 54ffadaf 2023-01-14 thomas {{ if strcmp(rc->committer, rc->author) != 0 }}
442 fdd79f2f 2023-09-12 thomas <dt>Via:</dt>
443 fdd79f2f 2023-09-12 thomas <dd>{{ rc->committer }}</dd>
444 54ffadaf 2023-01-14 thomas {{ end }}
445 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
447 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
452 bbf94fd6 2023-01-02 thomas <div class="commit">
453 bbf94fd6 2023-01-02 thomas {{ "\n" }}
454 bbf94fd6 2023-01-02 thomas {{ rc->commit_msg }}
456 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
457 7ade8b27 2022-12-30 thomas <div class="navs">
458 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
459 7ade8b27 2022-12-30 thomas {{ " | " }}
460 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
464 7ade8b27 2022-12-30 thomas {{ end }}
465 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, COMMITS) }}
467 b82440e1 2023-01-06 thomas {{ end }}
469 161663e7 2023-03-11 thomas {{ define gotweb_render_blob(struct template *tp) }}
471 b82440e1 2023-01-06 thomas struct request *c = tp->tp_arg;
472 b82440e1 2023-01-06 thomas struct transport *t = c->t;
473 161663e7 2023-03-11 thomas struct got_blob_object *blob = t->blob;
474 b82440e1 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
476 fdd79f2f 2023-09-12 thomas <header class="subtitle">
477 fdd79f2f 2023-09-12 thomas <h2>Blob</h2>
478 fdd79f2f 2023-09-12 thomas </header>
479 b82440e1 2023-01-06 thomas <div id="blob_content">
480 b82440e1 2023-01-06 thomas <div id="blob_header_wrapper">
481 fdd79f2f 2023-09-12 thomas <dl id="blob_header">
482 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
484 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
486 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
487 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
491 b82440e1 2023-01-06 thomas <div id="blob">
493 b82440e1 2023-01-06 thomas {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
497 d6795e9f 2022-12-30 thomas {{ end }}
499 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob_line(struct template *tp, const char *line,
500 b82440e1 2023-01-06 thomas size_t no) }}
502 b82440e1 2023-01-06 thomas char lineno[16];
505 b82440e1 2023-01-06 thomas r = snprintf(lineno, sizeof(lineno), "%zu", no);
506 b82440e1 2023-01-06 thomas if (r < 0 || (size_t)r >= sizeof(lineno))
507 b82440e1 2023-01-06 thomas return -1;
509 b82440e1 2023-01-06 thomas <div class="blob_line" id="line{{ lineno }}">
510 fdd79f2f 2023-09-12 thomas <a href="#line{{ lineno }}">{{ lineno }}</a>
511 fdd79f2f 2023-09-12 thomas <span class="blob_code">{{ line }}</span>
513 3c14c1f2 2023-01-06 thomas {{ end }}
515 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree(struct template *tp) }}
517 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
518 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
519 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
521 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
522 fdd79f2f 2023-09-12 thomas <h2>Tree</h2>
523 fdd79f2f 2023-09-12 thomas </header>
524 3c14c1f2 2023-01-06 thomas <div id="tree_content">
525 3c14c1f2 2023-01-06 thomas <div id="tree_header_wrapper">
526 fdd79f2f 2023-09-12 thomas <dl id="tree_header">
527 fdd79f2f 2023-09-12 thomas <dt>Tree:</dt>
528 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
529 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
531 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
533 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
534 cbe7b7d7 2023-10-08 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
538 fdd79f2f 2023-09-12 thomas <table id="tree">
539 3c14c1f2 2023-01-06 thomas {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
542 3c14c1f2 2023-01-06 thomas {{ end }}
544 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree_item(struct template *tp,
545 3c14c1f2 2023-01-06 thomas struct got_tree_entry *te) }}
547 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
548 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
549 3c14c1f2 2023-01-06 thomas struct querystring *qs = t->qs;
550 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
551 3c14c1f2 2023-01-06 thomas const char *modestr = "";
552 3c14c1f2 2023-01-06 thomas const char *name;
553 3c14c1f2 2023-01-06 thomas const char *folder;
554 3c14c1f2 2023-01-06 thomas char *dir = NULL;
555 3c14c1f2 2023-01-06 thomas mode_t mode;
556 3c14c1f2 2023-01-06 thomas struct gotweb_url url = {
557 3c14c1f2 2023-01-06 thomas .index_page = -1,
558 3c14c1f2 2023-01-06 thomas .page = -1,
559 3c14c1f2 2023-01-06 thomas .commit = rc->commit_id,
560 3c14c1f2 2023-01-06 thomas .path = qs->path,
563 3c14c1f2 2023-01-06 thomas name = got_tree_entry_get_name(te);
564 3c14c1f2 2023-01-06 thomas mode = got_tree_entry_get_mode(te);
566 3c14c1f2 2023-01-06 thomas folder = qs->folder ? qs->folder : "";
567 3c14c1f2 2023-01-06 thomas if (S_ISDIR(mode)) {
568 3c14c1f2 2023-01-06 thomas if (asprintf(&dir, "%s/%s", folder, name) == -1)
569 3c14c1f2 2023-01-06 thomas return (-1);
571 3c14c1f2 2023-01-06 thomas url.action = TREE;
572 3c14c1f2 2023-01-06 thomas url.folder = dir;
574 3c14c1f2 2023-01-06 thomas url.action = BLOB;
575 3c14c1f2 2023-01-06 thomas url.folder = folder;
576 3c14c1f2 2023-01-06 thomas url.file = name;
579 3c14c1f2 2023-01-06 thomas if (got_object_tree_entry_is_submodule(te))
580 3c14c1f2 2023-01-06 thomas modestr = "$";
581 3c14c1f2 2023-01-06 thomas else if (S_ISLNK(mode))
582 3c14c1f2 2023-01-06 thomas modestr = "@";
583 3c14c1f2 2023-01-06 thomas else if (S_ISDIR(mode))
584 3c14c1f2 2023-01-06 thomas modestr = "/";
585 3c14c1f2 2023-01-06 thomas else if (mode & S_IXUSR)
586 3c14c1f2 2023-01-06 thomas modestr = "*";
588 fdd79f2f 2023-09-12 thomas <tr class="tree_wrapper">
589 3c14c1f2 2023-01-06 thomas {{ if S_ISDIR(mode) }}
590 fdd79f2f 2023-09-12 thomas <td class="tree_line" colspan=2>
591 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
592 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
595 3c14c1f2 2023-01-06 thomas {{ else }}
596 fdd79f2f 2023-09-12 thomas <td class="tree_line">
597 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
598 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
601 fdd79f2f 2023-09-12 thomas <td class="tree_line_blank">
602 3c14c1f2 2023-01-06 thomas {! url.action = COMMITS; !}
603 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
606 3c14c1f2 2023-01-06 thomas {{ " | " }}
607 3c14c1f2 2023-01-06 thomas {! url.action = BLAME; !}
608 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
612 3c14c1f2 2023-01-06 thomas {{ end }}
614 3c14c1f2 2023-01-06 thomas {{ finally }}
616 3c14c1f2 2023-01-06 thomas free(dir);
618 617497a6 2023-01-09 thomas {{ end }}
620 b3ba36c3 2023-01-14 thomas {{ define gotweb_render_tags(struct template *tp) }}
622 617497a6 2023-01-09 thomas struct request *c = tp->tp_arg;
623 617497a6 2023-01-09 thomas struct transport *t = c->t;
624 617497a6 2023-01-09 thomas struct querystring *qs = t->qs;
625 617497a6 2023-01-09 thomas struct repo_tag *rt;
626 617497a6 2023-01-09 thomas int commit_found;
628 617497a6 2023-01-09 thomas commit_found = qs->commit == NULL;
630 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
631 fdd79f2f 2023-09-12 thomas <h2>Tags</h2>
632 fdd79f2f 2023-09-12 thomas </header>
633 617497a6 2023-01-09 thomas <div id="tags_content">
634 617497a6 2023-01-09 thomas {{ if t->tag_count == 0 }}
635 617497a6 2023-01-09 thomas <div id="err_content">
636 617497a6 2023-01-09 thomas This repository contains no tags
638 617497a6 2023-01-09 thomas {{ else }}
639 617497a6 2023-01-09 thomas {{ tailq-foreach rt &t->repo_tags entry }}
640 617497a6 2023-01-09 thomas {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
641 617497a6 2023-01-09 thomas {! commit_found = 1; !}
642 617497a6 2023-01-09 thomas {{ render tag_item(tp, rt) }}
643 617497a6 2023-01-09 thomas {{ end }}
644 617497a6 2023-01-09 thomas {{ end }}
645 617497a6 2023-01-09 thomas {{ if t->next_id || t->prev_id }}
646 20bab626 2023-02-03 thomas {! qs->action = TAGS; !}
647 617497a6 2023-01-09 thomas {{ render gotweb_render_navs(tp) }}
648 617497a6 2023-01-09 thomas {{ end }}
649 617497a6 2023-01-09 thomas {{ end }}
651 b82440e1 2023-01-06 thomas {{ end }}
653 617497a6 2023-01-09 thomas {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
655 617497a6 2023-01-09 thomas struct request *c = tp->tp_arg;
656 617497a6 2023-01-09 thomas struct transport *t = c->t;
657 617497a6 2023-01-09 thomas struct repo_dir *repo_dir = t->repo_dir;
658 617497a6 2023-01-09 thomas char *tag_name = rt->tag_name;
659 617497a6 2023-01-09 thomas char *msg = rt->tag_commit;
660 617497a6 2023-01-09 thomas char *nl;
661 617497a6 2023-01-09 thomas struct gotweb_url url = {
662 617497a6 2023-01-09 thomas .action = TAG,
663 617497a6 2023-01-09 thomas .index_page = -1,
664 617497a6 2023-01-09 thomas .page = -1,
665 617497a6 2023-01-09 thomas .path = repo_dir->name,
666 617497a6 2023-01-09 thomas .commit = rt->commit_id,
669 617497a6 2023-01-09 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
670 617497a6 2023-01-09 thomas tag_name += 10;
672 617497a6 2023-01-09 thomas if (msg) {
673 617497a6 2023-01-09 thomas nl = strchr(msg, '\n');
675 617497a6 2023-01-09 thomas *nl = '\0';
678 617497a6 2023-01-09 thomas <div class="tag_age">
679 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
681 fdd79f2f 2023-09-12 thomas <div class="tag_name">{{ tag_name }}</div>
682 617497a6 2023-01-09 thomas <div class="tag_log">
683 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
684 617497a6 2023-01-09 thomas {{ msg }}
687 617497a6 2023-01-09 thomas <div class="navs_wrapper">
688 617497a6 2023-01-09 thomas <div class="navs">
689 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
690 617497a6 2023-01-09 thomas {{ " | " }}
691 617497a6 2023-01-09 thomas {! url.action = BRIEFS; !}
692 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
693 617497a6 2023-01-09 thomas {{ " | " }}
694 617497a6 2023-01-09 thomas {! url.action = COMMITS; !}
695 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
699 617497a6 2023-01-09 thomas {{ end }}
701 145ca42a 2023-01-09 thomas {{ define gotweb_render_tag(struct template *tp) }}
703 145ca42a 2023-01-09 thomas struct request *c = tp->tp_arg;
704 145ca42a 2023-01-09 thomas struct transport *t = c->t;
705 145ca42a 2023-01-09 thomas struct repo_tag *rt;
706 145ca42a 2023-01-09 thomas const char *tag_name;
708 145ca42a 2023-01-09 thomas rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
709 145ca42a 2023-01-09 thomas tag_name = rt->tag_name;
711 145ca42a 2023-01-09 thomas if (strncmp(tag_name, "refs/", 5) == 0)
712 145ca42a 2023-01-09 thomas tag_name += 5;
714 fdd79f2f 2023-09-12 thomas <header class="subtitle">
715 fdd79f2f 2023-09-12 thomas <h2>Tag</h2>
716 fdd79f2f 2023-09-12 thomas </header>
717 145ca42a 2023-01-09 thomas <div id="tags_content">
718 145ca42a 2023-01-09 thomas <div id="tag_header_wrapper">
719 fdd79f2f 2023-09-12 thomas <dl id="tag_header">
720 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
722 fdd79f2f 2023-09-12 thomas <code class="commit-id">{{ rt->commit_id }}</code>
723 145ca42a 2023-01-09 thomas {{ " " }}
724 145ca42a 2023-01-09 thomas <span class="refs_str">({{ tag_name }})</span>
726 fdd79f2f 2023-09-12 thomas <dt>Tagger:</dt>
727 fdd79f2f 2023-09-12 thomas <dd>{{ rt->tagger }}</dd>
728 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
730 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
732 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
733 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rt->commit_msg }}</dd>
736 fdd79f2f 2023-09-12 thomas <pre id="tag_commit">
737 145ca42a 2023-01-09 thomas {{ rt->tag_commit }}
741 dccd05b4 2023-01-10 thomas {{ end }}
743 161663e7 2023-03-11 thomas {{ define gotweb_render_diff(struct template *tp) }}
745 dccd05b4 2023-01-10 thomas struct request *c = tp->tp_arg;
746 dccd05b4 2023-01-10 thomas struct transport *t = c->t;
747 161663e7 2023-03-11 thomas FILE *fp = t->fp;
748 dccd05b4 2023-01-10 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
749 dccd05b4 2023-01-10 thomas char *line = NULL;
750 dccd05b4 2023-01-10 thomas size_t linesize = 0;
751 dccd05b4 2023-01-10 thomas ssize_t linelen;
753 fdd79f2f 2023-09-12 thomas <header class="subtitle">
754 fdd79f2f 2023-09-12 thomas <h2>Commit Diff</h2>
755 fdd79f2f 2023-09-12 thomas </header>
756 dccd05b4 2023-01-10 thomas <div id="diff_content">
757 dccd05b4 2023-01-10 thomas <div id="diff_header_wrapper">
758 fdd79f2f 2023-09-12 thomas <dl id="diff_header">
759 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
760 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
761 fdd79f2f 2023-09-12 thomas <dt>From:</dt>
762 fdd79f2f 2023-09-12 thomas <dd>{{ rc->author }}</dd>
763 f7ee7604 2023-01-14 thomas {{ if strcmp(rc->committer, rc->author) != 0 }}
764 fdd79f2f 2023-09-12 thomas <dt>Via:</dt>
765 fdd79f2f 2023-09-12 thomas <dd>{{ rc->committer }}</dd>
766 f7ee7604 2023-01-14 thomas {{ end }}
767 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
769 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
771 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
772 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
776 fdd79f2f 2023-09-12 thomas <pre id="diff">
777 dccd05b4 2023-01-10 thomas {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
778 dccd05b4 2023-01-10 thomas {{ render diff_line(tp, line) }}
779 dccd05b4 2023-01-10 thomas {{ end }}
782 dccd05b4 2023-01-10 thomas {{ finally }}
783 dccd05b4 2023-01-10 thomas {! free(line); !}
784 145ca42a 2023-01-09 thomas {{ end }}
786 dccd05b4 2023-01-10 thomas {{ define diff_line(struct template *tp, char *line )}}
788 dccd05b4 2023-01-10 thomas const char *color = NULL;
789 dccd05b4 2023-01-10 thomas char *nl;
791 dccd05b4 2023-01-10 thomas if (!strncmp(line, "-", 1))
792 dccd05b4 2023-01-10 thomas color = "diff_minus";
793 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "+", 1))
794 dccd05b4 2023-01-10 thomas color = "diff_plus";
795 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "@@", 2))
796 dccd05b4 2023-01-10 thomas color = "diff_chunk_header";
797 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "commit +", 8) ||
798 dccd05b4 2023-01-10 thomas !strncmp(line, "commit -", 8) ||
799 dccd05b4 2023-01-10 thomas !strncmp(line, "blob +", 6) ||
800 dccd05b4 2023-01-10 thomas !strncmp(line, "blob -", 6) ||
801 dccd05b4 2023-01-10 thomas !strncmp(line, "file +", 6) ||
802 dccd05b4 2023-01-10 thomas !strncmp(line, "file -", 6))
803 dccd05b4 2023-01-10 thomas color = "diff_meta";
804 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
805 dccd05b4 2023-01-10 thomas color = "diff_author";
806 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "date:", 5))
807 dccd05b4 2023-01-10 thomas color = "diff_date";
809 dccd05b4 2023-01-10 thomas nl = strchr(line, '\n');
811 dccd05b4 2023-01-10 thomas *nl = '\0';
813 fdd79f2f 2023-09-12 thomas <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
814 dccd05b4 2023-01-10 thomas {{ end }}
816 00abe30b 2023-01-14 thomas {{ define gotweb_render_branches(struct template *tp,
817 00abe30b 2023-01-14 thomas struct got_reflist_head *refs) }}
819 00abe30b 2023-01-14 thomas struct got_reflist_entry *re;
821 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
822 fdd79f2f 2023-09-12 thomas <h2>Branches</h2>
823 fdd79f2f 2023-09-12 thomas </header>
824 00abe30b 2023-01-14 thomas <div id="branches_content">
825 00abe30b 2023-01-14 thomas {{ tailq-foreach re refs entry }}
826 00abe30b 2023-01-14 thomas {{ if !got_ref_is_symbolic(re->ref) }}
827 00abe30b 2023-01-14 thomas {{ render branch(tp, re) }}
828 00abe30b 2023-01-14 thomas {{ end }}
829 00abe30b 2023-01-14 thomas {{ end }}
831 00abe30b 2023-01-14 thomas {{ end }}
833 00abe30b 2023-01-14 thomas {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
835 00abe30b 2023-01-14 thomas const struct got_error *err;
836 00abe30b 2023-01-14 thomas struct request *c = tp->tp_arg;
837 00abe30b 2023-01-14 thomas struct querystring *qs = c->t->qs;
838 00abe30b 2023-01-14 thomas const char *refname;
839 53bf32b8 2023-01-23 thomas time_t age;
840 00abe30b 2023-01-14 thomas struct gotweb_url url = {
841 00abe30b 2023-01-14 thomas .action = SUMMARY,
842 00abe30b 2023-01-14 thomas .index_page = -1,
843 00abe30b 2023-01-14 thomas .page = -1,
844 00abe30b 2023-01-14 thomas .path = qs->path,
847 00abe30b 2023-01-14 thomas refname = got_ref_get_name(re->ref);
849 53bf32b8 2023-01-23 thomas err = got_get_repo_age(&age, c, refname);
850 00abe30b 2023-01-14 thomas if (err) {
851 00abe30b 2023-01-14 thomas log_warnx("%s: %s", __func__, err->msg);
852 00abe30b 2023-01-14 thomas return -1;
855 00abe30b 2023-01-14 thomas if (strncmp(refname, "refs/heads/", 11) == 0)
856 00abe30b 2023-01-14 thomas refname += 11;
858 00abe30b 2023-01-14 thomas url.headref = refname;
860 fdd79f2f 2023-09-12 thomas <section class="branches_wrapper">
861 53bf32b8 2023-01-23 thomas <div class="branches_age">
862 4cc0851e 2023-10-08 thomas {{ render datetime(tp, age, TM_DIFF) }}
864 00abe30b 2023-01-14 thomas <div class="branch">
865 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
867 00abe30b 2023-01-14 thomas <div class="navs_wrapper">
868 00abe30b 2023-01-14 thomas <div class="navs">
869 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
870 00abe30b 2023-01-14 thomas {{" | "}}
871 00abe30b 2023-01-14 thomas {! url.action = BRIEFS; !}
872 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
873 00abe30b 2023-01-14 thomas {{" | "}}
874 00abe30b 2023-01-14 thomas {! url.action = COMMITS; !}
875 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
879 fdd79f2f 2023-09-12 thomas </section>
880 18e466eb 2023-01-14 thomas {{ end }}
882 161663e7 2023-03-11 thomas {{ define gotweb_render_summary(struct template *tp) }}
884 18e466eb 2023-01-14 thomas struct request *c = tp->tp_arg;
885 18e466eb 2023-01-14 thomas struct server *srv = c->srv;
886 18e466eb 2023-01-14 thomas struct transport *t = c->t;
887 161663e7 2023-03-11 thomas struct got_reflist_head *refs = &t->refs;
889 fdd79f2f 2023-09-12 thomas <dl id="summary_wrapper">
890 18e466eb 2023-01-14 thomas {{ if srv->show_repo_description }}
891 fdd79f2f 2023-09-12 thomas <dt>Description:</dt>
892 fdd79f2f 2023-09-12 thomas <dd>{{ t->repo_dir->description }}</dd>
893 18e466eb 2023-01-14 thomas {{ end }}
894 18e466eb 2023-01-14 thomas {{ if srv->show_repo_owner }}
895 fdd79f2f 2023-09-12 thomas <dt>Owner:</dt>
896 fdd79f2f 2023-09-12 thomas <dd>{{ t->repo_dir->owner }}</dd>
897 18e466eb 2023-01-14 thomas {{ end }}
898 18e466eb 2023-01-14 thomas {{ if srv->show_repo_age }}
899 fdd79f2f 2023-09-12 thomas <dt>Last Change:</dt>
901 4cc0851e 2023-10-08 thomas {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
903 18e466eb 2023-01-14 thomas {{ end }}
904 18e466eb 2023-01-14 thomas {{ if srv->show_repo_cloneurl }}
905 fdd79f2f 2023-09-12 thomas <dt>Clone URL:</dt>
906 fdd79f2f 2023-09-12 thomas <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
907 18e466eb 2023-01-14 thomas {{ end }}
909 18e466eb 2023-01-14 thomas {{ render gotweb_render_briefs(tp) }}
910 18e466eb 2023-01-14 thomas {{ render gotweb_render_tags(tp) }}
911 18e466eb 2023-01-14 thomas {{ render gotweb_render_branches(tp, refs) }}
912 00abe30b 2023-01-14 thomas {{ end }}
914 1cd5d437 2023-01-15 thomas {{ define gotweb_render_blame(struct template *tp) }}
916 1cd5d437 2023-01-15 thomas const struct got_error *err;
917 1cd5d437 2023-01-15 thomas struct request *c = tp->tp_arg;
918 1cd5d437 2023-01-15 thomas struct transport *t = c->t;
919 1cd5d437 2023-01-15 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
921 fdd79f2f 2023-09-12 thomas <header class="subtitle">
922 fdd79f2f 2023-09-12 thomas <h2>Blame</h2>
923 fdd79f2f 2023-09-12 thomas </header>
924 1cd5d437 2023-01-15 thomas <div id="blame_content">
925 1cd5d437 2023-01-15 thomas <div id="blame_header_wrapper">
926 fdd79f2f 2023-09-12 thomas <dl id="blame_header">
927 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
929 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
931 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
932 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
936 fdd79f2f 2023-09-12 thomas <pre id="blame">
938 1cd5d437 2023-01-15 thomas err = got_output_file_blame(c, &blame_line);
939 aa2aecab 2023-05-25 thomas if (err && err->code != GOT_ERR_CANCELLED)
940 1cd5d437 2023-01-15 thomas log_warnx("%s: got_output_file_blame: %s", __func__,
941 1cd5d437 2023-01-15 thomas err->msg);
943 1cd5d437 2023-01-15 thomas return (-1);
947 1cd5d437 2023-01-15 thomas {{ end }}
949 1cd5d437 2023-01-15 thomas {{ define blame_line(struct template *tp, const char *line,
950 1cd5d437 2023-01-15 thomas struct blame_line *bline, int lprec, int lcur) }}
952 1cd5d437 2023-01-15 thomas struct request *c = tp->tp_arg;
953 1cd5d437 2023-01-15 thomas struct transport *t = c->t;
954 1cd5d437 2023-01-15 thomas struct repo_dir *repo_dir = t->repo_dir;
955 1cd5d437 2023-01-15 thomas char *committer, *s;
956 1cd5d437 2023-01-15 thomas struct gotweb_url url = {
957 1cd5d437 2023-01-15 thomas .action = DIFF,
958 1cd5d437 2023-01-15 thomas .index_page = -1,
959 1cd5d437 2023-01-15 thomas .page = -1,
960 1cd5d437 2023-01-15 thomas .path = repo_dir->name,
961 1cd5d437 2023-01-15 thomas .commit = bline->id_str,
964 1cd5d437 2023-01-15 thomas s = strchr(bline->committer, '<');
965 1cd5d437 2023-01-15 thomas committer = s ? s + 1 : bline->committer;
967 1cd5d437 2023-01-15 thomas s = strchr(committer, '@');
969 1cd5d437 2023-01-15 thomas *s = '\0';
971 1cd5d437 2023-01-15 thomas <div class="blame_wrapper">
972 1cd5d437 2023-01-15 thomas <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
973 1cd5d437 2023-01-15 thomas <div class="blame_hash">
974 1cd5d437 2023-01-15 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
975 1cd5d437 2023-01-15 thomas {{ printf "%.8s", bline->id_str }}
978 1cd5d437 2023-01-15 thomas <div class="blame_date">{{ bline->datebuf }}</div>
979 1cd5d437 2023-01-15 thomas <div class="blame_author">{{ printf "%.9s", committer }}</div>
980 1cd5d437 2023-01-15 thomas <div class="blame_code">{{ line }}</div>
982 1cd5d437 2023-01-15 thomas {{ end }}
984 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
986 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
987 d6795e9f 2022-12-30 thomas struct server *srv = c->srv;
988 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
989 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
990 d6795e9f 2022-12-30 thomas struct repo_tag *rt;
991 d6795e9f 2022-12-30 thomas struct gotweb_url summary = {
992 d6795e9f 2022-12-30 thomas .action = SUMMARY,
993 d6795e9f 2022-12-30 thomas .index_page = -1,
994 d6795e9f 2022-12-30 thomas .page = -1,
995 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
998 d6795e9f 2022-12-30 thomas <?xml version="1.0" encoding="UTF-8"?>
999 d6795e9f 2022-12-30 thomas <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1000 d6795e9f 2022-12-30 thomas <channel>
1001 d6795e9f 2022-12-30 thomas <title>Tags of {{ repo_dir->name }}</title>
1003 d6795e9f 2022-12-30 thomas <![CDATA[
1004 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
1007 d6795e9f 2022-12-30 thomas {{ if srv->show_repo_description }}
1008 d6795e9f 2022-12-30 thomas <description>{{ repo_dir->description }}</description>
1009 d6795e9f 2022-12-30 thomas {{ end }}
1010 d6795e9f 2022-12-30 thomas {{ tailq-foreach rt &t->repo_tags entry }}
1011 d6795e9f 2022-12-30 thomas {{ render rss_tag_item(tp, rt) }}
1012 d6795e9f 2022-12-30 thomas {{ end }}
1013 d6795e9f 2022-12-30 thomas </channel>
1015 d6795e9f 2022-12-30 thomas {{ end }}
1017 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1019 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
1020 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
1021 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
1022 10fa70e2 2023-10-08 thomas struct tm tm;
1023 10fa70e2 2023-10-08 thomas char rfc822[128];
1025 d6795e9f 2022-12-30 thomas char *tag_name = rt->tag_name;
1026 d6795e9f 2022-12-30 thomas struct gotweb_url tag = {
1027 d6795e9f 2022-12-30 thomas .action = TAG,
1028 d6795e9f 2022-12-30 thomas .index_page = -1,
1029 d6795e9f 2022-12-30 thomas .page = -1,
1030 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
1031 d6795e9f 2022-12-30 thomas .commit = rt->commit_id,
1034 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
1035 d6795e9f 2022-12-30 thomas tag_name += 10;
1037 10fa70e2 2023-10-08 thomas if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1038 10fa70e2 2023-10-08 thomas return -1;
1039 10fa70e2 2023-10-08 thomas r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1040 10fa70e2 2023-10-08 thomas if (r == 0)
1041 10fa70e2 2023-10-08 thomas return 0;
1044 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1046 d6795e9f 2022-12-30 thomas <![CDATA[
1047 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
1050 d6795e9f 2022-12-30 thomas <description>
1051 d6795e9f 2022-12-30 thomas <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1052 d6795e9f 2022-12-30 thomas </description>
1053 d6795e9f 2022-12-30 thomas {{ render rss_author(tp, rt->tagger) }}
1054 d6795e9f 2022-12-30 thomas <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1055 d6795e9f 2022-12-30 thomas <pubDate>
1056 10fa70e2 2023-10-08 thomas {{ rfc822 }}
1057 d6795e9f 2022-12-30 thomas </pubDate>
1059 7ade8b27 2022-12-30 thomas {{ end }}
1061 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
1063 d6795e9f 2022-12-30 thomas char *t, *mail;
1065 d6795e9f 2022-12-30 thomas /* what to do if the author name contains a paren? */
1066 d6795e9f 2022-12-30 thomas if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1067 d6795e9f 2022-12-30 thomas return 0;
1069 d6795e9f 2022-12-30 thomas t = strchr(author, '<');
1070 d6795e9f 2022-12-30 thomas if (t == NULL)
1071 d6795e9f 2022-12-30 thomas return 0;
1072 d6795e9f 2022-12-30 thomas *t = '\0';
1073 d6795e9f 2022-12-30 thomas mail = t+1;
1075 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
1076 d6795e9f 2022-12-30 thomas *t = '\0';
1078 d6795e9f 2022-12-30 thomas t = strchr(mail, '>');
1079 d6795e9f 2022-12-30 thomas if (t == NULL)
1080 d6795e9f 2022-12-30 thomas return 0;
1081 d6795e9f 2022-12-30 thomas *t = '\0';
1083 d6795e9f 2022-12-30 thomas <author>
1084 d6795e9f 2022-12-30 thomas {{ mail }} {{" "}} ({{ author }})
1085 d6795e9f 2022-12-30 thomas </author>
1086 d6795e9f 2022-12-30 thomas {{ end }}