Blame


1 e7e5fa49 2022-12-30 thomas {!
2 e7e5fa49 2022-12-30 thomas /*
3 e7e5fa49 2022-12-30 thomas * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 e7e5fa49 2022-12-30 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
5 e7e5fa49 2022-12-30 thomas *
6 e7e5fa49 2022-12-30 thomas * Permission to use, copy, modify, and distribute this software for any
7 e7e5fa49 2022-12-30 thomas * purpose with or without fee is hereby granted, provided that the above
8 e7e5fa49 2022-12-30 thomas * copyright notice and this permission notice appear in all copies.
9 e7e5fa49 2022-12-30 thomas *
10 e7e5fa49 2022-12-30 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 e7e5fa49 2022-12-30 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 e7e5fa49 2022-12-30 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 e7e5fa49 2022-12-30 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 e7e5fa49 2022-12-30 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 e7e5fa49 2022-12-30 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 e7e5fa49 2022-12-30 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 e7e5fa49 2022-12-30 thomas */
18 e7e5fa49 2022-12-30 thomas
19 e7e5fa49 2022-12-30 thomas #include <sys/types.h>
20 e7e5fa49 2022-12-30 thomas #include <sys/queue.h>
21 3c14c1f2 2023-01-06 thomas #include <sys/stat.h>
22 e7e5fa49 2022-12-30 thomas
23 d6795e9f 2022-12-30 thomas #include <ctype.h>
24 e7e5fa49 2022-12-30 thomas #include <event.h>
25 e7e5fa49 2022-12-30 thomas #include <stdint.h>
26 3c14c1f2 2023-01-06 thomas #include <stdio.h>
27 e7e5fa49 2022-12-30 thomas #include <stdlib.h>
28 e7e5fa49 2022-12-30 thomas #include <string.h>
29 e7e5fa49 2022-12-30 thomas #include <imsg.h>
30 e7e5fa49 2022-12-30 thomas
31 171ba12a 2023-01-06 thomas #include "got_compat.h"
32 3c14c1f2 2023-01-06 thomas #include "got_object.h"
33 3c14c1f2 2023-01-06 thomas
34 e7e5fa49 2022-12-30 thomas #include "proc.h"
35 e7e5fa49 2022-12-30 thomas
36 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
37 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
38 e7e5fa49 2022-12-30 thomas
39 b82440e1 2023-01-06 thomas static int gotweb_render_blob_line(struct template *, const char *, size_t);
40 3c14c1f2 2023-01-06 thomas static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
41 b82440e1 2023-01-06 thomas
42 5d860bce 2023-01-07 thomas static inline int gotweb_render_diff_line(struct template *, char *);
43 d6795e9f 2022-12-30 thomas static inline int rss_tag_item(struct template *, struct repo_tag *);
44 d6795e9f 2022-12-30 thomas static inline int rss_author(struct template *, char *);
45 d6795e9f 2022-12-30 thomas
46 e7e5fa49 2022-12-30 thomas static int
47 e7e5fa49 2022-12-30 thomas gotweb_render_age(struct template *tp, time_t time, int ref_tm)
48 e7e5fa49 2022-12-30 thomas {
49 e7e5fa49 2022-12-30 thomas const struct got_error *err;
50 e7e5fa49 2022-12-30 thomas char *age;
51 e7e5fa49 2022-12-30 thomas int r;
52 e7e5fa49 2022-12-30 thomas
53 e7e5fa49 2022-12-30 thomas err = gotweb_get_time_str(&age, time, ref_tm);
54 e7e5fa49 2022-12-30 thomas if (err)
55 e7e5fa49 2022-12-30 thomas return 0;
56 e7e5fa49 2022-12-30 thomas r = tp->tp_puts(tp, age);
57 e7e5fa49 2022-12-30 thomas free(age);
58 e7e5fa49 2022-12-30 thomas return r;
59 e7e5fa49 2022-12-30 thomas }
60 e7e5fa49 2022-12-30 thomas
61 e7e5fa49 2022-12-30 thomas !}
62 e7e5fa49 2022-12-30 thomas
63 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_header(struct template *tp) }}
64 e7e5fa49 2022-12-30 thomas {!
65 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
66 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
67 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
68 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
69 3191e256 2022-12-30 thomas const char *prfx = c->document_uri;
70 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
71 e7e5fa49 2022-12-30 thomas
72 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
73 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
74 e7e5fa49 2022-12-30 thomas u_path.page = -1;
75 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
76 e7e5fa49 2022-12-30 thomas !}
77 e7e5fa49 2022-12-30 thomas <!doctype html>
78 e7e5fa49 2022-12-30 thomas <html>
79 e7e5fa49 2022-12-30 thomas <head>
80 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
81 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
82 e7e5fa49 2022-12-30 thomas <meta name="viewport" content="initial-scale=.75" />
83 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
84 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
85 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
86 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
87 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
88 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
89 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
90 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
91 e7e5fa49 2022-12-30 thomas </head>
92 e7e5fa49 2022-12-30 thomas <body>
93 e7e5fa49 2022-12-30 thomas <div id="gw_body">
94 e7e5fa49 2022-12-30 thomas <div id="header">
95 e7e5fa49 2022-12-30 thomas <div id="got_link">
96 e7e5fa49 2022-12-30 thomas <a href="{{ srv->logo_url }}" target="_blank">
97 e7e5fa49 2022-12-30 thomas <img src="{{ prfx }}{{ srv->logo }}" />
98 e7e5fa49 2022-12-30 thomas </a>
99 e7e5fa49 2022-12-30 thomas </div>
100 e7e5fa49 2022-12-30 thomas </div>
101 e7e5fa49 2022-12-30 thomas <div id="site_path">
102 e7e5fa49 2022-12-30 thomas <div id="site_link">
103 e7e5fa49 2022-12-30 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
104 e7e5fa49 2022-12-30 thomas {{ srv->site_link }}
105 e7e5fa49 2022-12-30 thomas </a>
106 e7e5fa49 2022-12-30 thomas {{ if qs->path }}
107 e7e5fa49 2022-12-30 thomas {! u_path.path = qs->path; !}
108 e7e5fa49 2022-12-30 thomas {{ " / " }}
109 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
110 e7e5fa49 2022-12-30 thomas {{ qs->path }}
111 e7e5fa49 2022-12-30 thomas </a>
112 e7e5fa49 2022-12-30 thomas {{ end }}
113 e7e5fa49 2022-12-30 thomas {{ if qs->action != INDEX }}
114 e7e5fa49 2022-12-30 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
115 e7e5fa49 2022-12-30 thomas {{ end }}
116 e7e5fa49 2022-12-30 thomas </div>
117 e7e5fa49 2022-12-30 thomas </div>
118 e7e5fa49 2022-12-30 thomas <div id="content">
119 e7e5fa49 2022-12-30 thomas {{ end }}
120 e7e5fa49 2022-12-30 thomas
121 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_footer(struct template *tp) }}
122 e7e5fa49 2022-12-30 thomas {!
123 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
124 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
125 e7e5fa49 2022-12-30 thomas !}
126 e7e5fa49 2022-12-30 thomas <div id="site_owner_wrapper">
127 e7e5fa49 2022-12-30 thomas <div id="site_owner">
128 e7e5fa49 2022-12-30 thomas {{ if srv->show_site_owner }}
129 e7e5fa49 2022-12-30 thomas {{ srv->site_owner }}
130 e7e5fa49 2022-12-30 thomas {{ end }}
131 e7e5fa49 2022-12-30 thomas </div>
132 e7e5fa49 2022-12-30 thomas </div>
133 e7e5fa49 2022-12-30 thomas </div>
134 e7e5fa49 2022-12-30 thomas </div>
135 e7e5fa49 2022-12-30 thomas </body>
136 e7e5fa49 2022-12-30 thomas </html>
137 e7e5fa49 2022-12-30 thomas {{ end }}
138 e7e5fa49 2022-12-30 thomas
139 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
140 e7e5fa49 2022-12-30 thomas {!
141 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
142 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
143 e7e5fa49 2022-12-30 thomas !}
144 e7e5fa49 2022-12-30 thomas <div id="index_header">
145 e7e5fa49 2022-12-30 thomas <div id="index_header_project">
146 e7e5fa49 2022-12-30 thomas Project
147 e7e5fa49 2022-12-30 thomas </div>
148 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
149 e7e5fa49 2022-12-30 thomas <div id="index_header_description">
150 e7e5fa49 2022-12-30 thomas Description
151 e7e5fa49 2022-12-30 thomas </div>
152 e7e5fa49 2022-12-30 thomas {{ end }}
153 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
154 e7e5fa49 2022-12-30 thomas <div id="index_header_owner">
155 e7e5fa49 2022-12-30 thomas Owner
156 e7e5fa49 2022-12-30 thomas </div>
157 e7e5fa49 2022-12-30 thomas {{ end }}
158 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
159 e7e5fa49 2022-12-30 thomas <div id="index_header_age">
160 e7e5fa49 2022-12-30 thomas Last Change
161 e7e5fa49 2022-12-30 thomas </div>
162 e7e5fa49 2022-12-30 thomas {{ end }}
163 e7e5fa49 2022-12-30 thomas </div>
164 e7e5fa49 2022-12-30 thomas {{ end }}
165 e7e5fa49 2022-12-30 thomas
166 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
167 e7e5fa49 2022-12-30 thomas {!
168 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
169 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
170 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
171 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
172 e7e5fa49 2022-12-30 thomas .index_page = -1,
173 e7e5fa49 2022-12-30 thomas .page = -1,
174 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
175 e7e5fa49 2022-12-30 thomas }, briefs = {
176 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
177 e7e5fa49 2022-12-30 thomas .index_page = -1,
178 e7e5fa49 2022-12-30 thomas .page = -1,
179 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
180 e7e5fa49 2022-12-30 thomas }, commits = {
181 e7e5fa49 2022-12-30 thomas .action = COMMITS,
182 e7e5fa49 2022-12-30 thomas .index_page = -1,
183 e7e5fa49 2022-12-30 thomas .page = -1,
184 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
185 e7e5fa49 2022-12-30 thomas }, tags = {
186 e7e5fa49 2022-12-30 thomas .action = TAGS,
187 e7e5fa49 2022-12-30 thomas .index_page = -1,
188 e7e5fa49 2022-12-30 thomas .page = -1,
189 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
190 e7e5fa49 2022-12-30 thomas }, tree = {
191 e7e5fa49 2022-12-30 thomas .action = TREE,
192 e7e5fa49 2022-12-30 thomas .index_page = -1,
193 e7e5fa49 2022-12-30 thomas .page = -1,
194 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
195 d6795e9f 2022-12-30 thomas }, rss = {
196 d6795e9f 2022-12-30 thomas .action = RSS,
197 d6795e9f 2022-12-30 thomas .index_page = -1,
198 d6795e9f 2022-12-30 thomas .page = -1,
199 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
200 e7e5fa49 2022-12-30 thomas };
201 e7e5fa49 2022-12-30 thomas !}
202 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
203 e7e5fa49 2022-12-30 thomas <div class="index_project">
204 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
205 e7e5fa49 2022-12-30 thomas </div>
206 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
207 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
208 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
209 e7e5fa49 2022-12-30 thomas </div>
210 e7e5fa49 2022-12-30 thomas {{ end }}
211 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
212 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
213 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
214 e7e5fa49 2022-12-30 thomas </div>
215 e7e5fa49 2022-12-30 thomas {{ end }}
216 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
217 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
218 e7e5fa49 2022-12-30 thomas {{ repo_dir->age }}
219 e7e5fa49 2022-12-30 thomas </div>
220 e7e5fa49 2022-12-30 thomas {{ end }}
221 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
222 e7e5fa49 2022-12-30 thomas <div class="navs">
223 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
224 e7e5fa49 2022-12-30 thomas {{ " | " }}
225 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
226 e7e5fa49 2022-12-30 thomas {{ " | " }}
227 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
228 e7e5fa49 2022-12-30 thomas {{ " | " }}
229 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
230 e7e5fa49 2022-12-30 thomas {{ " | " }}
231 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
232 d6795e9f 2022-12-30 thomas {{ " | " }}
233 d6795e9f 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
234 e7e5fa49 2022-12-30 thomas </div>
235 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
236 e7e5fa49 2022-12-30 thomas </div>
237 e7e5fa49 2022-12-30 thomas </div>
238 e7e5fa49 2022-12-30 thomas {{ end }}
239 e7e5fa49 2022-12-30 thomas
240 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
241 e7e5fa49 2022-12-30 thomas {!
242 e7e5fa49 2022-12-30 thomas const struct got_error *error;
243 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
244 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
245 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
246 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
247 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
248 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
249 e7e5fa49 2022-12-30 thomas struct gotweb_url diff_url, tree_url;
250 e7e5fa49 2022-12-30 thomas char *tmp;
251 e7e5fa49 2022-12-30 thomas
252 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
253 e7e5fa49 2022-12-30 thomas .action = DIFF,
254 e7e5fa49 2022-12-30 thomas .index_page = -1,
255 e7e5fa49 2022-12-30 thomas .page = -1,
256 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
257 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
258 e7e5fa49 2022-12-30 thomas };
259 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
260 e7e5fa49 2022-12-30 thomas .action = TREE,
261 e7e5fa49 2022-12-30 thomas .index_page = -1,
262 e7e5fa49 2022-12-30 thomas .page = -1,
263 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
264 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
265 e7e5fa49 2022-12-30 thomas };
266 e7e5fa49 2022-12-30 thomas
267 e7e5fa49 2022-12-30 thomas if (qs->action == SUMMARY) {
268 e7e5fa49 2022-12-30 thomas qs->action = BRIEFS;
269 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
270 e7e5fa49 2022-12-30 thomas } else
271 e7e5fa49 2022-12-30 thomas error = got_get_repo_commits(c, srv->max_commits_display);
272 e7e5fa49 2022-12-30 thomas if (error)
273 e7e5fa49 2022-12-30 thomas return -1;
274 e7e5fa49 2022-12-30 thomas !}
275 e7e5fa49 2022-12-30 thomas <div id="briefs_title_wrapper">
276 e7e5fa49 2022-12-30 thomas <div id="briefs_title">Commit Briefs</div>
277 e7e5fa49 2022-12-30 thomas </div>
278 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
279 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
280 e7e5fa49 2022-12-30 thomas {!
281 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
282 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
283 e7e5fa49 2022-12-30 thomas
284 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->author, '<');
285 e7e5fa49 2022-12-30 thomas if (tmp)
286 e7e5fa49 2022-12-30 thomas *tmp = '\0';
287 e7e5fa49 2022-12-30 thomas
288 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
289 e7e5fa49 2022-12-30 thomas if (tmp)
290 e7e5fa49 2022-12-30 thomas *tmp = '\0';
291 e7e5fa49 2022-12-30 thomas !}
292 e7e5fa49 2022-12-30 thomas <div class="briefs_age">
293 e7e5fa49 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
294 e7e5fa49 2022-12-30 thomas </div>
295 e7e5fa49 2022-12-30 thomas <div class="briefs_author">
296 e7e5fa49 2022-12-30 thomas {{ rc->author }}
297 e7e5fa49 2022-12-30 thomas </div>
298 e7e5fa49 2022-12-30 thomas <div class="briefs_log">
299 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
300 e7e5fa49 2022-12-30 thomas {{ rc->commit_msg }}
301 e7e5fa49 2022-12-30 thomas </a>
302 e7e5fa49 2022-12-30 thomas {{ if rc->refs_str }}
303 e7e5fa49 2022-12-30 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
304 e7e5fa49 2022-12-30 thomas {{ end }}
305 e7e5fa49 2022-12-30 thomas </a>
306 e7e5fa49 2022-12-30 thomas </div>
307 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
308 e7e5fa49 2022-12-30 thomas <div class="navs">
309 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
310 e7e5fa49 2022-12-30 thomas {{ " | " }}
311 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
312 e7e5fa49 2022-12-30 thomas </div>
313 e7e5fa49 2022-12-30 thomas </div>
314 e7e5fa49 2022-12-30 thomas <div class="dotted_line"></div>
315 e7e5fa49 2022-12-30 thomas {{ end }}
316 e7e5fa49 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
317 2f4f0731 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
318 e7e5fa49 2022-12-30 thomas {{ end }}
319 2f4f0731 2022-12-30 thomas </div>
320 2f4f0731 2022-12-30 thomas {{ end }}
321 2f4f0731 2022-12-30 thomas
322 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
323 2f4f0731 2022-12-30 thomas {!
324 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
325 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
326 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
327 2f4f0731 2022-12-30 thomas int have_prev, have_next;
328 2f4f0731 2022-12-30 thomas
329 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
330 2f4f0731 2022-12-30 thomas !}
331 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
332 2f4f0731 2022-12-30 thomas <div id="nav_prev">
333 2f4f0731 2022-12-30 thomas {{ if have_prev }}
334 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
335 2f4f0731 2022-12-30 thomas Previous
336 2f4f0731 2022-12-30 thomas </a>
337 2f4f0731 2022-12-30 thomas {{ end }}
338 2f4f0731 2022-12-30 thomas </div>
339 2f4f0731 2022-12-30 thomas <div id="nav_next">
340 2f4f0731 2022-12-30 thomas {{ if have_next }}
341 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
342 2f4f0731 2022-12-30 thomas Next
343 2f4f0731 2022-12-30 thomas </a>
344 2f4f0731 2022-12-30 thomas {{ end }}
345 2f4f0731 2022-12-30 thomas </div>
346 e7e5fa49 2022-12-30 thomas </div>
347 2f4f0731 2022-12-30 thomas {{ finally }}
348 2f4f0731 2022-12-30 thomas {!
349 2f4f0731 2022-12-30 thomas free(t->next_id);
350 2f4f0731 2022-12-30 thomas t->next_id = NULL;
351 2f4f0731 2022-12-30 thomas free(t->prev_id);
352 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
353 2f4f0731 2022-12-30 thomas !}
354 e7e5fa49 2022-12-30 thomas {{ end }}
355 7ade8b27 2022-12-30 thomas
356 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
357 7ade8b27 2022-12-30 thomas {!
358 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
359 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
360 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
361 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
362 7ade8b27 2022-12-30 thomas struct gotweb_url diff, tree;
363 7ade8b27 2022-12-30 thomas
364 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
365 7ade8b27 2022-12-30 thomas .action = DIFF,
366 7ade8b27 2022-12-30 thomas .index_page = -1,
367 7ade8b27 2022-12-30 thomas .page = -1,
368 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
369 7ade8b27 2022-12-30 thomas };
370 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
371 7ade8b27 2022-12-30 thomas .action = TREE,
372 7ade8b27 2022-12-30 thomas .index_page = -1,
373 7ade8b27 2022-12-30 thomas .page = -1,
374 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
375 7ade8b27 2022-12-30 thomas };
376 7ade8b27 2022-12-30 thomas !}
377 7ade8b27 2022-12-30 thomas <div class="commits_title_wrapper">
378 7ade8b27 2022-12-30 thomas <div class="commits_title">Commits</div>
379 7ade8b27 2022-12-30 thomas </div>
380 7ade8b27 2022-12-30 thomas <div class="commits_content">
381 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
382 7ade8b27 2022-12-30 thomas {!
383 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
384 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
385 7ade8b27 2022-12-30 thomas !}
386 7ade8b27 2022-12-30 thomas <div class="commits_header_wrapper">
387 7ade8b27 2022-12-30 thomas <div class="commits_header">
388 7ade8b27 2022-12-30 thomas <div class="header_commit_title">Commit:</div>
389 7ade8b27 2022-12-30 thomas <div class="header_commit">{{ rc->commit_id }}</div>
390 7ade8b27 2022-12-30 thomas <div class="header_author_title">Author:</div>
391 7ade8b27 2022-12-30 thomas <div class="header_author">{{ rc->author }}</div>
392 7ade8b27 2022-12-30 thomas <div class="header_age_title">Date:</div>
393 7ade8b27 2022-12-30 thomas <div class="header_age">
394 7ade8b27 2022-12-30 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
395 7ade8b27 2022-12-30 thomas </div>
396 7ade8b27 2022-12-30 thomas </div>
397 7ade8b27 2022-12-30 thomas </div>
398 bbf94fd6 2023-01-02 thomas <div class="dotted_line"></div>
399 bbf94fd6 2023-01-02 thomas <div class="commit">
400 bbf94fd6 2023-01-02 thomas {{ "\n" }}
401 bbf94fd6 2023-01-02 thomas {{ rc->commit_msg }}
402 bbf94fd6 2023-01-02 thomas </div>
403 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
404 7ade8b27 2022-12-30 thomas <div class="navs">
405 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
406 7ade8b27 2022-12-30 thomas {{ " | " }}
407 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
408 7ade8b27 2022-12-30 thomas </div>
409 7ade8b27 2022-12-30 thomas </div>
410 7ade8b27 2022-12-30 thomas <div class="dotted_line"></div>
411 7ade8b27 2022-12-30 thomas {{ end }}
412 7ade8b27 2022-12-30 thomas {{ if t->next_id || t->prev_id }}
413 7ade8b27 2022-12-30 thomas {{ render gotweb_render_navs(tp) }}
414 7ade8b27 2022-12-30 thomas {{ end }}
415 b82440e1 2023-01-06 thomas </div>
416 b82440e1 2023-01-06 thomas {{ end }}
417 b82440e1 2023-01-06 thomas
418 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob(struct template *tp,
419 b82440e1 2023-01-06 thomas struct got_blob_object *blob) }}
420 b82440e1 2023-01-06 thomas {!
421 b82440e1 2023-01-06 thomas struct request *c = tp->tp_arg;
422 b82440e1 2023-01-06 thomas struct transport *t = c->t;
423 b82440e1 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
424 b82440e1 2023-01-06 thomas !}
425 b82440e1 2023-01-06 thomas <div id="blob_title_wrapper">
426 b82440e1 2023-01-06 thomas <div id="blob_title">Blob</div>
427 b82440e1 2023-01-06 thomas </div>
428 b82440e1 2023-01-06 thomas <div id="blob_content">
429 b82440e1 2023-01-06 thomas <div id="blob_header_wrapper">
430 b82440e1 2023-01-06 thomas <div id="blob_header">
431 b82440e1 2023-01-06 thomas <div class="header_age_title">Date:</div>
432 b82440e1 2023-01-06 thomas <div class="header_age">
433 b82440e1 2023-01-06 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
434 b82440e1 2023-01-06 thomas </div>
435 b82440e1 2023-01-06 thomas <div id="header_commit_msg_title">Message:</div>
436 b82440e1 2023-01-06 thomas <div id="header_commit_msg">{{ rc->commit_msg }}</div>
437 b82440e1 2023-01-06 thomas </div>
438 b82440e1 2023-01-06 thomas </div>
439 b82440e1 2023-01-06 thomas <div class="dotted_line"></div>
440 b82440e1 2023-01-06 thomas <div id="blob">
441 b82440e1 2023-01-06 thomas <pre>
442 b82440e1 2023-01-06 thomas {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
443 b82440e1 2023-01-06 thomas </pre>
444 b82440e1 2023-01-06 thomas </div>
445 7ade8b27 2022-12-30 thomas </div>
446 d6795e9f 2022-12-30 thomas {{ end }}
447 d6795e9f 2022-12-30 thomas
448 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob_line(struct template *tp, const char *line,
449 b82440e1 2023-01-06 thomas size_t no) }}
450 b82440e1 2023-01-06 thomas {!
451 b82440e1 2023-01-06 thomas char lineno[16];
452 b82440e1 2023-01-06 thomas int r;
453 b82440e1 2023-01-06 thomas
454 b82440e1 2023-01-06 thomas r = snprintf(lineno, sizeof(lineno), "%zu", no);
455 b82440e1 2023-01-06 thomas if (r < 0 || (size_t)r >= sizeof(lineno))
456 b82440e1 2023-01-06 thomas return -1;
457 b82440e1 2023-01-06 thomas !}
458 b82440e1 2023-01-06 thomas <div class="blob_line" id="line{{ lineno }}">
459 b82440e1 2023-01-06 thomas <div class="blob_number">
460 b82440e1 2023-01-06 thomas <a href="#line{{ lineno }}">{{ lineno }}</a>
461 b82440e1 2023-01-06 thomas </div>
462 b82440e1 2023-01-06 thomas <div class="blob_code">{{ line }}</div>
463 3c14c1f2 2023-01-06 thomas </div>
464 3c14c1f2 2023-01-06 thomas {{ end }}
465 3c14c1f2 2023-01-06 thomas
466 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree(struct template *tp) }}
467 3c14c1f2 2023-01-06 thomas {!
468 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
469 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
470 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
471 3c14c1f2 2023-01-06 thomas !}
472 3c14c1f2 2023-01-06 thomas <div id="tree_title_wrapper">
473 3c14c1f2 2023-01-06 thomas <div id="tree_title">Tree</div>
474 3c14c1f2 2023-01-06 thomas </div>
475 3c14c1f2 2023-01-06 thomas <div id="tree_content">
476 3c14c1f2 2023-01-06 thomas <div id="tree_header_wrapper">
477 3c14c1f2 2023-01-06 thomas <div id="tree_header">
478 3c14c1f2 2023-01-06 thomas <div id="header_tree_title">Tree:</div>
479 3c14c1f2 2023-01-06 thomas <div id="header_tree">{{ rc->tree_id }}</div>
480 3c14c1f2 2023-01-06 thomas <div class="header_age_title">Date:</div>
481 3c14c1f2 2023-01-06 thomas <div class="header_age">
482 3c14c1f2 2023-01-06 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
483 3c14c1f2 2023-01-06 thomas </div>
484 3c14c1f2 2023-01-06 thomas <div id="header_commit_msg_title">Message:</div>
485 3c14c1f2 2023-01-06 thomas <div id="header_commit_msg">{{ rc->commit_msg }}</div>
486 3c14c1f2 2023-01-06 thomas </div>
487 3c14c1f2 2023-01-06 thomas </div>
488 3c14c1f2 2023-01-06 thomas <div class="dotted_line"></div>
489 3c14c1f2 2023-01-06 thomas <div id="tree">
490 3c14c1f2 2023-01-06 thomas {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
491 3c14c1f2 2023-01-06 thomas </div>
492 3c14c1f2 2023-01-06 thomas </div>
493 3c14c1f2 2023-01-06 thomas {{ end }}
494 3c14c1f2 2023-01-06 thomas
495 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree_item(struct template *tp,
496 3c14c1f2 2023-01-06 thomas struct got_tree_entry *te) }}
497 3c14c1f2 2023-01-06 thomas {!
498 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
499 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
500 3c14c1f2 2023-01-06 thomas struct querystring *qs = t->qs;
501 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
502 3c14c1f2 2023-01-06 thomas const char *modestr = "";
503 3c14c1f2 2023-01-06 thomas const char *name;
504 3c14c1f2 2023-01-06 thomas const char *folder;
505 3c14c1f2 2023-01-06 thomas char *dir = NULL;
506 3c14c1f2 2023-01-06 thomas mode_t mode;
507 3c14c1f2 2023-01-06 thomas struct gotweb_url url = {
508 3c14c1f2 2023-01-06 thomas .index_page = -1,
509 3c14c1f2 2023-01-06 thomas .page = -1,
510 3c14c1f2 2023-01-06 thomas .commit = rc->commit_id,
511 3c14c1f2 2023-01-06 thomas .path = qs->path,
512 3c14c1f2 2023-01-06 thomas };
513 3c14c1f2 2023-01-06 thomas
514 3c14c1f2 2023-01-06 thomas name = got_tree_entry_get_name(te);
515 3c14c1f2 2023-01-06 thomas mode = got_tree_entry_get_mode(te);
516 3c14c1f2 2023-01-06 thomas
517 3c14c1f2 2023-01-06 thomas folder = qs->folder ? qs->folder : "";
518 3c14c1f2 2023-01-06 thomas if (S_ISDIR(mode)) {
519 3c14c1f2 2023-01-06 thomas if (asprintf(&dir, "%s/%s", folder, name) == -1)
520 3c14c1f2 2023-01-06 thomas return (-1);
521 3c14c1f2 2023-01-06 thomas
522 3c14c1f2 2023-01-06 thomas url.action = TREE;
523 3c14c1f2 2023-01-06 thomas url.folder = dir;
524 3c14c1f2 2023-01-06 thomas } else {
525 3c14c1f2 2023-01-06 thomas url.action = BLOB;
526 3c14c1f2 2023-01-06 thomas url.folder = folder;
527 3c14c1f2 2023-01-06 thomas url.file = name;
528 3c14c1f2 2023-01-06 thomas }
529 3c14c1f2 2023-01-06 thomas
530 3c14c1f2 2023-01-06 thomas if (got_object_tree_entry_is_submodule(te))
531 3c14c1f2 2023-01-06 thomas modestr = "$";
532 3c14c1f2 2023-01-06 thomas else if (S_ISLNK(mode))
533 3c14c1f2 2023-01-06 thomas modestr = "@";
534 3c14c1f2 2023-01-06 thomas else if (S_ISDIR(mode))
535 3c14c1f2 2023-01-06 thomas modestr = "/";
536 3c14c1f2 2023-01-06 thomas else if (mode & S_IXUSR)
537 3c14c1f2 2023-01-06 thomas modestr = "*";
538 3c14c1f2 2023-01-06 thomas !}
539 3c14c1f2 2023-01-06 thomas <div class="tree_wrapper">
540 3c14c1f2 2023-01-06 thomas {{ if S_ISDIR(mode) }}
541 3c14c1f2 2023-01-06 thomas <div class="tree_line">
542 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
543 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
544 3c14c1f2 2023-01-06 thomas </a>
545 3c14c1f2 2023-01-06 thomas </div>
546 3c14c1f2 2023-01-06 thomas <div class="tree_line_blank">&nbsp;</div>
547 3c14c1f2 2023-01-06 thomas {{ else }}
548 3c14c1f2 2023-01-06 thomas <div class="tree_line">
549 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
550 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
551 3c14c1f2 2023-01-06 thomas </a>
552 3c14c1f2 2023-01-06 thomas </div>
553 3c14c1f2 2023-01-06 thomas <div class="tree_line_blank">
554 3c14c1f2 2023-01-06 thomas {! url.action = COMMITS; !}
555 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
556 3c14c1f2 2023-01-06 thomas commits
557 3c14c1f2 2023-01-06 thomas </a>
558 3c14c1f2 2023-01-06 thomas {{ " | " }}
559 3c14c1f2 2023-01-06 thomas {! url.action = BLAME; !}
560 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
561 3c14c1f2 2023-01-06 thomas blame
562 3c14c1f2 2023-01-06 thomas </a>
563 3c14c1f2 2023-01-06 thomas </div>
564 3c14c1f2 2023-01-06 thomas {{ end }}
565 b82440e1 2023-01-06 thomas </div>
566 3c14c1f2 2023-01-06 thomas {{ finally }}
567 3c14c1f2 2023-01-06 thomas {!
568 3c14c1f2 2023-01-06 thomas free(dir);
569 5d860bce 2023-01-07 thomas !}
570 5d860bce 2023-01-07 thomas {{ end }}
571 5d860bce 2023-01-07 thomas
572 5d860bce 2023-01-07 thomas {{ define gotweb_render_diff(struct template *tp, FILE *fp) }}
573 5d860bce 2023-01-07 thomas {!
574 5d860bce 2023-01-07 thomas struct request *c = tp->tp_arg;
575 5d860bce 2023-01-07 thomas struct transport *t = c->t;
576 5d860bce 2023-01-07 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
577 5d860bce 2023-01-07 thomas char *line = NULL;
578 5d860bce 2023-01-07 thomas size_t linesize = 0;
579 5d860bce 2023-01-07 thomas ssize_t linelen;
580 5d860bce 2023-01-07 thomas !}
581 5d860bce 2023-01-07 thomas <div id="diff_title_wrapper">
582 5d860bce 2023-01-07 thomas <div id="diff_title">Commit Diff</div>
583 5d860bce 2023-01-07 thomas </div>
584 5d860bce 2023-01-07 thomas <div id="diff_content">
585 5d860bce 2023-01-07 thomas <div id="diff_header_wrapper">
586 5d860bce 2023-01-07 thomas <div id="diff_header">
587 5d860bce 2023-01-07 thomas <div id="header_diff_title">Diff:</div>
588 5d860bce 2023-01-07 thomas <div id="header_diff">
589 5d860bce 2023-01-07 thomas {{ rc->parent_id }}
590 5d860bce 2023-01-07 thomas <br />
591 5d860bce 2023-01-07 thomas {{ rc->commit_id }}
592 5d860bce 2023-01-07 thomas </div>
593 5d860bce 2023-01-07 thomas <div class="header_commit_title">Commit:</div>
594 5d860bce 2023-01-07 thomas <div class="header_commit">{{ rc->commit_id }}</div>
595 5d860bce 2023-01-07 thomas <div id="header_tree_title">Tree:</div>
596 5d860bce 2023-01-07 thomas <div id="header_tree">{{ rc->tree_id }}</div>
597 5d860bce 2023-01-07 thomas <div class="header_author_title">Author:</div>
598 5d860bce 2023-01-07 thomas <div class="header_author">{{ rc->author }}</div>
599 5d860bce 2023-01-07 thomas <div class="header_age_title">Date:</div>
600 5d860bce 2023-01-07 thomas <div class="header_age">
601 5d860bce 2023-01-07 thomas {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
602 5d860bce 2023-01-07 thomas </div>
603 5d860bce 2023-01-07 thomas <div id="header_commit_msg_title">Message</div>
604 5d860bce 2023-01-07 thomas <div id="header_commit_msg">{{ rc->commit_msg }}</div>
605 5d860bce 2023-01-07 thomas </div>
606 5d860bce 2023-01-07 thomas </div>
607 5d860bce 2023-01-07 thomas <div class="dotted_line"></div>
608 5d860bce 2023-01-07 thomas <div id="diff">
609 5d860bce 2023-01-07 thomas {{ "\n" }}
610 5d860bce 2023-01-07 thomas {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
611 5d860bce 2023-01-07 thomas {{ render gotweb_render_diff_line(tp, line) }}
612 5d860bce 2023-01-07 thomas {{ end }}
613 5d860bce 2023-01-07 thomas </div>
614 5d860bce 2023-01-07 thomas </div>
615 5d860bce 2023-01-07 thomas {{ finally }}
616 5d860bce 2023-01-07 thomas {! free(line); !}
617 5d860bce 2023-01-07 thomas {{ end }}
618 5d860bce 2023-01-07 thomas
619 5d860bce 2023-01-07 thomas {{ define gotweb_render_diff_line(struct template *tp, char *line )}}
620 5d860bce 2023-01-07 thomas {!
621 5d860bce 2023-01-07 thomas const char *color = NULL;
622 5d860bce 2023-01-07 thomas char *nl;
623 5d860bce 2023-01-07 thomas
624 5d860bce 2023-01-07 thomas if (!strncmp(line, "-", 1))
625 5d860bce 2023-01-07 thomas color = "diff_minus";
626 5d860bce 2023-01-07 thomas else if (!strncmp(line, "+", 1))
627 5d860bce 2023-01-07 thomas color = "diff_plus";
628 5d860bce 2023-01-07 thomas else if (!strncmp(line, "@@", 2))
629 5d860bce 2023-01-07 thomas color = "diff_chunk_header";
630 5d860bce 2023-01-07 thomas else if (!strncmp(line, "commit +", 8) ||
631 5d860bce 2023-01-07 thomas !strncmp(line, "commit -", 8) ||
632 5d860bce 2023-01-07 thomas !strncmp(line, "blob +", 6) ||
633 5d860bce 2023-01-07 thomas !strncmp(line, "blob -", 6) ||
634 5d860bce 2023-01-07 thomas !strncmp(line, "file +", 6) ||
635 5d860bce 2023-01-07 thomas !strncmp(line, "file -", 6))
636 5d860bce 2023-01-07 thomas color = "diff_meta";
637 5d860bce 2023-01-07 thomas else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
638 5d860bce 2023-01-07 thomas color = "diff_author";
639 5d860bce 2023-01-07 thomas else if (!strncmp(line, "date:", 5))
640 5d860bce 2023-01-07 thomas color = "diff_date";
641 5d860bce 2023-01-07 thomas
642 5d860bce 2023-01-07 thomas nl = strchr(line, '\n');
643 5d860bce 2023-01-07 thomas if (nl)
644 5d860bce 2023-01-07 thomas *nl = '\0';
645 3c14c1f2 2023-01-06 thomas !}
646 5d860bce 2023-01-07 thomas <div class="diff_line {{ color }}">{{ line }}</div>
647 b82440e1 2023-01-06 thomas {{ end }}
648 b82440e1 2023-01-06 thomas
649 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
650 d6795e9f 2022-12-30 thomas {!
651 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
652 d6795e9f 2022-12-30 thomas struct server *srv = c->srv;
653 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
654 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
655 d6795e9f 2022-12-30 thomas struct repo_tag *rt;
656 d6795e9f 2022-12-30 thomas struct gotweb_url summary = {
657 d6795e9f 2022-12-30 thomas .action = SUMMARY,
658 d6795e9f 2022-12-30 thomas .index_page = -1,
659 d6795e9f 2022-12-30 thomas .page = -1,
660 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
661 d6795e9f 2022-12-30 thomas };
662 d6795e9f 2022-12-30 thomas !}
663 d6795e9f 2022-12-30 thomas <?xml version="1.0" encoding="UTF-8"?>
664 d6795e9f 2022-12-30 thomas <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
665 d6795e9f 2022-12-30 thomas <channel>
666 d6795e9f 2022-12-30 thomas <title>Tags of {{ repo_dir->name }}</title>
667 d6795e9f 2022-12-30 thomas <link>
668 d6795e9f 2022-12-30 thomas <![CDATA[
669 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
670 d6795e9f 2022-12-30 thomas ]]>
671 d6795e9f 2022-12-30 thomas </link>
672 d6795e9f 2022-12-30 thomas {{ if srv->show_repo_description }}
673 d6795e9f 2022-12-30 thomas <description>{{ repo_dir->description }}</description>
674 d6795e9f 2022-12-30 thomas {{ end }}
675 d6795e9f 2022-12-30 thomas {{ tailq-foreach rt &t->repo_tags entry }}
676 d6795e9f 2022-12-30 thomas {{ render rss_tag_item(tp, rt) }}
677 d6795e9f 2022-12-30 thomas {{ end }}
678 d6795e9f 2022-12-30 thomas </channel>
679 d6795e9f 2022-12-30 thomas </rss>
680 d6795e9f 2022-12-30 thomas {{ end }}
681 d6795e9f 2022-12-30 thomas
682 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
683 d6795e9f 2022-12-30 thomas {!
684 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
685 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
686 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
687 d6795e9f 2022-12-30 thomas char *tag_name = rt->tag_name;
688 d6795e9f 2022-12-30 thomas struct gotweb_url tag = {
689 d6795e9f 2022-12-30 thomas .action = TAG,
690 d6795e9f 2022-12-30 thomas .index_page = -1,
691 d6795e9f 2022-12-30 thomas .page = -1,
692 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
693 d6795e9f 2022-12-30 thomas .commit = rt->commit_id,
694 d6795e9f 2022-12-30 thomas };
695 d6795e9f 2022-12-30 thomas
696 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
697 d6795e9f 2022-12-30 thomas tag_name += 10;
698 d6795e9f 2022-12-30 thomas !}
699 d6795e9f 2022-12-30 thomas <item>
700 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
701 d6795e9f 2022-12-30 thomas <link>
702 d6795e9f 2022-12-30 thomas <![CDATA[
703 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
704 d6795e9f 2022-12-30 thomas ]]>
705 d6795e9f 2022-12-30 thomas </link>
706 d6795e9f 2022-12-30 thomas <description>
707 d6795e9f 2022-12-30 thomas <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
708 d6795e9f 2022-12-30 thomas </description>
709 d6795e9f 2022-12-30 thomas {{ render rss_author(tp, rt->tagger) }}
710 d6795e9f 2022-12-30 thomas <guid isPermaLink="false">{{ rt->commit_id }}</guid>
711 d6795e9f 2022-12-30 thomas <pubDate>
712 d6795e9f 2022-12-30 thomas {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
713 d6795e9f 2022-12-30 thomas </pubDate>
714 d6795e9f 2022-12-30 thomas </item>
715 7ade8b27 2022-12-30 thomas {{ end }}
716 d6795e9f 2022-12-30 thomas
717 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
718 d6795e9f 2022-12-30 thomas {!
719 d6795e9f 2022-12-30 thomas char *t, *mail;
720 d6795e9f 2022-12-30 thomas
721 d6795e9f 2022-12-30 thomas /* what to do if the author name contains a paren? */
722 d6795e9f 2022-12-30 thomas if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
723 d6795e9f 2022-12-30 thomas return 0;
724 d6795e9f 2022-12-30 thomas
725 d6795e9f 2022-12-30 thomas t = strchr(author, '<');
726 d6795e9f 2022-12-30 thomas if (t == NULL)
727 d6795e9f 2022-12-30 thomas return 0;
728 d6795e9f 2022-12-30 thomas *t = '\0';
729 d6795e9f 2022-12-30 thomas mail = t+1;
730 d6795e9f 2022-12-30 thomas
731 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
732 d6795e9f 2022-12-30 thomas *t = '\0';
733 d6795e9f 2022-12-30 thomas
734 d6795e9f 2022-12-30 thomas t = strchr(mail, '>');
735 d6795e9f 2022-12-30 thomas if (t == NULL)
736 d6795e9f 2022-12-30 thomas return 0;
737 d6795e9f 2022-12-30 thomas *t = '\0';
738 d6795e9f 2022-12-30 thomas !}
739 d6795e9f 2022-12-30 thomas <author>
740 d6795e9f 2022-12-30 thomas {{ mail }} {{" "}} ({{ author }})
741 d6795e9f 2022-12-30 thomas </author>
742 d6795e9f 2022-12-30 thomas {{ end }}