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