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