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