Blame


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