Blame


1 ed619ca0 2022-12-14 op {!
2 ed619ca0 2022-12-14 op /*
3 ed619ca0 2022-12-14 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 ed619ca0 2022-12-14 op * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 ed619ca0 2022-12-14 op *
6 ed619ca0 2022-12-14 op * Permission to use, copy, modify, and distribute this software for any
7 ed619ca0 2022-12-14 op * purpose with or without fee is hereby granted, provided that the above
8 ed619ca0 2022-12-14 op * copyright notice and this permission notice appear in all copies.
9 ed619ca0 2022-12-14 op *
10 ed619ca0 2022-12-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 ed619ca0 2022-12-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 ed619ca0 2022-12-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ed619ca0 2022-12-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 ed619ca0 2022-12-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ed619ca0 2022-12-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 ed619ca0 2022-12-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ed619ca0 2022-12-14 op */
18 ed619ca0 2022-12-14 op
19 ed619ca0 2022-12-14 op #include <sys/types.h>
20 ed619ca0 2022-12-14 op #include <sys/queue.h>
21 43d421de 2023-01-05 op #include <sys/stat.h>
22 ed619ca0 2022-12-14 op
23 1abb18e1 2022-12-20 op #include <ctype.h>
24 ed619ca0 2022-12-14 op #include <event.h>
25 ed619ca0 2022-12-14 op #include <stdint.h>
26 43d421de 2023-01-05 op #include <stdio.h>
27 ed619ca0 2022-12-14 op #include <stdlib.h>
28 ed619ca0 2022-12-14 op #include <string.h>
29 43d421de 2023-01-05 op #include <sha1.h>
30 5822e79e 2023-02-23 op #include <sha2.h>
31 ed619ca0 2022-12-14 op #include <imsg.h>
32 ed619ca0 2022-12-14 op
33 3ab2c914 2023-01-11 op #include "got_error.h"
34 43d421de 2023-01-05 op #include "got_object.h"
35 3ab2c914 2023-01-11 op #include "got_reference.h"
36 ed619ca0 2022-12-14 op
37 ed619ca0 2022-12-14 op #include "gotwebd.h"
38 ed619ca0 2022-12-14 op #include "tmpl.h"
39 ed619ca0 2022-12-14 op
40 7781b991 2023-10-05 op enum gotweb_ref_tm {
41 7781b991 2023-10-05 op TM_DIFF,
42 7781b991 2023-10-05 op TM_LONG,
43 7781b991 2023-10-05 op };
44 7781b991 2023-10-05 op
45 c2abf03c 2023-11-30 op static int breadcumbs(struct template *);
46 7781b991 2023-10-05 op static int datetime(struct template *, time_t, int);
47 298f95fb 2023-01-05 op static int gotweb_render_blob_line(struct template *, const char *, size_t);
48 43d421de 2023-01-05 op static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
49 8319855f 2023-01-15 op static int blame_line(struct template *, const char *, struct blame_line *,
50 8319855f 2023-01-15 op int, int);
51 e3662697 2023-02-03 op
52 e3662697 2023-02-03 op static inline int gotweb_render_more(struct template *, int);
53 298f95fb 2023-01-05 op
54 587550a5 2023-01-10 op static inline int diff_line(struct template *, char *);
55 067396e6 2023-01-09 op static inline int tag_item(struct template *, struct repo_tag *);
56 3ab2c914 2023-01-11 op static inline int branch(struct template *, struct got_reflist_entry *);
57 1abb18e1 2022-12-20 op static inline int rss_tag_item(struct template *, struct repo_tag *);
58 1abb18e1 2022-12-20 op static inline int rss_author(struct template *, char *);
59 1abb18e1 2022-12-20 op
60 c2abf03c 2023-11-30 op static inline char *
61 c2abf03c 2023-11-30 op nextsep(char *s, char **t)
62 c2abf03c 2023-11-30 op {
63 c2abf03c 2023-11-30 op char *q;
64 c2abf03c 2023-11-30 op
65 c2abf03c 2023-11-30 op while (*s == '/')
66 c2abf03c 2023-11-30 op s++;
67 c2abf03c 2023-11-30 op *t = s;
68 c2abf03c 2023-11-30 op if (*s == '\0')
69 c2abf03c 2023-11-30 op return NULL;
70 c2abf03c 2023-11-30 op
71 c2abf03c 2023-11-30 op q = strchr(s, '/');
72 c2abf03c 2023-11-30 op if (q == NULL)
73 c2abf03c 2023-11-30 op q = strchr(s, '\0');
74 c2abf03c 2023-11-30 op return q;
75 c2abf03c 2023-11-30 op }
76 c2abf03c 2023-11-30 op
77 ed619ca0 2022-12-14 op !}
78 7781b991 2023-10-05 op
79 7781b991 2023-10-05 op {{ define datetime(struct template *tp, time_t t, int fmt) }}
80 7781b991 2023-10-05 op {!
81 7781b991 2023-10-05 op struct tm tm;
82 7781b991 2023-10-05 op char rfc3339[64];
83 7781b991 2023-10-05 op char datebuf[64];
84 7781b991 2023-10-05 op
85 7781b991 2023-10-05 op if (gmtime_r(&t, &tm) == NULL)
86 7781b991 2023-10-05 op return -1;
87 7781b991 2023-10-05 op
88 7781b991 2023-10-05 op if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
89 7781b991 2023-10-05 op return -1;
90 7781b991 2023-10-05 op
91 7781b991 2023-10-05 op if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
92 7781b991 2023-10-05 op return -1;
93 7781b991 2023-10-05 op !}
94 7781b991 2023-10-05 op <time datetime="{{ rfc3339 }}">
95 7781b991 2023-10-05 op {{ if fmt == TM_DIFF }}
96 7781b991 2023-10-05 op {{ render gotweb_render_age(tp, t) }}
97 7781b991 2023-10-05 op {{ else }}
98 7781b991 2023-10-05 op {{ datebuf }} {{ " UTC" }}
99 7781b991 2023-10-05 op {{ end }}
100 7781b991 2023-10-05 op </time>
101 7781b991 2023-10-05 op {{ end }}
102 ed619ca0 2022-12-14 op
103 c2abf03c 2023-11-30 op {{ define breadcumbs(struct template *tp) }}
104 c2abf03c 2023-11-30 op {!
105 c2abf03c 2023-11-30 op struct request *c = tp->tp_arg;
106 c2abf03c 2023-11-30 op struct querystring *qs = c->t->qs;
107 c2abf03c 2023-11-30 op struct gotweb_url url;
108 c2abf03c 2023-11-30 op const char *folder = qs->folder;
109 c2abf03c 2023-11-30 op char *t, *s = NULL, *dir = NULL;
110 c2abf03c 2023-11-30 op char ch;
111 c2abf03c 2023-11-30 op
112 c2abf03c 2023-11-30 op memset(&url, 0, sizeof(url));
113 c2abf03c 2023-11-30 op url.index_page = -1;
114 c2abf03c 2023-11-30 op url.page = -1;
115 c2abf03c 2023-11-30 op url.action = TREE;
116 c2abf03c 2023-11-30 op url.path = qs->path;
117 c2abf03c 2023-11-30 op url.commit = qs->commit;
118 c2abf03c 2023-11-30 op
119 c2abf03c 2023-11-30 op if (folder && *folder != '\0') {
120 c2abf03c 2023-11-30 op while (*folder == '/')
121 c2abf03c 2023-11-30 op folder++;
122 c2abf03c 2023-11-30 op dir = strdup(folder);
123 c2abf03c 2023-11-30 op if (dir == NULL)
124 c2abf03c 2023-11-30 op return (-1);
125 c2abf03c 2023-11-30 op s = dir;
126 c2abf03c 2023-11-30 op }
127 c2abf03c 2023-11-30 op !}
128 c2abf03c 2023-11-30 op {{ " / " }}
129 c2abf03c 2023-11-30 op <a href="{{ render gotweb_render_url(c, &url) }}">tree</a>
130 c2abf03c 2023-11-30 op {{ " / " }}
131 c2abf03c 2023-11-30 op {{ if dir }}
132 c2abf03c 2023-11-30 op {{ while (s = nextsep(s, &t)) != NULL }}
133 c2abf03c 2023-11-30 op {!
134 c2abf03c 2023-11-30 op ch = *s;
135 c2abf03c 2023-11-30 op *s = '\0';
136 c2abf03c 2023-11-30 op url.folder = dir;
137 c2abf03c 2023-11-30 op !}
138 c2abf03c 2023-11-30 op
139 c2abf03c 2023-11-30 op <a href="{{ render gotweb_render_url(c, &url) }}">
140 c2abf03c 2023-11-30 op {{ t }}
141 c2abf03c 2023-11-30 op </a>
142 c2abf03c 2023-11-30 op {{ " / " }}
143 c2abf03c 2023-11-30 op
144 c2abf03c 2023-11-30 op {! *s = ch; !}
145 c2abf03c 2023-11-30 op {{ end }}
146 c2abf03c 2023-11-30 op {{ end }}
147 c2abf03c 2023-11-30 op
148 c2abf03c 2023-11-30 op {{ if qs->file }}
149 c2abf03c 2023-11-30 op {{ qs->file }}
150 c2abf03c 2023-11-30 op {{ end}}
151 c2abf03c 2023-11-30 op
152 c2abf03c 2023-11-30 op {{ finally }}
153 c2abf03c 2023-11-30 op {! free(dir); !}
154 c2abf03c 2023-11-30 op {{ end }}
155 c2abf03c 2023-11-30 op
156 df2d3cd2 2023-03-11 op {{ define gotweb_render_page(struct template *tp,
157 df2d3cd2 2023-03-11 op int (*body)(struct template *)) }}
158 ed619ca0 2022-12-14 op {!
159 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
160 ed619ca0 2022-12-14 op struct server *srv = c->srv;
161 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
162 ed619ca0 2022-12-14 op struct gotweb_url u_path;
163 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
164 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
165 ed619ca0 2022-12-14 op
166 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
167 ed619ca0 2022-12-14 op u_path.index_page = -1;
168 ed619ca0 2022-12-14 op u_path.page = -1;
169 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
170 ed619ca0 2022-12-14 op !}
171 ed619ca0 2022-12-14 op <!doctype html>
172 ed619ca0 2022-12-14 op <html>
173 ed619ca0 2022-12-14 op <head>
174 ed619ca0 2022-12-14 op <meta charset="utf-8" />
175 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
176 424803ac 2023-09-12 op <meta name="viewport" content="initial-scale=1.0" />
177 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
178 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
179 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
180 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
181 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
182 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
183 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
184 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
185 ed619ca0 2022-12-14 op </head>
186 ed619ca0 2022-12-14 op <body>
187 424803ac 2023-09-12 op <header id="header">
188 424803ac 2023-09-12 op <div id="got_link">
189 424803ac 2023-09-12 op <a href="{{ srv->logo_url }}" target="_blank">
190 424803ac 2023-09-12 op <img src="{{ prfx }}{{ srv->logo }}" />
191 424803ac 2023-09-12 op </a>
192 ed619ca0 2022-12-14 op </div>
193 424803ac 2023-09-12 op </header>
194 424803ac 2023-09-12 op <nav id="site_path">
195 424803ac 2023-09-12 op <div id="site_link">
196 424803ac 2023-09-12 op <a href="?index_page={{ printf "%d", qs->index_page }}">
197 424803ac 2023-09-12 op {{ srv->site_link }}
198 424803ac 2023-09-12 op </a>
199 424803ac 2023-09-12 op {{ if qs->path }}
200 424803ac 2023-09-12 op {! u_path.path = qs->path; !}
201 424803ac 2023-09-12 op {{ " / " }}
202 424803ac 2023-09-12 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
203 424803ac 2023-09-12 op {{ qs->path }}
204 ed619ca0 2022-12-14 op </a>
205 424803ac 2023-09-12 op {{ end }}
206 c2abf03c 2023-11-30 op {{ if qs->action == TREE || qs->action == BLOB }}
207 c2abf03c 2023-11-30 op {{ render breadcumbs(tp) }}
208 c2abf03c 2023-11-30 op {{ else if qs->action != INDEX }}
209 424803ac 2023-09-12 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
210 424803ac 2023-09-12 op {{ end }}
211 ed619ca0 2022-12-14 op </div>
212 424803ac 2023-09-12 op </nav>
213 424803ac 2023-09-12 op <main>
214 424803ac 2023-09-12 op {{ render body(tp) }}
215 424803ac 2023-09-12 op </main>
216 424803ac 2023-09-12 op <footer id="site_owner_wrapper">
217 424803ac 2023-09-12 op <p id="site_owner">
218 424803ac 2023-09-12 op {{ if srv->show_site_owner }}
219 424803ac 2023-09-12 op {{ srv->site_owner }}
220 424803ac 2023-09-12 op {{ end }}
221 424803ac 2023-09-12 op </p>
222 424803ac 2023-09-12 op </footer>
223 ed619ca0 2022-12-14 op </body>
224 ed619ca0 2022-12-14 op </html>
225 8f37175d 2023-03-11 op {{ end }}
226 8f37175d 2023-03-11 op
227 8f37175d 2023-03-11 op {{ define gotweb_render_error(struct template *tp) }}
228 8f37175d 2023-03-11 op {!
229 8f37175d 2023-03-11 op struct request *c = tp->tp_arg;
230 8f37175d 2023-03-11 op struct transport *t = c->t;
231 8f37175d 2023-03-11 op !}
232 8f37175d 2023-03-11 op <div id="err_content">
233 8f37175d 2023-03-11 op {{ if t->error }}
234 8f37175d 2023-03-11 op {{ t->error->msg }}
235 8f37175d 2023-03-11 op {{ else }}
236 8f37175d 2023-03-11 op See daemon logs for details
237 8f37175d 2023-03-11 op {{ end }}
238 8f37175d 2023-03-11 op </div>
239 ed619ca0 2022-12-14 op {{ end }}
240 ed619ca0 2022-12-14 op
241 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
242 ed619ca0 2022-12-14 op {!
243 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
244 ed619ca0 2022-12-14 op struct server *srv = c->srv;
245 ed619ca0 2022-12-14 op !}
246 ed619ca0 2022-12-14 op <div id="index_header">
247 424803ac 2023-09-12 op <div class="index_project">
248 ed619ca0 2022-12-14 op Project
249 ed619ca0 2022-12-14 op </div>
250 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
251 424803ac 2023-09-12 op <div class="index_project_description">
252 ed619ca0 2022-12-14 op Description
253 ed619ca0 2022-12-14 op </div>
254 ed619ca0 2022-12-14 op {{ end }}
255 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
256 424803ac 2023-09-12 op <div class="index_project_owner">
257 ed619ca0 2022-12-14 op Owner
258 ed619ca0 2022-12-14 op </div>
259 ed619ca0 2022-12-14 op {{ end }}
260 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
261 424803ac 2023-09-12 op <div class="index_project_age">
262 ed619ca0 2022-12-14 op Last Change
263 ed619ca0 2022-12-14 op </div>
264 ed619ca0 2022-12-14 op {{ end }}
265 ed619ca0 2022-12-14 op </div>
266 ed619ca0 2022-12-14 op {{ end }}
267 ed619ca0 2022-12-14 op
268 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
269 ed619ca0 2022-12-14 op {!
270 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
271 ed619ca0 2022-12-14 op struct server *srv = c->srv;
272 ed619ca0 2022-12-14 op struct gotweb_url summary = {
273 ed619ca0 2022-12-14 op .action = SUMMARY,
274 ed619ca0 2022-12-14 op .index_page = -1,
275 ed619ca0 2022-12-14 op .page = -1,
276 ed619ca0 2022-12-14 op .path = repo_dir->name,
277 ed619ca0 2022-12-14 op }, briefs = {
278 ed619ca0 2022-12-14 op .action = BRIEFS,
279 ed619ca0 2022-12-14 op .index_page = -1,
280 ed619ca0 2022-12-14 op .page = -1,
281 ed619ca0 2022-12-14 op .path = repo_dir->name,
282 ed619ca0 2022-12-14 op }, commits = {
283 ed619ca0 2022-12-14 op .action = COMMITS,
284 ed619ca0 2022-12-14 op .index_page = -1,
285 ed619ca0 2022-12-14 op .page = -1,
286 ed619ca0 2022-12-14 op .path = repo_dir->name,
287 ed619ca0 2022-12-14 op }, tags = {
288 ed619ca0 2022-12-14 op .action = TAGS,
289 ed619ca0 2022-12-14 op .index_page = -1,
290 ed619ca0 2022-12-14 op .page = -1,
291 ed619ca0 2022-12-14 op .path = repo_dir->name,
292 ed619ca0 2022-12-14 op }, tree = {
293 ed619ca0 2022-12-14 op .action = TREE,
294 ed619ca0 2022-12-14 op .index_page = -1,
295 ed619ca0 2022-12-14 op .page = -1,
296 ed619ca0 2022-12-14 op .path = repo_dir->name,
297 1abb18e1 2022-12-20 op }, rss = {
298 1abb18e1 2022-12-20 op .action = RSS,
299 1abb18e1 2022-12-20 op .index_page = -1,
300 1abb18e1 2022-12-20 op .page = -1,
301 1abb18e1 2022-12-20 op .path = repo_dir->name,
302 ed619ca0 2022-12-14 op };
303 ed619ca0 2022-12-14 op !}
304 ed619ca0 2022-12-14 op <div class="index_wrapper">
305 ed619ca0 2022-12-14 op <div class="index_project">
306 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
307 ed619ca0 2022-12-14 op </div>
308 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
309 ed619ca0 2022-12-14 op <div class="index_project_description">
310 ed619ca0 2022-12-14 op {{ repo_dir->description }}
311 ed619ca0 2022-12-14 op </div>
312 ed619ca0 2022-12-14 op {{ end }}
313 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
314 ed619ca0 2022-12-14 op <div class="index_project_owner">
315 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
316 ed619ca0 2022-12-14 op </div>
317 ed619ca0 2022-12-14 op {{ end }}
318 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
319 ed619ca0 2022-12-14 op <div class="index_project_age">
320 7781b991 2023-10-05 op {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
321 ed619ca0 2022-12-14 op </div>
322 ed619ca0 2022-12-14 op {{ end }}
323 ed619ca0 2022-12-14 op <div class="navs_wrapper">
324 ed619ca0 2022-12-14 op <div class="navs">
325 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
326 ed619ca0 2022-12-14 op {{ " | " }}
327 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
328 ed619ca0 2022-12-14 op {{ " | " }}
329 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
330 ed619ca0 2022-12-14 op {{ " | " }}
331 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
332 ed619ca0 2022-12-14 op {{ " | " }}
333 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
334 1abb18e1 2022-12-20 op {{ " | " }}
335 1abb18e1 2022-12-20 op <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
336 ed619ca0 2022-12-14 op </div>
337 424803ac 2023-09-12 op <hr />
338 ed619ca0 2022-12-14 op </div>
339 ed619ca0 2022-12-14 op </div>
340 ed619ca0 2022-12-14 op {{ end }}
341 ed619ca0 2022-12-14 op
342 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
343 ed619ca0 2022-12-14 op {!
344 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
345 ed619ca0 2022-12-14 op struct transport *t = c->t;
346 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
347 ed619ca0 2022-12-14 op struct repo_commit *rc;
348 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
349 34f1dbc6 2023-12-01 op struct gotweb_url diff_url, patch_url, tree_url;
350 ed619ca0 2022-12-14 op char *tmp;
351 ed619ca0 2022-12-14 op
352 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
353 ed619ca0 2022-12-14 op .action = DIFF,
354 34f1dbc6 2023-12-01 op .index_page = -1,
355 34f1dbc6 2023-12-01 op .page = -1,
356 34f1dbc6 2023-12-01 op .path = repo_dir->name,
357 34f1dbc6 2023-12-01 op .headref = qs->headref,
358 34f1dbc6 2023-12-01 op };
359 34f1dbc6 2023-12-01 op patch_url = (struct gotweb_url){
360 34f1dbc6 2023-12-01 op .action = PATCH,
361 ed619ca0 2022-12-14 op .index_page = -1,
362 ed619ca0 2022-12-14 op .page = -1,
363 ed619ca0 2022-12-14 op .path = repo_dir->name,
364 ed619ca0 2022-12-14 op .headref = qs->headref,
365 ed619ca0 2022-12-14 op };
366 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
367 ed619ca0 2022-12-14 op .action = TREE,
368 ed619ca0 2022-12-14 op .index_page = -1,
369 ed619ca0 2022-12-14 op .page = -1,
370 ed619ca0 2022-12-14 op .path = repo_dir->name,
371 ed619ca0 2022-12-14 op .headref = qs->headref,
372 ed619ca0 2022-12-14 op };
373 ed619ca0 2022-12-14 op !}
374 424803ac 2023-09-12 op <header class='subtitle'>
375 424803ac 2023-09-12 op <h2>Commit Briefs</h2>
376 424803ac 2023-09-12 op </header>
377 ed619ca0 2022-12-14 op <div id="briefs_content">
378 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
379 ed619ca0 2022-12-14 op {!
380 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
381 34f1dbc6 2023-12-01 op patch_url.commit = rc->commit_id;
382 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
383 ed619ca0 2022-12-14 op
384 6c3d3263 2023-01-10 op tmp = strchr(rc->committer, '<');
385 ed619ca0 2022-12-14 op if (tmp)
386 ed619ca0 2022-12-14 op *tmp = '\0';
387 ed619ca0 2022-12-14 op
388 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
389 ed619ca0 2022-12-14 op if (tmp)
390 ed619ca0 2022-12-14 op *tmp = '\0';
391 ed619ca0 2022-12-14 op !}
392 424803ac 2023-09-12 op <div class='brief'>
393 424803ac 2023-09-12 op <p class='brief_meta'>
394 424803ac 2023-09-12 op <span class='briefs_age'>
395 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
396 424803ac 2023-09-12 op </span>
397 424803ac 2023-09-12 op {{" "}}
398 424803ac 2023-09-12 op <span class="briefs_author">
399 424803ac 2023-09-12 op {{ rc->committer }}
400 424803ac 2023-09-12 op </span>
401 424803ac 2023-09-12 op </p>
402 424803ac 2023-09-12 op <p class="briefs_log">
403 424803ac 2023-09-12 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
404 424803ac 2023-09-12 op {{ rc->commit_msg }}
405 424803ac 2023-09-12 op </a>
406 424803ac 2023-09-12 op {{ if rc->refs_str }}
407 424803ac 2023-09-12 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
408 424803ac 2023-09-12 op {{ end }}
409 424803ac 2023-09-12 op </a>
410 424803ac 2023-09-12 op </p>
411 ed619ca0 2022-12-14 op </div>
412 ed619ca0 2022-12-14 op <div class="navs_wrapper">
413 ed619ca0 2022-12-14 op <div class="navs">
414 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
415 ed619ca0 2022-12-14 op {{ " | " }}
416 34f1dbc6 2023-12-01 op <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
417 34f1dbc6 2023-12-01 op {{ " | " }}
418 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
419 ed619ca0 2022-12-14 op </div>
420 ed619ca0 2022-12-14 op </div>
421 424803ac 2023-09-12 op <hr />
422 ed619ca0 2022-12-14 op {{ end }}
423 e3662697 2023-02-03 op {{ render gotweb_render_more(tp, BRIEFS) }}
424 b4c0bd72 2022-12-17 op </div>
425 b4c0bd72 2022-12-17 op {{ end }}
426 b4c0bd72 2022-12-17 op
427 e3662697 2023-02-03 op {{ define gotweb_render_more(struct template *tp, int action) }}
428 e3662697 2023-02-03 op {!
429 e3662697 2023-02-03 op struct request *c = tp->tp_arg;
430 e3662697 2023-02-03 op struct transport *t = c->t;
431 e3662697 2023-02-03 op struct querystring *qs = t->qs;
432 e3662697 2023-02-03 op struct gotweb_url more = {
433 e3662697 2023-02-03 op .action = action,
434 e3662697 2023-02-03 op .index_page = -1,
435 e3662697 2023-02-03 op .path = qs->path,
436 e3662697 2023-02-03 op .commit = t->more_id,
437 e3662697 2023-02-03 op .headref = qs->headref,
438 de8c0409 2023-09-12 op .file = qs->file,
439 e3662697 2023-02-03 op };
440 e3662697 2023-02-03 op !}
441 e3662697 2023-02-03 op {{ if t->more_id }}
442 e3662697 2023-02-03 op <div id="np_wrapper">
443 e3662697 2023-02-03 op <div id="nav_more">
444 e3662697 2023-02-03 op <a href="{{ render gotweb_render_url(c, &more) }}">
445 0af50e04 2023-02-03 op More&nbsp;&darr;
446 e3662697 2023-02-03 op </a>
447 e3662697 2023-02-03 op </div>
448 e3662697 2023-02-03 op </div>
449 e3662697 2023-02-03 op {{ end }}
450 e3662697 2023-02-03 op {{ end }}
451 e3662697 2023-02-03 op
452 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
453 b4c0bd72 2022-12-17 op {!
454 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
455 b4c0bd72 2022-12-17 op struct transport *t = c->t;
456 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
457 b4c0bd72 2022-12-17 op int have_prev, have_next;
458 b4c0bd72 2022-12-17 op
459 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
460 b4c0bd72 2022-12-17 op !}
461 b4c0bd72 2022-12-17 op <div id="np_wrapper">
462 b4c0bd72 2022-12-17 op <div id="nav_prev">
463 b4c0bd72 2022-12-17 op {{ if have_prev }}
464 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
465 b4c0bd72 2022-12-17 op Previous
466 b4c0bd72 2022-12-17 op </a>
467 b4c0bd72 2022-12-17 op {{ end }}
468 b4c0bd72 2022-12-17 op </div>
469 b4c0bd72 2022-12-17 op <div id="nav_next">
470 b4c0bd72 2022-12-17 op {{ if have_next }}
471 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
472 b4c0bd72 2022-12-17 op Next
473 b4c0bd72 2022-12-17 op </a>
474 b4c0bd72 2022-12-17 op {{ end }}
475 b4c0bd72 2022-12-17 op </div>
476 ed619ca0 2022-12-14 op </div>
477 b4c0bd72 2022-12-17 op {{ finally }}
478 b4c0bd72 2022-12-17 op {!
479 b4c0bd72 2022-12-17 op free(t->next_id);
480 b4c0bd72 2022-12-17 op t->next_id = NULL;
481 b4c0bd72 2022-12-17 op free(t->prev_id);
482 b4c0bd72 2022-12-17 op t->prev_id = NULL;
483 b4c0bd72 2022-12-17 op !}
484 ed619ca0 2022-12-14 op {{ end }}
485 156a1144 2022-12-17 op
486 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
487 156a1144 2022-12-17 op {!
488 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
489 156a1144 2022-12-17 op struct transport *t = c->t;
490 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
491 156a1144 2022-12-17 op struct repo_commit *rc;
492 34f1dbc6 2023-12-01 op struct gotweb_url diff, patch, tree;
493 156a1144 2022-12-17 op
494 156a1144 2022-12-17 op diff = (struct gotweb_url){
495 156a1144 2022-12-17 op .action = DIFF,
496 156a1144 2022-12-17 op .index_page = -1,
497 156a1144 2022-12-17 op .page = -1,
498 156a1144 2022-12-17 op .path = repo_dir->name,
499 156a1144 2022-12-17 op };
500 34f1dbc6 2023-12-01 op patch = (struct gotweb_url){
501 34f1dbc6 2023-12-01 op .action = PATCH,
502 34f1dbc6 2023-12-01 op .index_page = -1,
503 34f1dbc6 2023-12-01 op .page = -1,
504 34f1dbc6 2023-12-01 op .path = repo_dir->name,
505 34f1dbc6 2023-12-01 op };
506 156a1144 2022-12-17 op tree = (struct gotweb_url){
507 156a1144 2022-12-17 op .action = TREE,
508 156a1144 2022-12-17 op .index_page = -1,
509 156a1144 2022-12-17 op .page = -1,
510 156a1144 2022-12-17 op .path = repo_dir->name,
511 156a1144 2022-12-17 op };
512 156a1144 2022-12-17 op !}
513 424803ac 2023-09-12 op <header class="subtitle">
514 424803ac 2023-09-12 op <h2>Commits</h2>
515 424803ac 2023-09-12 op </header>
516 156a1144 2022-12-17 op <div class="commits_content">
517 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
518 156a1144 2022-12-17 op {!
519 156a1144 2022-12-17 op diff.commit = rc->commit_id;
520 34f1dbc6 2023-12-01 op patch.commit = rc->commit_id;
521 156a1144 2022-12-17 op tree.commit = rc->commit_id;
522 156a1144 2022-12-17 op !}
523 6595d730 2023-11-30 op <div class="page_header_wrapper">
524 6595d730 2023-11-30 op <dl>
525 424803ac 2023-09-12 op <dt>Commit:</dt>
526 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
527 424803ac 2023-09-12 op <dt>From:</dt>
528 424803ac 2023-09-12 op <dd>{{ rc->author }}</dd>
529 af800df5 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
530 424803ac 2023-09-12 op <dt>Via:</dt>
531 424803ac 2023-09-12 op <dd>{{ rc->committer }}</dd>
532 af800df5 2023-01-10 op {{ end }}
533 424803ac 2023-09-12 op <dt>Date:</dt>
534 424803ac 2023-09-12 op <dd>
535 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_LONG) }}
536 424803ac 2023-09-12 op </dd>
537 424803ac 2023-09-12 op </dl>
538 156a1144 2022-12-17 op </div>
539 424803ac 2023-09-12 op <hr />
540 cf536071 2022-12-31 op <div class="commit">
541 cf536071 2022-12-31 op {{ "\n" }}
542 cf536071 2022-12-31 op {{ rc->commit_msg }}
543 cf536071 2022-12-31 op </div>
544 156a1144 2022-12-17 op <div class="navs_wrapper">
545 156a1144 2022-12-17 op <div class="navs">
546 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
547 34f1dbc6 2023-12-01 op {{ " | " }}
548 34f1dbc6 2023-12-01 op <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
549 156a1144 2022-12-17 op {{ " | " }}
550 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
551 156a1144 2022-12-17 op </div>
552 156a1144 2022-12-17 op </div>
553 424803ac 2023-09-12 op <hr />
554 156a1144 2022-12-17 op {{ end }}
555 e3662697 2023-02-03 op {{ render gotweb_render_more(tp, COMMITS) }}
556 298f95fb 2023-01-05 op </div>
557 298f95fb 2023-01-05 op {{ end }}
558 298f95fb 2023-01-05 op
559 df2d3cd2 2023-03-11 op {{ define gotweb_render_blob(struct template *tp) }}
560 298f95fb 2023-01-05 op {!
561 298f95fb 2023-01-05 op struct request *c = tp->tp_arg;
562 298f95fb 2023-01-05 op struct transport *t = c->t;
563 4dfd9794 2023-12-01 op struct querystring *qs = t->qs;
564 df2d3cd2 2023-03-11 op struct got_blob_object *blob = t->blob;
565 298f95fb 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
566 4dfd9794 2023-12-01 op struct gotweb_url briefs_url, blame_url, raw_url;
567 4dfd9794 2023-12-01 op
568 4dfd9794 2023-12-01 op memset(&briefs_url, 0, sizeof(briefs_url));
569 4dfd9794 2023-12-01 op briefs_url.index_page = -1,
570 4dfd9794 2023-12-01 op briefs_url.page = -1,
571 4dfd9794 2023-12-01 op briefs_url.action = BRIEFS,
572 4dfd9794 2023-12-01 op briefs_url.path = qs->path,
573 4dfd9794 2023-12-01 op briefs_url.commit = qs->commit,
574 4dfd9794 2023-12-01 op briefs_url.folder = qs->folder,
575 4dfd9794 2023-12-01 op briefs_url.file = qs->file,
576 4dfd9794 2023-12-01 op
577 4dfd9794 2023-12-01 op memcpy(&blame_url, &briefs_url, sizeof(blame_url));
578 4dfd9794 2023-12-01 op blame_url.action = BLAME;
579 4dfd9794 2023-12-01 op
580 4dfd9794 2023-12-01 op memcpy(&raw_url, &briefs_url, sizeof(raw_url));
581 4dfd9794 2023-12-01 op raw_url.action = BLOBRAW;
582 298f95fb 2023-01-05 op !}
583 424803ac 2023-09-12 op <header class="subtitle">
584 424803ac 2023-09-12 op <h2>Blob</h2>
585 424803ac 2023-09-12 op </header>
586 298f95fb 2023-01-05 op <div id="blob_content">
587 6595d730 2023-11-30 op <div class="page_header_wrapper">
588 6595d730 2023-11-30 op <dl>
589 424803ac 2023-09-12 op <dt>Date:</dt>
590 424803ac 2023-09-12 op <dd>
591 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_LONG) }}
592 424803ac 2023-09-12 op </dd>
593 424803ac 2023-09-12 op <dt>Message:</dt>
594 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
595 4dfd9794 2023-12-01 op <dt>Actions:</dt>
596 4dfd9794 2023-12-01 op <dd>
597 4dfd9794 2023-12-01 op <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
598 4dfd9794 2023-12-01 op History
599 4dfd9794 2023-12-01 op </a>
600 4dfd9794 2023-12-01 op {{" | "}}
601 4dfd9794 2023-12-01 op <a href="{{ render gotweb_render_url(c, &blame_url) }}">
602 4dfd9794 2023-12-01 op Blame
603 4dfd9794 2023-12-01 op </a>
604 4dfd9794 2023-12-01 op {{" | "}}
605 4dfd9794 2023-12-01 op <a href="{{ render gotweb_render_url(c, &raw_url) }}">
606 4dfd9794 2023-12-01 op Raw File
607 4dfd9794 2023-12-01 op </a>
608 4dfd9794 2023-12-01 op </dd>
609 424803ac 2023-09-12 op </dl>
610 298f95fb 2023-01-05 op </div>
611 424803ac 2023-09-12 op <hr />
612 298f95fb 2023-01-05 op <div id="blob">
613 298f95fb 2023-01-05 op <pre>
614 298f95fb 2023-01-05 op {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
615 298f95fb 2023-01-05 op </pre>
616 298f95fb 2023-01-05 op </div>
617 156a1144 2022-12-17 op </div>
618 1abb18e1 2022-12-20 op {{ end }}
619 1abb18e1 2022-12-20 op
620 298f95fb 2023-01-05 op {{ define gotweb_render_blob_line(struct template *tp, const char *line,
621 298f95fb 2023-01-05 op size_t no) }}
622 298f95fb 2023-01-05 op {!
623 298f95fb 2023-01-05 op char lineno[16];
624 298f95fb 2023-01-05 op int r;
625 298f95fb 2023-01-05 op
626 298f95fb 2023-01-05 op r = snprintf(lineno, sizeof(lineno), "%zu", no);
627 298f95fb 2023-01-05 op if (r < 0 || (size_t)r >= sizeof(lineno))
628 298f95fb 2023-01-05 op return -1;
629 298f95fb 2023-01-05 op !}
630 298f95fb 2023-01-05 op <div class="blob_line" id="line{{ lineno }}">
631 424803ac 2023-09-12 op <a href="#line{{ lineno }}">{{ lineno }}</a>
632 edc930eb 2023-11-30 op {{" "}}
633 424803ac 2023-09-12 op <span class="blob_code">{{ line }}</span>
634 43d421de 2023-01-05 op </div>
635 43d421de 2023-01-05 op {{ end }}
636 43d421de 2023-01-05 op
637 43d421de 2023-01-05 op {{ define gotweb_render_tree(struct template *tp) }}
638 43d421de 2023-01-05 op {!
639 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
640 43d421de 2023-01-05 op struct transport *t = c->t;
641 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
642 43d421de 2023-01-05 op !}
643 424803ac 2023-09-12 op <header class='subtitle'>
644 424803ac 2023-09-12 op <h2>Tree</h2>
645 424803ac 2023-09-12 op </header>
646 43d421de 2023-01-05 op <div id="tree_content">
647 6595d730 2023-11-30 op <div class="page_header_wrapper">
648 6595d730 2023-11-30 op <dl>
649 424803ac 2023-09-12 op <dt>Tree:</dt>
650 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
651 424803ac 2023-09-12 op <dt>Date:</dt>
652 424803ac 2023-09-12 op <dd>
653 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_LONG) }}
654 424803ac 2023-09-12 op </dd>
655 424803ac 2023-09-12 op <dt>Message:</dt>
656 f8275511 2023-10-05 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
657 424803ac 2023-09-12 op </dl>
658 43d421de 2023-01-05 op </div>
659 424803ac 2023-09-12 op <hr />
660 424803ac 2023-09-12 op <table id="tree">
661 43d421de 2023-01-05 op {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
662 424803ac 2023-09-12 op </table>
663 43d421de 2023-01-05 op </div>
664 43d421de 2023-01-05 op {{ end }}
665 43d421de 2023-01-05 op
666 43d421de 2023-01-05 op {{ define gotweb_render_tree_item(struct template *tp,
667 43d421de 2023-01-05 op struct got_tree_entry *te) }}
668 43d421de 2023-01-05 op {!
669 43d421de 2023-01-05 op struct request *c = tp->tp_arg;
670 43d421de 2023-01-05 op struct transport *t = c->t;
671 43d421de 2023-01-05 op struct querystring *qs = t->qs;
672 43d421de 2023-01-05 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
673 43d421de 2023-01-05 op const char *modestr = "";
674 43d421de 2023-01-05 op const char *name;
675 43d421de 2023-01-05 op const char *folder;
676 43d421de 2023-01-05 op char *dir = NULL;
677 43d421de 2023-01-05 op mode_t mode;
678 43d421de 2023-01-05 op struct gotweb_url url = {
679 43d421de 2023-01-05 op .index_page = -1,
680 43d421de 2023-01-05 op .page = -1,
681 43d421de 2023-01-05 op .commit = rc->commit_id,
682 43d421de 2023-01-05 op .path = qs->path,
683 43d421de 2023-01-05 op };
684 43d421de 2023-01-05 op
685 43d421de 2023-01-05 op name = got_tree_entry_get_name(te);
686 43d421de 2023-01-05 op mode = got_tree_entry_get_mode(te);
687 43d421de 2023-01-05 op
688 43d421de 2023-01-05 op folder = qs->folder ? qs->folder : "";
689 43d421de 2023-01-05 op if (S_ISDIR(mode)) {
690 43d421de 2023-01-05 op if (asprintf(&dir, "%s/%s", folder, name) == -1)
691 43d421de 2023-01-05 op return (-1);
692 43d421de 2023-01-05 op
693 43d421de 2023-01-05 op url.action = TREE;
694 43d421de 2023-01-05 op url.folder = dir;
695 43d421de 2023-01-05 op } else {
696 43d421de 2023-01-05 op url.action = BLOB;
697 43d421de 2023-01-05 op url.folder = folder;
698 43d421de 2023-01-05 op url.file = name;
699 43d421de 2023-01-05 op }
700 43d421de 2023-01-05 op
701 43d421de 2023-01-05 op if (got_object_tree_entry_is_submodule(te))
702 43d421de 2023-01-05 op modestr = "$";
703 43d421de 2023-01-05 op else if (S_ISLNK(mode))
704 43d421de 2023-01-05 op modestr = "@";
705 43d421de 2023-01-05 op else if (S_ISDIR(mode))
706 43d421de 2023-01-05 op modestr = "/";
707 43d421de 2023-01-05 op else if (mode & S_IXUSR)
708 43d421de 2023-01-05 op modestr = "*";
709 43d421de 2023-01-05 op !}
710 424803ac 2023-09-12 op <tr class="tree_wrapper">
711 43d421de 2023-01-05 op {{ if S_ISDIR(mode) }}
712 424803ac 2023-09-12 op <td class="tree_line" colspan=2>
713 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
714 43d421de 2023-01-05 op {{ name }}{{ modestr }}
715 43d421de 2023-01-05 op </a>
716 424803ac 2023-09-12 op </td>
717 43d421de 2023-01-05 op {{ else }}
718 424803ac 2023-09-12 op <td class="tree_line">
719 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
720 43d421de 2023-01-05 op {{ name }}{{ modestr }}
721 43d421de 2023-01-05 op </a>
722 424803ac 2023-09-12 op </td>
723 424803ac 2023-09-12 op <td class="tree_line_blank">
724 43d421de 2023-01-05 op {! url.action = COMMITS; !}
725 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
726 43d421de 2023-01-05 op commits
727 43d421de 2023-01-05 op </a>
728 43d421de 2023-01-05 op {{ " | " }}
729 43d421de 2023-01-05 op {! url.action = BLAME; !}
730 43d421de 2023-01-05 op <a href="{{ render gotweb_render_url(c, &url) }}">
731 43d421de 2023-01-05 op blame
732 43d421de 2023-01-05 op </a>
733 424803ac 2023-09-12 op </td>
734 43d421de 2023-01-05 op {{ end }}
735 424803ac 2023-09-12 op </tr>
736 43d421de 2023-01-05 op {{ finally }}
737 43d421de 2023-01-05 op {!
738 43d421de 2023-01-05 op free(dir);
739 067396e6 2023-01-09 op !}
740 067396e6 2023-01-09 op {{ end }}
741 067396e6 2023-01-09 op
742 d60961d2 2023-01-13 op {{ define gotweb_render_tags(struct template *tp) }}
743 067396e6 2023-01-09 op {!
744 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
745 067396e6 2023-01-09 op struct transport *t = c->t;
746 067396e6 2023-01-09 op struct querystring *qs = t->qs;
747 067396e6 2023-01-09 op struct repo_tag *rt;
748 067396e6 2023-01-09 op int commit_found;
749 067396e6 2023-01-09 op
750 067396e6 2023-01-09 op commit_found = qs->commit == NULL;
751 43d421de 2023-01-05 op !}
752 424803ac 2023-09-12 op <header class='subtitle'>
753 424803ac 2023-09-12 op <h2>Tags</h2>
754 424803ac 2023-09-12 op </header>
755 067396e6 2023-01-09 op <div id="tags_content">
756 067396e6 2023-01-09 op {{ if t->tag_count == 0 }}
757 067396e6 2023-01-09 op <div id="err_content">
758 067396e6 2023-01-09 op This repository contains no tags
759 067396e6 2023-01-09 op </div>
760 067396e6 2023-01-09 op {{ else }}
761 067396e6 2023-01-09 op {{ tailq-foreach rt &t->repo_tags entry }}
762 067396e6 2023-01-09 op {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
763 067396e6 2023-01-09 op {! commit_found = 1; !}
764 067396e6 2023-01-09 op {{ render tag_item(tp, rt) }}
765 067396e6 2023-01-09 op {{ end }}
766 067396e6 2023-01-09 op {{ end }}
767 067396e6 2023-01-09 op {{ if t->next_id || t->prev_id }}
768 e3662697 2023-02-03 op {! qs->action = TAGS; !}
769 067396e6 2023-01-09 op {{ render gotweb_render_navs(tp) }}
770 067396e6 2023-01-09 op {{ end }}
771 067396e6 2023-01-09 op {{ end }}
772 067396e6 2023-01-09 op </div>
773 298f95fb 2023-01-05 op {{ end }}
774 298f95fb 2023-01-05 op
775 067396e6 2023-01-09 op {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
776 067396e6 2023-01-09 op {!
777 067396e6 2023-01-09 op struct request *c = tp->tp_arg;
778 067396e6 2023-01-09 op struct transport *t = c->t;
779 067396e6 2023-01-09 op struct repo_dir *repo_dir = t->repo_dir;
780 067396e6 2023-01-09 op char *tag_name = rt->tag_name;
781 067396e6 2023-01-09 op char *msg = rt->tag_commit;
782 067396e6 2023-01-09 op char *nl;
783 067396e6 2023-01-09 op struct gotweb_url url = {
784 067396e6 2023-01-09 op .action = TAG,
785 067396e6 2023-01-09 op .index_page = -1,
786 067396e6 2023-01-09 op .page = -1,
787 067396e6 2023-01-09 op .path = repo_dir->name,
788 067396e6 2023-01-09 op .commit = rt->commit_id,
789 067396e6 2023-01-09 op };
790 067396e6 2023-01-09 op
791 067396e6 2023-01-09 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
792 067396e6 2023-01-09 op tag_name += 10;
793 067396e6 2023-01-09 op
794 067396e6 2023-01-09 op if (msg) {
795 067396e6 2023-01-09 op nl = strchr(msg, '\n');
796 067396e6 2023-01-09 op if (nl)
797 067396e6 2023-01-09 op *nl = '\0';
798 067396e6 2023-01-09 op }
799 067396e6 2023-01-09 op !}
800 067396e6 2023-01-09 op <div class="tag_age">
801 7781b991 2023-10-05 op {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
802 067396e6 2023-01-09 op </div>
803 424803ac 2023-09-12 op <div class="tag_name">{{ tag_name }}</div>
804 067396e6 2023-01-09 op <div class="tag_log">
805 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">
806 067396e6 2023-01-09 op {{ msg }}
807 067396e6 2023-01-09 op </a>
808 067396e6 2023-01-09 op </div>
809 067396e6 2023-01-09 op <div class="navs_wrapper">
810 067396e6 2023-01-09 op <div class="navs">
811 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
812 067396e6 2023-01-09 op {{ " | " }}
813 067396e6 2023-01-09 op {! url.action = BRIEFS; !}
814 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
815 067396e6 2023-01-09 op {{ " | " }}
816 067396e6 2023-01-09 op {! url.action = COMMITS; !}
817 067396e6 2023-01-09 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
818 067396e6 2023-01-09 op </div>
819 067396e6 2023-01-09 op </div>
820 424803ac 2023-09-12 op <hr />
821 067396e6 2023-01-09 op {{ end }}
822 dc07f76c 2023-01-09 op
823 dc07f76c 2023-01-09 op {{ define gotweb_render_tag(struct template *tp) }}
824 dc07f76c 2023-01-09 op {!
825 dc07f76c 2023-01-09 op struct request *c = tp->tp_arg;
826 dc07f76c 2023-01-09 op struct transport *t = c->t;
827 dc07f76c 2023-01-09 op struct repo_tag *rt;
828 dc07f76c 2023-01-09 op const char *tag_name;
829 067396e6 2023-01-09 op
830 dc07f76c 2023-01-09 op rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
831 dc07f76c 2023-01-09 op tag_name = rt->tag_name;
832 dc07f76c 2023-01-09 op
833 dc07f76c 2023-01-09 op if (strncmp(tag_name, "refs/", 5) == 0)
834 dc07f76c 2023-01-09 op tag_name += 5;
835 dc07f76c 2023-01-09 op !}
836 424803ac 2023-09-12 op <header class="subtitle">
837 424803ac 2023-09-12 op <h2>Tag</h2>
838 424803ac 2023-09-12 op </header>
839 dc07f76c 2023-01-09 op <div id="tags_content">
840 6595d730 2023-11-30 op <div class="page_header_wrapper">
841 6595d730 2023-11-30 op <dl>
842 424803ac 2023-09-12 op <dt>Commit:</dt>
843 424803ac 2023-09-12 op <dd>
844 424803ac 2023-09-12 op <code class="commit-id">{{ rt->commit_id }}</code>
845 dc07f76c 2023-01-09 op {{ " " }}
846 dc07f76c 2023-01-09 op <span class="refs_str">({{ tag_name }})</span>
847 424803ac 2023-09-12 op </dd>
848 424803ac 2023-09-12 op <dt>Tagger:</dt>
849 424803ac 2023-09-12 op <dd>{{ rt->tagger }}</dd>
850 424803ac 2023-09-12 op <dt>Date:</dt>
851 424803ac 2023-09-12 op <dd>
852 7781b991 2023-10-05 op {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
853 424803ac 2023-09-12 op </dd>
854 424803ac 2023-09-12 op <dt>Message:</dt>
855 424803ac 2023-09-12 op <dd class="commit-msg">{{ rt->commit_msg }}</dd>
856 424803ac 2023-09-12 op </dl>
857 424803ac 2023-09-12 op <hr />
858 424803ac 2023-09-12 op <pre id="tag_commit">
859 dc07f76c 2023-01-09 op {{ rt->tag_commit }}
860 424803ac 2023-09-12 op </pre>
861 587550a5 2023-01-10 op </div>
862 587550a5 2023-01-10 op </div>
863 587550a5 2023-01-10 op {{ end }}
864 587550a5 2023-01-10 op
865 df2d3cd2 2023-03-11 op {{ define gotweb_render_diff(struct template *tp) }}
866 587550a5 2023-01-10 op {!
867 587550a5 2023-01-10 op struct request *c = tp->tp_arg;
868 587550a5 2023-01-10 op struct transport *t = c->t;
869 df2d3cd2 2023-03-11 op FILE *fp = t->fp;
870 587550a5 2023-01-10 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
871 587550a5 2023-01-10 op char *line = NULL;
872 587550a5 2023-01-10 op size_t linesize = 0;
873 587550a5 2023-01-10 op ssize_t linelen;
874 587550a5 2023-01-10 op !}
875 424803ac 2023-09-12 op <header class="subtitle">
876 424803ac 2023-09-12 op <h2>Commit Diff</h2>
877 424803ac 2023-09-12 op </header>
878 587550a5 2023-01-10 op <div id="diff_content">
879 6595d730 2023-11-30 op <div class="page_header_wrapper">
880 6595d730 2023-11-30 op <dl>
881 424803ac 2023-09-12 op <dt>Commit:</dt>
882 424803ac 2023-09-12 op <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
883 424803ac 2023-09-12 op <dt>From:</dt>
884 424803ac 2023-09-12 op <dd>{{ rc->author }}</dd>
885 49632cd3 2023-01-10 op {{ if strcmp(rc->committer, rc->author) != 0 }}
886 424803ac 2023-09-12 op <dt>Via:</dt>
887 424803ac 2023-09-12 op <dd>{{ rc->committer }}</dd>
888 49632cd3 2023-01-10 op {{ end }}
889 424803ac 2023-09-12 op <dt>Date:</dt>
890 424803ac 2023-09-12 op <dd>
891 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_LONG) }}
892 424803ac 2023-09-12 op </dd>
893 424803ac 2023-09-12 op <dt>Message:</dt>
894 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
895 424803ac 2023-09-12 op </dl>
896 dc07f76c 2023-01-09 op </div>
897 424803ac 2023-09-12 op <hr />
898 424803ac 2023-09-12 op <pre id="diff">
899 587550a5 2023-01-10 op {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
900 587550a5 2023-01-10 op {{ render diff_line(tp, line) }}
901 587550a5 2023-01-10 op {{ end }}
902 424803ac 2023-09-12 op </pre>
903 dc07f76c 2023-01-09 op </div>
904 587550a5 2023-01-10 op {{ finally }}
905 587550a5 2023-01-10 op {! free(line); !}
906 dc07f76c 2023-01-09 op {{ end }}
907 dc07f76c 2023-01-09 op
908 587550a5 2023-01-10 op {{ define diff_line(struct template *tp, char *line )}}
909 587550a5 2023-01-10 op {!
910 587550a5 2023-01-10 op const char *color = NULL;
911 587550a5 2023-01-10 op char *nl;
912 587550a5 2023-01-10 op
913 587550a5 2023-01-10 op if (!strncmp(line, "-", 1))
914 587550a5 2023-01-10 op color = "diff_minus";
915 587550a5 2023-01-10 op else if (!strncmp(line, "+", 1))
916 587550a5 2023-01-10 op color = "diff_plus";
917 587550a5 2023-01-10 op else if (!strncmp(line, "@@", 2))
918 587550a5 2023-01-10 op color = "diff_chunk_header";
919 587550a5 2023-01-10 op else if (!strncmp(line, "commit +", 8) ||
920 587550a5 2023-01-10 op !strncmp(line, "commit -", 8) ||
921 587550a5 2023-01-10 op !strncmp(line, "blob +", 6) ||
922 587550a5 2023-01-10 op !strncmp(line, "blob -", 6) ||
923 587550a5 2023-01-10 op !strncmp(line, "file +", 6) ||
924 587550a5 2023-01-10 op !strncmp(line, "file -", 6))
925 587550a5 2023-01-10 op color = "diff_meta";
926 587550a5 2023-01-10 op else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
927 587550a5 2023-01-10 op color = "diff_author";
928 587550a5 2023-01-10 op else if (!strncmp(line, "date:", 5))
929 587550a5 2023-01-10 op color = "diff_date";
930 587550a5 2023-01-10 op
931 587550a5 2023-01-10 op nl = strchr(line, '\n');
932 587550a5 2023-01-10 op if (nl)
933 587550a5 2023-01-10 op *nl = '\0';
934 587550a5 2023-01-10 op !}
935 424803ac 2023-09-12 op <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
936 3ab2c914 2023-01-11 op {{ end }}
937 3ab2c914 2023-01-11 op
938 3ab2c914 2023-01-11 op {{ define gotweb_render_branches(struct template *tp,
939 3ab2c914 2023-01-11 op struct got_reflist_head *refs) }}
940 3ab2c914 2023-01-11 op {!
941 3ab2c914 2023-01-11 op struct got_reflist_entry *re;
942 3ab2c914 2023-01-11 op !}
943 424803ac 2023-09-12 op <header class='subtitle'>
944 424803ac 2023-09-12 op <h2>Branches</h2>
945 424803ac 2023-09-12 op </header>
946 3ab2c914 2023-01-11 op <div id="branches_content">
947 3ab2c914 2023-01-11 op {{ tailq-foreach re refs entry }}
948 3ab2c914 2023-01-11 op {{ if !got_ref_is_symbolic(re->ref) }}
949 3ab2c914 2023-01-11 op {{ render branch(tp, re) }}
950 3ab2c914 2023-01-11 op {{ end }}
951 3ab2c914 2023-01-11 op {{ end }}
952 3ab2c914 2023-01-11 op </div>
953 3ab2c914 2023-01-11 op {{ end }}
954 3ab2c914 2023-01-11 op
955 3ab2c914 2023-01-11 op {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
956 3ab2c914 2023-01-11 op {!
957 3ab2c914 2023-01-11 op const struct got_error *err;
958 3ab2c914 2023-01-11 op struct request *c = tp->tp_arg;
959 3ab2c914 2023-01-11 op struct querystring *qs = c->t->qs;
960 3ab2c914 2023-01-11 op const char *refname;
961 cb93ab40 2023-01-22 op time_t age;
962 3ab2c914 2023-01-11 op struct gotweb_url url = {
963 3ab2c914 2023-01-11 op .action = SUMMARY,
964 3ab2c914 2023-01-11 op .index_page = -1,
965 3ab2c914 2023-01-11 op .page = -1,
966 3ab2c914 2023-01-11 op .path = qs->path,
967 3ab2c914 2023-01-11 op };
968 3ab2c914 2023-01-11 op
969 3ab2c914 2023-01-11 op refname = got_ref_get_name(re->ref);
970 3ab2c914 2023-01-11 op
971 cb93ab40 2023-01-22 op err = got_get_repo_age(&age, c, refname);
972 3ab2c914 2023-01-11 op if (err) {
973 3ab2c914 2023-01-11 op log_warnx("%s: %s", __func__, err->msg);
974 3ab2c914 2023-01-11 op return -1;
975 3ab2c914 2023-01-11 op }
976 3ab2c914 2023-01-11 op
977 3ab2c914 2023-01-11 op if (strncmp(refname, "refs/heads/", 11) == 0)
978 3ab2c914 2023-01-11 op refname += 11;
979 3ab2c914 2023-01-11 op
980 3ab2c914 2023-01-11 op url.headref = refname;
981 3ab2c914 2023-01-11 op !}
982 424803ac 2023-09-12 op <section class="branches_wrapper">
983 cb93ab40 2023-01-22 op <div class="branches_age">
984 7781b991 2023-10-05 op {{ render datetime(tp, age, TM_DIFF) }}
985 cb93ab40 2023-01-22 op </div>
986 3ab2c914 2023-01-11 op <div class="branch">
987 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
988 3ab2c914 2023-01-11 op </div>
989 3ab2c914 2023-01-11 op <div class="navs_wrapper">
990 3ab2c914 2023-01-11 op <div class="navs">
991 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
992 3ab2c914 2023-01-11 op {{" | "}}
993 3ab2c914 2023-01-11 op {! url.action = BRIEFS; !}
994 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
995 3ab2c914 2023-01-11 op {{" | "}}
996 3ab2c914 2023-01-11 op {! url.action = COMMITS; !}
997 3ab2c914 2023-01-11 op <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
998 3ab2c914 2023-01-11 op </div>
999 3ab2c914 2023-01-11 op </div>
1000 424803ac 2023-09-12 op <hr />
1001 424803ac 2023-09-12 op </section>
1002 69525b4e 2023-01-13 op {{ end }}
1003 69525b4e 2023-01-13 op
1004 df2d3cd2 2023-03-11 op {{ define gotweb_render_summary(struct template *tp) }}
1005 69525b4e 2023-01-13 op {!
1006 69525b4e 2023-01-13 op struct request *c = tp->tp_arg;
1007 69525b4e 2023-01-13 op struct server *srv = c->srv;
1008 69525b4e 2023-01-13 op struct transport *t = c->t;
1009 df2d3cd2 2023-03-11 op struct got_reflist_head *refs = &t->refs;
1010 69525b4e 2023-01-13 op !}
1011 34f1dbc6 2023-12-01 op <dl id="summary_wrapper" class="page_header_wrapper">
1012 69525b4e 2023-01-13 op {{ if srv->show_repo_description }}
1013 424803ac 2023-09-12 op <dt>Description:</dt>
1014 424803ac 2023-09-12 op <dd>{{ t->repo_dir->description }}</dd>
1015 69525b4e 2023-01-13 op {{ end }}
1016 69525b4e 2023-01-13 op {{ if srv->show_repo_owner }}
1017 424803ac 2023-09-12 op <dt>Owner:</dt>
1018 424803ac 2023-09-12 op <dd>{{ t->repo_dir->owner }}</dd>
1019 69525b4e 2023-01-13 op {{ end }}
1020 69525b4e 2023-01-13 op {{ if srv->show_repo_age }}
1021 424803ac 2023-09-12 op <dt>Last Change:</dt>
1022 424803ac 2023-09-12 op <dd>
1023 7781b991 2023-10-05 op {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1024 424803ac 2023-09-12 op </dd>
1025 69525b4e 2023-01-13 op {{ end }}
1026 69525b4e 2023-01-13 op {{ if srv->show_repo_cloneurl }}
1027 424803ac 2023-09-12 op <dt>Clone URL:</dt>
1028 424803ac 2023-09-12 op <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1029 69525b4e 2023-01-13 op {{ end }}
1030 424803ac 2023-09-12 op </dl>
1031 69525b4e 2023-01-13 op {{ render gotweb_render_briefs(tp) }}
1032 69525b4e 2023-01-13 op {{ render gotweb_render_tags(tp) }}
1033 69525b4e 2023-01-13 op {{ render gotweb_render_branches(tp, refs) }}
1034 587550a5 2023-01-10 op {{ end }}
1035 587550a5 2023-01-10 op
1036 8319855f 2023-01-15 op {{ define gotweb_render_blame(struct template *tp) }}
1037 8319855f 2023-01-15 op {!
1038 8319855f 2023-01-15 op const struct got_error *err;
1039 8319855f 2023-01-15 op struct request *c = tp->tp_arg;
1040 8319855f 2023-01-15 op struct transport *t = c->t;
1041 8319855f 2023-01-15 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1042 8319855f 2023-01-15 op !}
1043 424803ac 2023-09-12 op <header class="subtitle">
1044 424803ac 2023-09-12 op <h2>Blame</h2>
1045 424803ac 2023-09-12 op </header>
1046 8319855f 2023-01-15 op <div id="blame_content">
1047 6595d730 2023-11-30 op <div class="page_header_wrapper">
1048 6595d730 2023-11-30 op <dl>
1049 424803ac 2023-09-12 op <dt>Date:</dt>
1050 424803ac 2023-09-12 op <dd>
1051 7781b991 2023-10-05 op {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1052 424803ac 2023-09-12 op </dd>
1053 424803ac 2023-09-12 op <dt>Message:</dt>
1054 424803ac 2023-09-12 op <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1055 424803ac 2023-09-12 op </dl>
1056 8319855f 2023-01-15 op </div>
1057 424803ac 2023-09-12 op <hr />
1058 424803ac 2023-09-12 op <pre id="blame">
1059 8319855f 2023-01-15 op {!
1060 8319855f 2023-01-15 op err = got_output_file_blame(c, &blame_line);
1061 8a078d7f 2023-05-17 op if (err && err->code != GOT_ERR_CANCELLED)
1062 8319855f 2023-01-15 op log_warnx("%s: got_output_file_blame: %s", __func__,
1063 8319855f 2023-01-15 op err->msg);
1064 8a078d7f 2023-05-17 op if (err)
1065 8319855f 2023-01-15 op return (-1);
1066 8319855f 2023-01-15 op !}
1067 424803ac 2023-09-12 op </pre>
1068 8319855f 2023-01-15 op </div>
1069 8319855f 2023-01-15 op {{ end }}
1070 8319855f 2023-01-15 op
1071 8319855f 2023-01-15 op {{ define blame_line(struct template *tp, const char *line,
1072 8319855f 2023-01-15 op struct blame_line *bline, int lprec, int lcur) }}
1073 8319855f 2023-01-15 op {!
1074 8319855f 2023-01-15 op struct request *c = tp->tp_arg;
1075 8319855f 2023-01-15 op struct transport *t = c->t;
1076 8319855f 2023-01-15 op struct repo_dir *repo_dir = t->repo_dir;
1077 8319855f 2023-01-15 op char *committer, *s;
1078 8319855f 2023-01-15 op struct gotweb_url url = {
1079 8319855f 2023-01-15 op .action = DIFF,
1080 8319855f 2023-01-15 op .index_page = -1,
1081 8319855f 2023-01-15 op .page = -1,
1082 8319855f 2023-01-15 op .path = repo_dir->name,
1083 8319855f 2023-01-15 op .commit = bline->id_str,
1084 8319855f 2023-01-15 op };
1085 8319855f 2023-01-15 op
1086 8319855f 2023-01-15 op s = strchr(bline->committer, '<');
1087 8319855f 2023-01-15 op committer = s ? s + 1 : bline->committer;
1088 8319855f 2023-01-15 op
1089 8319855f 2023-01-15 op s = strchr(committer, '@');
1090 8319855f 2023-01-15 op if (s)
1091 8319855f 2023-01-15 op *s = '\0';
1092 8319855f 2023-01-15 op !}
1093 8319855f 2023-01-15 op <div class="blame_wrapper">
1094 8319855f 2023-01-15 op <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
1095 8319855f 2023-01-15 op <div class="blame_hash">
1096 8319855f 2023-01-15 op <a href="{{ render gotweb_render_url(c, &url) }}">
1097 8319855f 2023-01-15 op {{ printf "%.8s", bline->id_str }}
1098 8319855f 2023-01-15 op </a>
1099 8319855f 2023-01-15 op </div>
1100 8319855f 2023-01-15 op <div class="blame_date">{{ bline->datebuf }}</div>
1101 8319855f 2023-01-15 op <div class="blame_author">{{ printf "%.9s", committer }}</div>
1102 8319855f 2023-01-15 op <div class="blame_code">{{ line }}</div>
1103 8319855f 2023-01-15 op </div>
1104 34f1dbc6 2023-12-01 op {{ end }}
1105 34f1dbc6 2023-12-01 op
1106 34f1dbc6 2023-12-01 op {{ define gotweb_render_patch(struct template *tp) }}
1107 34f1dbc6 2023-12-01 op {!
1108 34f1dbc6 2023-12-01 op struct request *c = tp->tp_arg;
1109 34f1dbc6 2023-12-01 op struct transport *t = c->t;
1110 34f1dbc6 2023-12-01 op struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1111 34f1dbc6 2023-12-01 op struct tm tm;
1112 34f1dbc6 2023-12-01 op char buf[BUFSIZ], datebuf[64];
1113 34f1dbc6 2023-12-01 op size_t r;
1114 34f1dbc6 2023-12-01 op
1115 34f1dbc6 2023-12-01 op if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1116 34f1dbc6 2023-12-01 op strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1117 34f1dbc6 2023-12-01 op return (-1);
1118 34f1dbc6 2023-12-01 op !}
1119 34f1dbc6 2023-12-01 op commit {{ rc->commit_id }} {{ "\n" }}
1120 34f1dbc6 2023-12-01 op from: {{ rc->author | unsafe }} {{ "\n" }}
1121 34f1dbc6 2023-12-01 op {{ if strcmp(rc->committer, rc->author) != 0 }}
1122 34f1dbc6 2023-12-01 op via: {{ rc->author | unsafe }} {{ "\n" }}
1123 8319855f 2023-01-15 op {{ end }}
1124 34f1dbc6 2023-12-01 op date: {{ datebuf }} {{ "\n" }}
1125 34f1dbc6 2023-12-01 op {{ "\n" }}
1126 34f1dbc6 2023-12-01 op {{ rc->commit_msg | unsafe }} {{ "\n" }}
1127 34f1dbc6 2023-12-01 op {!
1128 34f1dbc6 2023-12-01 op if (template_flush(tp) == -1)
1129 34f1dbc6 2023-12-01 op return (-1);
1130 34f1dbc6 2023-12-01 op for (;;) {
1131 34f1dbc6 2023-12-01 op r = fread(buf, 1, sizeof(buf), t->fp);
1132 34f1dbc6 2023-12-01 op if (fcgi_write(c, buf, r) == -1 ||
1133 34f1dbc6 2023-12-01 op r != sizeof(buf))
1134 34f1dbc6 2023-12-01 op break;
1135 34f1dbc6 2023-12-01 op }
1136 34f1dbc6 2023-12-01 op !}
1137 34f1dbc6 2023-12-01 op {{ end }}
1138 8319855f 2023-01-15 op
1139 1abb18e1 2022-12-20 op {{ define gotweb_render_rss(struct template *tp) }}
1140 1abb18e1 2022-12-20 op {!
1141 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
1142 1abb18e1 2022-12-20 op struct server *srv = c->srv;
1143 1abb18e1 2022-12-20 op struct transport *t = c->t;
1144 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
1145 1abb18e1 2022-12-20 op struct repo_tag *rt;
1146 1abb18e1 2022-12-20 op struct gotweb_url summary = {
1147 1abb18e1 2022-12-20 op .action = SUMMARY,
1148 1abb18e1 2022-12-20 op .index_page = -1,
1149 1abb18e1 2022-12-20 op .page = -1,
1150 1abb18e1 2022-12-20 op .path = repo_dir->name,
1151 1abb18e1 2022-12-20 op };
1152 1abb18e1 2022-12-20 op !}
1153 1abb18e1 2022-12-20 op <?xml version="1.0" encoding="UTF-8"?>
1154 1abb18e1 2022-12-20 op <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1155 1abb18e1 2022-12-20 op <channel>
1156 1abb18e1 2022-12-20 op <title>Tags of {{ repo_dir->name }}</title>
1157 1abb18e1 2022-12-20 op <link>
1158 1abb18e1 2022-12-20 op <![CDATA[
1159 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &summary) }}
1160 1abb18e1 2022-12-20 op ]]>
1161 1abb18e1 2022-12-20 op </link>
1162 1abb18e1 2022-12-20 op {{ if srv->show_repo_description }}
1163 1abb18e1 2022-12-20 op <description>{{ repo_dir->description }}</description>
1164 1abb18e1 2022-12-20 op {{ end }}
1165 1abb18e1 2022-12-20 op {{ tailq-foreach rt &t->repo_tags entry }}
1166 1abb18e1 2022-12-20 op {{ render rss_tag_item(tp, rt) }}
1167 1abb18e1 2022-12-20 op {{ end }}
1168 1abb18e1 2022-12-20 op </channel>
1169 1abb18e1 2022-12-20 op </rss>
1170 1abb18e1 2022-12-20 op {{ end }}
1171 1abb18e1 2022-12-20 op
1172 1abb18e1 2022-12-20 op {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1173 1abb18e1 2022-12-20 op {!
1174 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
1175 1abb18e1 2022-12-20 op struct transport *t = c->t;
1176 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
1177 bf26a633 2023-10-05 op struct tm tm;
1178 bf26a633 2023-10-05 op char rfc822[128];
1179 bf26a633 2023-10-05 op int r;
1180 1abb18e1 2022-12-20 op char *tag_name = rt->tag_name;
1181 1abb18e1 2022-12-20 op struct gotweb_url tag = {
1182 1abb18e1 2022-12-20 op .action = TAG,
1183 1abb18e1 2022-12-20 op .index_page = -1,
1184 1abb18e1 2022-12-20 op .page = -1,
1185 1abb18e1 2022-12-20 op .path = repo_dir->name,
1186 1abb18e1 2022-12-20 op .commit = rt->commit_id,
1187 1abb18e1 2022-12-20 op };
1188 1abb18e1 2022-12-20 op
1189 1abb18e1 2022-12-20 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
1190 1abb18e1 2022-12-20 op tag_name += 10;
1191 bf26a633 2023-10-05 op
1192 bf26a633 2023-10-05 op if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1193 bf26a633 2023-10-05 op return -1;
1194 bf26a633 2023-10-05 op r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1195 bf26a633 2023-10-05 op if (r == 0)
1196 bf26a633 2023-10-05 op return 0;
1197 1abb18e1 2022-12-20 op !}
1198 1abb18e1 2022-12-20 op <item>
1199 1abb18e1 2022-12-20 op <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1200 1abb18e1 2022-12-20 op <link>
1201 1abb18e1 2022-12-20 op <![CDATA[
1202 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &tag) }}
1203 1abb18e1 2022-12-20 op ]]>
1204 1abb18e1 2022-12-20 op </link>
1205 1abb18e1 2022-12-20 op <description>
1206 1abb18e1 2022-12-20 op <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1207 1abb18e1 2022-12-20 op </description>
1208 1abb18e1 2022-12-20 op {{ render rss_author(tp, rt->tagger) }}
1209 1abb18e1 2022-12-20 op <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1210 1abb18e1 2022-12-20 op <pubDate>
1211 bf26a633 2023-10-05 op {{ rfc822 }}
1212 1abb18e1 2022-12-20 op </pubDate>
1213 1abb18e1 2022-12-20 op </item>
1214 156a1144 2022-12-17 op {{ end }}
1215 1abb18e1 2022-12-20 op
1216 1abb18e1 2022-12-20 op {{ define rss_author(struct template *tp, char *author) }}
1217 1abb18e1 2022-12-20 op {!
1218 1abb18e1 2022-12-20 op char *t, *mail;
1219 1abb18e1 2022-12-20 op
1220 1abb18e1 2022-12-20 op /* what to do if the author name contains a paren? */
1221 1abb18e1 2022-12-20 op if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1222 1abb18e1 2022-12-20 op return 0;
1223 1abb18e1 2022-12-20 op
1224 1abb18e1 2022-12-20 op t = strchr(author, '<');
1225 1abb18e1 2022-12-20 op if (t == NULL)
1226 1abb18e1 2022-12-20 op return 0;
1227 1abb18e1 2022-12-20 op *t = '\0';
1228 1abb18e1 2022-12-20 op mail = t+1;
1229 1abb18e1 2022-12-20 op
1230 1abb18e1 2022-12-20 op while (isspace((unsigned char)*--t))
1231 1abb18e1 2022-12-20 op *t = '\0';
1232 1abb18e1 2022-12-20 op
1233 1abb18e1 2022-12-20 op t = strchr(mail, '>');
1234 1abb18e1 2022-12-20 op if (t == NULL)
1235 1abb18e1 2022-12-20 op return 0;
1236 1abb18e1 2022-12-20 op *t = '\0';
1237 1abb18e1 2022-12-20 op !}
1238 1abb18e1 2022-12-20 op <author>
1239 1abb18e1 2022-12-20 op {{ mail }} {{" "}} ({{ author }})
1240 1abb18e1 2022-12-20 op </author>
1241 1abb18e1 2022-12-20 op {{ end }}