Blame


1 e7e5fa49 2022-12-30 thomas {!
2 e7e5fa49 2022-12-30 thomas /*
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>
5 e7e5fa49 2022-12-30 thomas *
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.
9 e7e5fa49 2022-12-30 thomas *
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.
17 e7e5fa49 2022-12-30 thomas */
18 4fccd2fe 2023-03-08 thomas
19 4fccd2fe 2023-03-08 thomas #include "got_compat.h"
20 e7e5fa49 2022-12-30 thomas
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>
24 e7e5fa49 2022-12-30 thomas
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>
32 e7e5fa49 2022-12-30 thomas
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"
36 3c14c1f2 2023-01-06 thomas
37 e7e5fa49 2022-12-30 thomas #include "proc.h"
38 e7e5fa49 2022-12-30 thomas
39 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
40 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
41 e7e5fa49 2022-12-30 thomas
42 4cc0851e 2023-10-08 thomas enum gotweb_ref_tm {
43 4cc0851e 2023-10-08 thomas TM_DIFF,
44 4cc0851e 2023-10-08 thomas TM_LONG,
45 4cc0851e 2023-10-08 thomas };
46 4cc0851e 2023-10-08 thomas
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);
52 20bab626 2023-02-03 thomas
53 20bab626 2023-02-03 thomas static inline int gotweb_render_more(struct template *, int);
54 b82440e1 2023-01-06 thomas
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 *);
60 d6795e9f 2022-12-30 thomas
61 e7e5fa49 2022-12-30 thomas !}
62 4cc0851e 2023-10-08 thomas
63 4cc0851e 2023-10-08 thomas {{ define datetime(struct template *tp, time_t t, int fmt) }}
64 4cc0851e 2023-10-08 thomas {!
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];
68 4cc0851e 2023-10-08 thomas
69 4cc0851e 2023-10-08 thomas if (gmtime_r(&t, &tm) == NULL)
70 4cc0851e 2023-10-08 thomas return -1;
71 4cc0851e 2023-10-08 thomas
72 4cc0851e 2023-10-08 thomas if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
73 4cc0851e 2023-10-08 thomas return -1;
74 4cc0851e 2023-10-08 thomas
75 4cc0851e 2023-10-08 thomas if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
76 4cc0851e 2023-10-08 thomas return -1;
77 4cc0851e 2023-10-08 thomas !}
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" }}
83 4cc0851e 2023-10-08 thomas {{ end }}
84 4cc0851e 2023-10-08 thomas </time>
85 4cc0851e 2023-10-08 thomas {{ end }}
86 e7e5fa49 2022-12-30 thomas
87 161663e7 2023-03-11 thomas {{ define gotweb_render_page(struct template *tp,
88 161663e7 2023-03-11 thomas int (*body)(struct template *)) }}
89 e7e5fa49 2022-12-30 thomas {!
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;
96 e7e5fa49 2022-12-30 thomas
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;
101 e7e5fa49 2022-12-30 thomas !}
102 e7e5fa49 2022-12-30 thomas <!doctype html>
103 e7e5fa49 2022-12-30 thomas <html>
104 e7e5fa49 2022-12-30 thomas <head>
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 }}" />
116 e7e5fa49 2022-12-30 thomas </head>
117 e7e5fa49 2022-12-30 thomas <body>
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 }}" />
122 fdd79f2f 2023-09-12 thomas </a>
123 e7e5fa49 2022-12-30 thomas </div>
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 }}
129 fdd79f2f 2023-09-12 thomas </a>
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 }}
135 e7e5fa49 2022-12-30 thomas </a>
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 }}
140 e7e5fa49 2022-12-30 thomas </div>
141 fdd79f2f 2023-09-12 thomas </nav>
142 fdd79f2f 2023-09-12 thomas <main>
143 fdd79f2f 2023-09-12 thomas {{ render body(tp) }}
144 fdd79f2f 2023-09-12 thomas </main>
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 }}
150 fdd79f2f 2023-09-12 thomas </p>
151 fdd79f2f 2023-09-12 thomas </footer>
152 e7e5fa49 2022-12-30 thomas </body>
153 e7e5fa49 2022-12-30 thomas </html>
154 164b5ddc 2023-03-11 thomas {{ end }}
155 164b5ddc 2023-03-11 thomas
156 164b5ddc 2023-03-11 thomas {{ define gotweb_render_error(struct template *tp) }}
157 164b5ddc 2023-03-11 thomas {!
158 164b5ddc 2023-03-11 thomas struct request *c = tp->tp_arg;
159 164b5ddc 2023-03-11 thomas struct transport *t = c->t;
160 164b5ddc 2023-03-11 thomas !}
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 }}
167 164b5ddc 2023-03-11 thomas </div>
168 e7e5fa49 2022-12-30 thomas {{ end }}
169 e7e5fa49 2022-12-30 thomas
170 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
171 e7e5fa49 2022-12-30 thomas {!
172 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
173 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
174 e7e5fa49 2022-12-30 thomas !}
175 e7e5fa49 2022-12-30 thomas <div id="index_header">
176 fdd79f2f 2023-09-12 thomas <div class="index_project">
177 e7e5fa49 2022-12-30 thomas Project
178 e7e5fa49 2022-12-30 thomas </div>
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
182 e7e5fa49 2022-12-30 thomas </div>
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">
186 e7e5fa49 2022-12-30 thomas Owner
187 e7e5fa49 2022-12-30 thomas </div>
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
192 e7e5fa49 2022-12-30 thomas </div>
193 e7e5fa49 2022-12-30 thomas {{ end }}
194 e7e5fa49 2022-12-30 thomas </div>
195 e7e5fa49 2022-12-30 thomas {{ end }}
196 e7e5fa49 2022-12-30 thomas
197 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
198 e7e5fa49 2022-12-30 thomas {!
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,
231 e7e5fa49 2022-12-30 thomas };
232 e7e5fa49 2022-12-30 thomas !}
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>
236 e7e5fa49 2022-12-30 thomas </div>
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 }}
240 e7e5fa49 2022-12-30 thomas </div>
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 }}
245 e7e5fa49 2022-12-30 thomas </div>
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) }}
250 e7e5fa49 2022-12-30 thomas </div>
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>
265 e7e5fa49 2022-12-30 thomas </div>
266 fdd79f2f 2023-09-12 thomas <hr />
267 e7e5fa49 2022-12-30 thomas </div>
268 e7e5fa49 2022-12-30 thomas </div>
269 e7e5fa49 2022-12-30 thomas {{ end }}
270 e7e5fa49 2022-12-30 thomas
271 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
272 e7e5fa49 2022-12-30 thomas {!
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;
280 e7e5fa49 2022-12-30 thomas
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,
287 e7e5fa49 2022-12-30 thomas };
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,
294 e7e5fa49 2022-12-30 thomas };
295 e7e5fa49 2022-12-30 thomas !}
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 }}
301 e7e5fa49 2022-12-30 thomas {!
302 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
303 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
304 e7e5fa49 2022-12-30 thomas
305 64d39587 2023-01-14 thomas tmp = strchr(rc->committer, '<');
306 e7e5fa49 2022-12-30 thomas if (tmp)
307 e7e5fa49 2022-12-30 thomas *tmp = '\0';
308 e7e5fa49 2022-12-30 thomas
309 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
310 e7e5fa49 2022-12-30 thomas if (tmp)
311 e7e5fa49 2022-12-30 thomas *tmp = '\0';
312 e7e5fa49 2022-12-30 thomas !}
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) }}
317 fdd79f2f 2023-09-12 thomas </span>
318 fdd79f2f 2023-09-12 thomas {{" "}}
319 fdd79f2f 2023-09-12 thomas <span class="briefs_author">
320 fdd79f2f 2023-09-12 thomas {{ rc->committer }}
321 fdd79f2f 2023-09-12 thomas </span>
322 fdd79f2f 2023-09-12 thomas </p>
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 }}
326 fdd79f2f 2023-09-12 thomas </a>
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 }}
330 fdd79f2f 2023-09-12 thomas </a>
331 fdd79f2f 2023-09-12 thomas </p>
332 e7e5fa49 2022-12-30 thomas </div>
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>
338 e7e5fa49 2022-12-30 thomas </div>
339 e7e5fa49 2022-12-30 thomas </div>
340 fdd79f2f 2023-09-12 thomas <hr />
341 e7e5fa49 2022-12-30 thomas {{ end }}
342 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, BRIEFS) }}
343 2f4f0731 2022-12-30 thomas </div>
344 2f4f0731 2022-12-30 thomas {{ end }}
345 2f4f0731 2022-12-30 thomas
346 20bab626 2023-02-03 thomas {{ define gotweb_render_more(struct template *tp, int action) }}
347 20bab626 2023-02-03 thomas {!
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,
358 20bab626 2023-02-03 thomas };
359 20bab626 2023-02-03 thomas !}
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&nbsp;&darr;
365 20bab626 2023-02-03 thomas </a>
366 20bab626 2023-02-03 thomas </div>
367 20bab626 2023-02-03 thomas </div>
368 20bab626 2023-02-03 thomas {{ end }}
369 20bab626 2023-02-03 thomas {{ end }}
370 20bab626 2023-02-03 thomas
371 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
372 2f4f0731 2022-12-30 thomas {!
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;
377 2f4f0731 2022-12-30 thomas
378 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
379 2f4f0731 2022-12-30 thomas !}
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) }}">
384 2f4f0731 2022-12-30 thomas Previous
385 2f4f0731 2022-12-30 thomas </a>
386 2f4f0731 2022-12-30 thomas {{ end }}
387 2f4f0731 2022-12-30 thomas </div>
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) }}">
391 2f4f0731 2022-12-30 thomas Next
392 2f4f0731 2022-12-30 thomas </a>
393 2f4f0731 2022-12-30 thomas {{ end }}
394 2f4f0731 2022-12-30 thomas </div>
395 e7e5fa49 2022-12-30 thomas </div>
396 2f4f0731 2022-12-30 thomas {{ finally }}
397 2f4f0731 2022-12-30 thomas {!
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;
402 2f4f0731 2022-12-30 thomas !}
403 e7e5fa49 2022-12-30 thomas {{ end }}
404 7ade8b27 2022-12-30 thomas
405 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
406 7ade8b27 2022-12-30 thomas {!
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;
412 7ade8b27 2022-12-30 thomas
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,
418 7ade8b27 2022-12-30 thomas };
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,
424 7ade8b27 2022-12-30 thomas };
425 7ade8b27 2022-12-30 thomas !}
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 }}
431 7ade8b27 2022-12-30 thomas {!
432 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
433 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
434 7ade8b27 2022-12-30 thomas !}
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>
446 fdd79f2f 2023-09-12 thomas <dd>
447 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
448 fdd79f2f 2023-09-12 thomas </dd>
449 fdd79f2f 2023-09-12 thomas </dl>
450 7ade8b27 2022-12-30 thomas </div>
451 fdd79f2f 2023-09-12 thomas <hr />
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 }}
455 bbf94fd6 2023-01-02 thomas </div>
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>
461 7ade8b27 2022-12-30 thomas </div>
462 7ade8b27 2022-12-30 thomas </div>
463 fdd79f2f 2023-09-12 thomas <hr />
464 7ade8b27 2022-12-30 thomas {{ end }}
465 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, COMMITS) }}
466 b82440e1 2023-01-06 thomas </div>
467 b82440e1 2023-01-06 thomas {{ end }}
468 b82440e1 2023-01-06 thomas
469 161663e7 2023-03-11 thomas {{ define gotweb_render_blob(struct template *tp) }}
470 b82440e1 2023-01-06 thomas {!
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);
475 b82440e1 2023-01-06 thomas !}
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>
483 fdd79f2f 2023-09-12 thomas <dd>
484 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
485 fdd79f2f 2023-09-12 thomas </dd>
486 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
487 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
488 fdd79f2f 2023-09-12 thomas </dl>
489 b82440e1 2023-01-06 thomas </div>
490 fdd79f2f 2023-09-12 thomas <hr />
491 b82440e1 2023-01-06 thomas <div id="blob">
492 b82440e1 2023-01-06 thomas <pre>
493 b82440e1 2023-01-06 thomas {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
494 b82440e1 2023-01-06 thomas </pre>
495 b82440e1 2023-01-06 thomas </div>
496 7ade8b27 2022-12-30 thomas </div>
497 d6795e9f 2022-12-30 thomas {{ end }}
498 d6795e9f 2022-12-30 thomas
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) }}
501 b82440e1 2023-01-06 thomas {!
502 b82440e1 2023-01-06 thomas char lineno[16];
503 b82440e1 2023-01-06 thomas int r;
504 b82440e1 2023-01-06 thomas
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;
508 b82440e1 2023-01-06 thomas !}
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>
512 3c14c1f2 2023-01-06 thomas </div>
513 3c14c1f2 2023-01-06 thomas {{ end }}
514 3c14c1f2 2023-01-06 thomas
515 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree(struct template *tp) }}
516 3c14c1f2 2023-01-06 thomas {!
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);
520 3c14c1f2 2023-01-06 thomas !}
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>
530 fdd79f2f 2023-09-12 thomas <dd>
531 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
532 fdd79f2f 2023-09-12 thomas </dd>
533 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
534 cbe7b7d7 2023-10-08 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
535 fdd79f2f 2023-09-12 thomas </dl>
536 3c14c1f2 2023-01-06 thomas </div>
537 fdd79f2f 2023-09-12 thomas <hr />
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) }}
540 fdd79f2f 2023-09-12 thomas </table>
541 3c14c1f2 2023-01-06 thomas </div>
542 3c14c1f2 2023-01-06 thomas {{ end }}
543 3c14c1f2 2023-01-06 thomas
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) }}
546 3c14c1f2 2023-01-06 thomas {!
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,
561 3c14c1f2 2023-01-06 thomas };
562 3c14c1f2 2023-01-06 thomas
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);
565 3c14c1f2 2023-01-06 thomas
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);
570 3c14c1f2 2023-01-06 thomas
571 3c14c1f2 2023-01-06 thomas url.action = TREE;
572 3c14c1f2 2023-01-06 thomas url.folder = dir;
573 3c14c1f2 2023-01-06 thomas } else {
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;
577 3c14c1f2 2023-01-06 thomas }
578 3c14c1f2 2023-01-06 thomas
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 = "*";
587 3c14c1f2 2023-01-06 thomas !}
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 }}
593 3c14c1f2 2023-01-06 thomas </a>
594 fdd79f2f 2023-09-12 thomas </td>
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 }}
599 3c14c1f2 2023-01-06 thomas </a>
600 fdd79f2f 2023-09-12 thomas </td>
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) }}">
604 3c14c1f2 2023-01-06 thomas commits
605 3c14c1f2 2023-01-06 thomas </a>
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) }}">
609 3c14c1f2 2023-01-06 thomas blame
610 3c14c1f2 2023-01-06 thomas </a>
611 fdd79f2f 2023-09-12 thomas </td>
612 3c14c1f2 2023-01-06 thomas {{ end }}
613 fdd79f2f 2023-09-12 thomas </tr>
614 3c14c1f2 2023-01-06 thomas {{ finally }}
615 3c14c1f2 2023-01-06 thomas {!
616 3c14c1f2 2023-01-06 thomas free(dir);
617 617497a6 2023-01-09 thomas !}
618 617497a6 2023-01-09 thomas {{ end }}
619 617497a6 2023-01-09 thomas
620 b3ba36c3 2023-01-14 thomas {{ define gotweb_render_tags(struct template *tp) }}
621 617497a6 2023-01-09 thomas {!
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;
627 617497a6 2023-01-09 thomas
628 617497a6 2023-01-09 thomas commit_found = qs->commit == NULL;
629 3c14c1f2 2023-01-06 thomas !}
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
637 617497a6 2023-01-09 thomas </div>
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 }}
650 617497a6 2023-01-09 thomas </div>
651 b82440e1 2023-01-06 thomas {{ end }}
652 b82440e1 2023-01-06 thomas
653 617497a6 2023-01-09 thomas {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
654 617497a6 2023-01-09 thomas {!
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,
667 617497a6 2023-01-09 thomas };
668 617497a6 2023-01-09 thomas
669 617497a6 2023-01-09 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
670 617497a6 2023-01-09 thomas tag_name += 10;
671 617497a6 2023-01-09 thomas
672 617497a6 2023-01-09 thomas if (msg) {
673 617497a6 2023-01-09 thomas nl = strchr(msg, '\n');
674 617497a6 2023-01-09 thomas if (nl)
675 617497a6 2023-01-09 thomas *nl = '\0';
676 617497a6 2023-01-09 thomas }
677 617497a6 2023-01-09 thomas !}
678 617497a6 2023-01-09 thomas <div class="tag_age">
679 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
680 617497a6 2023-01-09 thomas </div>
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 }}
685 617497a6 2023-01-09 thomas </a>
686 617497a6 2023-01-09 thomas </div>
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>
696 617497a6 2023-01-09 thomas </div>
697 617497a6 2023-01-09 thomas </div>
698 fdd79f2f 2023-09-12 thomas <hr />
699 617497a6 2023-01-09 thomas {{ end }}
700 145ca42a 2023-01-09 thomas
701 145ca42a 2023-01-09 thomas {{ define gotweb_render_tag(struct template *tp) }}
702 145ca42a 2023-01-09 thomas {!
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;
707 617497a6 2023-01-09 thomas
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;
710 145ca42a 2023-01-09 thomas
711 145ca42a 2023-01-09 thomas if (strncmp(tag_name, "refs/", 5) == 0)
712 145ca42a 2023-01-09 thomas tag_name += 5;
713 145ca42a 2023-01-09 thomas !}
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>
721 fdd79f2f 2023-09-12 thomas <dd>
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>
725 fdd79f2f 2023-09-12 thomas </dd>
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>
729 fdd79f2f 2023-09-12 thomas <dd>
730 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
731 fdd79f2f 2023-09-12 thomas </dd>
732 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
733 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rt->commit_msg }}</dd>
734 fdd79f2f 2023-09-12 thomas </dl>
735 fdd79f2f 2023-09-12 thomas <hr />
736 fdd79f2f 2023-09-12 thomas <pre id="tag_commit">
737 145ca42a 2023-01-09 thomas {{ rt->tag_commit }}
738 fdd79f2f 2023-09-12 thomas </pre>
739 dccd05b4 2023-01-10 thomas </div>
740 dccd05b4 2023-01-10 thomas </div>
741 dccd05b4 2023-01-10 thomas {{ end }}
742 dccd05b4 2023-01-10 thomas
743 161663e7 2023-03-11 thomas {{ define gotweb_render_diff(struct template *tp) }}
744 dccd05b4 2023-01-10 thomas {!
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;
752 dccd05b4 2023-01-10 thomas !}
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>
768 fdd79f2f 2023-09-12 thomas <dd>
769 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
770 fdd79f2f 2023-09-12 thomas </dd>
771 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
772 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
773 fdd79f2f 2023-09-12 thomas </dl>
774 145ca42a 2023-01-09 thomas </div>
775 fdd79f2f 2023-09-12 thomas <hr />
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 }}
780 fdd79f2f 2023-09-12 thomas </pre>
781 145ca42a 2023-01-09 thomas </div>
782 dccd05b4 2023-01-10 thomas {{ finally }}
783 dccd05b4 2023-01-10 thomas {! free(line); !}
784 145ca42a 2023-01-09 thomas {{ end }}
785 145ca42a 2023-01-09 thomas
786 dccd05b4 2023-01-10 thomas {{ define diff_line(struct template *tp, char *line )}}
787 dccd05b4 2023-01-10 thomas {!
788 dccd05b4 2023-01-10 thomas const char *color = NULL;
789 dccd05b4 2023-01-10 thomas char *nl;
790 dccd05b4 2023-01-10 thomas
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";
808 dccd05b4 2023-01-10 thomas
809 dccd05b4 2023-01-10 thomas nl = strchr(line, '\n');
810 dccd05b4 2023-01-10 thomas if (nl)
811 dccd05b4 2023-01-10 thomas *nl = '\0';
812 dccd05b4 2023-01-10 thomas !}
813 fdd79f2f 2023-09-12 thomas <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
814 dccd05b4 2023-01-10 thomas {{ end }}
815 dccd05b4 2023-01-10 thomas
816 00abe30b 2023-01-14 thomas {{ define gotweb_render_branches(struct template *tp,
817 00abe30b 2023-01-14 thomas struct got_reflist_head *refs) }}
818 00abe30b 2023-01-14 thomas {!
819 00abe30b 2023-01-14 thomas struct got_reflist_entry *re;
820 00abe30b 2023-01-14 thomas !}
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 }}
830 00abe30b 2023-01-14 thomas </div>
831 00abe30b 2023-01-14 thomas {{ end }}
832 00abe30b 2023-01-14 thomas
833 00abe30b 2023-01-14 thomas {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
834 00abe30b 2023-01-14 thomas {!
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,
845 00abe30b 2023-01-14 thomas };
846 00abe30b 2023-01-14 thomas
847 00abe30b 2023-01-14 thomas refname = got_ref_get_name(re->ref);
848 00abe30b 2023-01-14 thomas
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;
853 00abe30b 2023-01-14 thomas }
854 00abe30b 2023-01-14 thomas
855 00abe30b 2023-01-14 thomas if (strncmp(refname, "refs/heads/", 11) == 0)
856 00abe30b 2023-01-14 thomas refname += 11;
857 00abe30b 2023-01-14 thomas
858 00abe30b 2023-01-14 thomas url.headref = refname;
859 00abe30b 2023-01-14 thomas !}
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) }}
863 53bf32b8 2023-01-23 thomas </div>
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>
866 00abe30b 2023-01-14 thomas </div>
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>
876 00abe30b 2023-01-14 thomas </div>
877 00abe30b 2023-01-14 thomas </div>
878 fdd79f2f 2023-09-12 thomas <hr />
879 fdd79f2f 2023-09-12 thomas </section>
880 18e466eb 2023-01-14 thomas {{ end }}
881 18e466eb 2023-01-14 thomas
882 161663e7 2023-03-11 thomas {{ define gotweb_render_summary(struct template *tp) }}
883 18e466eb 2023-01-14 thomas {!
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;
888 18e466eb 2023-01-14 thomas !}
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>
900 fdd79f2f 2023-09-12 thomas <dd>
901 4cc0851e 2023-10-08 thomas {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
902 fdd79f2f 2023-09-12 thomas </dd>
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 }}
908 fdd79f2f 2023-09-12 thomas </dl>
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 }}
913 00abe30b 2023-01-14 thomas
914 1cd5d437 2023-01-15 thomas {{ define gotweb_render_blame(struct template *tp) }}
915 1cd5d437 2023-01-15 thomas {!
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);
920 1cd5d437 2023-01-15 thomas !}
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>
928 fdd79f2f 2023-09-12 thomas <dd>
929 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
930 fdd79f2f 2023-09-12 thomas </dd>
931 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
932 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
933 fdd79f2f 2023-09-12 thomas </dl>
934 1cd5d437 2023-01-15 thomas </div>
935 fdd79f2f 2023-09-12 thomas <hr />
936 fdd79f2f 2023-09-12 thomas <pre id="blame">
937 1cd5d437 2023-01-15 thomas {!
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);
942 aa2aecab 2023-05-25 thomas if (err)
943 1cd5d437 2023-01-15 thomas return (-1);
944 1cd5d437 2023-01-15 thomas !}
945 fdd79f2f 2023-09-12 thomas </pre>
946 1cd5d437 2023-01-15 thomas </div>
947 1cd5d437 2023-01-15 thomas {{ end }}
948 1cd5d437 2023-01-15 thomas
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) }}
951 1cd5d437 2023-01-15 thomas {!
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,
962 1cd5d437 2023-01-15 thomas };
963 1cd5d437 2023-01-15 thomas
964 1cd5d437 2023-01-15 thomas s = strchr(bline->committer, '<');
965 1cd5d437 2023-01-15 thomas committer = s ? s + 1 : bline->committer;
966 1cd5d437 2023-01-15 thomas
967 1cd5d437 2023-01-15 thomas s = strchr(committer, '@');
968 1cd5d437 2023-01-15 thomas if (s)
969 1cd5d437 2023-01-15 thomas *s = '\0';
970 1cd5d437 2023-01-15 thomas !}
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 }}
976 1cd5d437 2023-01-15 thomas </a>
977 1cd5d437 2023-01-15 thomas </div>
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>
981 1cd5d437 2023-01-15 thomas </div>
982 1cd5d437 2023-01-15 thomas {{ end }}
983 1cd5d437 2023-01-15 thomas
984 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
985 d6795e9f 2022-12-30 thomas {!
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,
996 d6795e9f 2022-12-30 thomas };
997 d6795e9f 2022-12-30 thomas !}
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>
1002 d6795e9f 2022-12-30 thomas <link>
1003 d6795e9f 2022-12-30 thomas <![CDATA[
1004 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
1005 d6795e9f 2022-12-30 thomas ]]>
1006 d6795e9f 2022-12-30 thomas </link>
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>
1014 d6795e9f 2022-12-30 thomas </rss>
1015 d6795e9f 2022-12-30 thomas {{ end }}
1016 d6795e9f 2022-12-30 thomas
1017 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1018 d6795e9f 2022-12-30 thomas {!
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];
1024 10fa70e2 2023-10-08 thomas int r;
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,
1032 d6795e9f 2022-12-30 thomas };
1033 d6795e9f 2022-12-30 thomas
1034 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
1035 d6795e9f 2022-12-30 thomas tag_name += 10;
1036 10fa70e2 2023-10-08 thomas
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;
1042 d6795e9f 2022-12-30 thomas !}
1043 d6795e9f 2022-12-30 thomas <item>
1044 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1045 d6795e9f 2022-12-30 thomas <link>
1046 d6795e9f 2022-12-30 thomas <![CDATA[
1047 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
1048 d6795e9f 2022-12-30 thomas ]]>
1049 d6795e9f 2022-12-30 thomas </link>
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>
1058 d6795e9f 2022-12-30 thomas </item>
1059 7ade8b27 2022-12-30 thomas {{ end }}
1060 d6795e9f 2022-12-30 thomas
1061 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
1062 d6795e9f 2022-12-30 thomas {!
1063 d6795e9f 2022-12-30 thomas char *t, *mail;
1064 d6795e9f 2022-12-30 thomas
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;
1068 d6795e9f 2022-12-30 thomas
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;
1074 d6795e9f 2022-12-30 thomas
1075 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
1076 d6795e9f 2022-12-30 thomas *t = '\0';
1077 d6795e9f 2022-12-30 thomas
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';
1082 d6795e9f 2022-12-30 thomas !}
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 }}