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