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