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