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