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