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 4fccd2fe 2023-03-08 thomas
19 4fccd2fe 2023-03-08 thomas #include "got_compat.h"
20 e7e5fa49 2022-12-30 thomas
21 e7e5fa49 2022-12-30 thomas #include <sys/types.h>
22 e7e5fa49 2022-12-30 thomas #include <sys/queue.h>
23 3c14c1f2 2023-01-06 thomas #include <sys/stat.h>
24 e7e5fa49 2022-12-30 thomas
25 d6795e9f 2022-12-30 thomas #include <ctype.h>
26 e7e5fa49 2022-12-30 thomas #include <event.h>
27 e7e5fa49 2022-12-30 thomas #include <stdint.h>
28 3c14c1f2 2023-01-06 thomas #include <stdio.h>
29 e7e5fa49 2022-12-30 thomas #include <stdlib.h>
30 e7e5fa49 2022-12-30 thomas #include <string.h>
31 e7e5fa49 2022-12-30 thomas #include <imsg.h>
32 e7e5fa49 2022-12-30 thomas
33 00abe30b 2023-01-14 thomas #include "got_error.h"
34 3c14c1f2 2023-01-06 thomas #include "got_object.h"
35 00abe30b 2023-01-14 thomas #include "got_reference.h"
36 e7e5fa49 2022-12-30 thomas
37 e7e5fa49 2022-12-30 thomas #include "gotwebd.h"
38 e7e5fa49 2022-12-30 thomas #include "tmpl.h"
39 e7e5fa49 2022-12-30 thomas
40 4cc0851e 2023-10-08 thomas enum gotweb_ref_tm {
41 4cc0851e 2023-10-08 thomas TM_DIFF,
42 4cc0851e 2023-10-08 thomas TM_LONG,
43 4cc0851e 2023-10-08 thomas };
44 4cc0851e 2023-10-08 thomas
45 6da1aa18 2023-12-01 thomas static int breadcumbs(struct template *);
46 4cc0851e 2023-10-08 thomas static int datetime(struct template *, time_t, int);
47 b82440e1 2023-01-06 thomas static int gotweb_render_blob_line(struct template *, const char *, size_t);
48 3c14c1f2 2023-01-06 thomas static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
49 1cd5d437 2023-01-15 thomas static int blame_line(struct template *, const char *, struct blame_line *,
50 1cd5d437 2023-01-15 thomas int, int);
51 20bab626 2023-02-03 thomas
52 20bab626 2023-02-03 thomas static inline int gotweb_render_more(struct template *, int);
53 b82440e1 2023-01-06 thomas
54 dccd05b4 2023-01-10 thomas static inline int diff_line(struct template *, char *);
55 617497a6 2023-01-09 thomas static inline int tag_item(struct template *, struct repo_tag *);
56 00abe30b 2023-01-14 thomas static inline int branch(struct template *, struct got_reflist_entry *);
57 d6795e9f 2022-12-30 thomas static inline int rss_tag_item(struct template *, struct repo_tag *);
58 d6795e9f 2022-12-30 thomas static inline int rss_author(struct template *, char *);
59 d6795e9f 2022-12-30 thomas
60 6da1aa18 2023-12-01 thomas static inline char *
61 6da1aa18 2023-12-01 thomas nextsep(char *s, char **t)
62 6da1aa18 2023-12-01 thomas {
63 6da1aa18 2023-12-01 thomas char *q;
64 6da1aa18 2023-12-01 thomas
65 6da1aa18 2023-12-01 thomas while (*s == '/')
66 6da1aa18 2023-12-01 thomas s++;
67 6da1aa18 2023-12-01 thomas *t = s;
68 6da1aa18 2023-12-01 thomas if (*s == '\0')
69 6da1aa18 2023-12-01 thomas return NULL;
70 6da1aa18 2023-12-01 thomas
71 6da1aa18 2023-12-01 thomas q = strchr(s, '/');
72 6da1aa18 2023-12-01 thomas if (q == NULL)
73 6da1aa18 2023-12-01 thomas q = strchr(s, '\0');
74 6da1aa18 2023-12-01 thomas return q;
75 6da1aa18 2023-12-01 thomas }
76 6da1aa18 2023-12-01 thomas
77 e7e5fa49 2022-12-30 thomas !}
78 4cc0851e 2023-10-08 thomas
79 4cc0851e 2023-10-08 thomas {{ define datetime(struct template *tp, time_t t, int fmt) }}
80 4cc0851e 2023-10-08 thomas {!
81 4cc0851e 2023-10-08 thomas struct tm tm;
82 4cc0851e 2023-10-08 thomas char rfc3339[64];
83 4cc0851e 2023-10-08 thomas char datebuf[64];
84 4cc0851e 2023-10-08 thomas
85 4cc0851e 2023-10-08 thomas if (gmtime_r(&t, &tm) == NULL)
86 4cc0851e 2023-10-08 thomas return -1;
87 4cc0851e 2023-10-08 thomas
88 4cc0851e 2023-10-08 thomas if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
89 4cc0851e 2023-10-08 thomas return -1;
90 4cc0851e 2023-10-08 thomas
91 4cc0851e 2023-10-08 thomas if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
92 4cc0851e 2023-10-08 thomas return -1;
93 4cc0851e 2023-10-08 thomas !}
94 4cc0851e 2023-10-08 thomas <time datetime="{{ rfc3339 }}">
95 4cc0851e 2023-10-08 thomas {{ if fmt == TM_DIFF }}
96 4cc0851e 2023-10-08 thomas {{ render gotweb_render_age(tp, t) }}
97 4cc0851e 2023-10-08 thomas {{ else }}
98 4cc0851e 2023-10-08 thomas {{ datebuf }} {{ " UTC" }}
99 4cc0851e 2023-10-08 thomas {{ end }}
100 4cc0851e 2023-10-08 thomas </time>
101 4cc0851e 2023-10-08 thomas {{ end }}
102 e7e5fa49 2022-12-30 thomas
103 6da1aa18 2023-12-01 thomas {{ define breadcumbs(struct template *tp) }}
104 6da1aa18 2023-12-01 thomas {!
105 6da1aa18 2023-12-01 thomas struct request *c = tp->tp_arg;
106 6da1aa18 2023-12-01 thomas struct querystring *qs = c->t->qs;
107 6da1aa18 2023-12-01 thomas struct gotweb_url url;
108 6da1aa18 2023-12-01 thomas const char *folder = qs->folder;
109 df7661fb 2023-12-03 thomas const char *action = "tree";
110 6da1aa18 2023-12-01 thomas char *t, *s = NULL, *dir = NULL;
111 6da1aa18 2023-12-01 thomas char ch;
112 6da1aa18 2023-12-01 thomas
113 6da1aa18 2023-12-01 thomas memset(&url, 0, sizeof(url));
114 6da1aa18 2023-12-01 thomas url.index_page = -1;
115 6da1aa18 2023-12-01 thomas url.page = -1;
116 6da1aa18 2023-12-01 thomas url.action = TREE;
117 6da1aa18 2023-12-01 thomas url.path = qs->path;
118 6da1aa18 2023-12-01 thomas url.commit = qs->commit;
119 6da1aa18 2023-12-01 thomas
120 df7661fb 2023-12-03 thomas if (qs->action != TREE && qs->action != BLOB) {
121 df7661fb 2023-12-03 thomas action = gotweb_action_name(qs->action);
122 df7661fb 2023-12-03 thomas url.action = qs->action;
123 df7661fb 2023-12-03 thomas }
124 df7661fb 2023-12-03 thomas
125 6da1aa18 2023-12-01 thomas if (folder && *folder != '\0') {
126 6da1aa18 2023-12-01 thomas while (*folder == '/')
127 6da1aa18 2023-12-01 thomas folder++;
128 6da1aa18 2023-12-01 thomas dir = strdup(folder);
129 6da1aa18 2023-12-01 thomas if (dir == NULL)
130 6da1aa18 2023-12-01 thomas return (-1);
131 6da1aa18 2023-12-01 thomas s = dir;
132 6da1aa18 2023-12-01 thomas }
133 6da1aa18 2023-12-01 thomas !}
134 6da1aa18 2023-12-01 thomas {{ " / " }}
135 df7661fb 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &url) }}">{{ action }}</a>
136 6da1aa18 2023-12-01 thomas {{ " / " }}
137 6da1aa18 2023-12-01 thomas {{ if dir }}
138 6da1aa18 2023-12-01 thomas {{ while (s = nextsep(s, &t)) != NULL }}
139 6da1aa18 2023-12-01 thomas {!
140 6da1aa18 2023-12-01 thomas ch = *s;
141 6da1aa18 2023-12-01 thomas *s = '\0';
142 6da1aa18 2023-12-01 thomas url.folder = dir;
143 6da1aa18 2023-12-01 thomas !}
144 6da1aa18 2023-12-01 thomas
145 6da1aa18 2023-12-01 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
146 6da1aa18 2023-12-01 thomas {{ t }}
147 6da1aa18 2023-12-01 thomas </a>
148 6da1aa18 2023-12-01 thomas {{ " / " }}
149 6da1aa18 2023-12-01 thomas
150 6da1aa18 2023-12-01 thomas {! *s = ch; !}
151 6da1aa18 2023-12-01 thomas {{ end }}
152 6da1aa18 2023-12-01 thomas {{ end }}
153 6da1aa18 2023-12-01 thomas
154 6da1aa18 2023-12-01 thomas {{ if qs->file }}
155 6da1aa18 2023-12-01 thomas {{ qs->file }}
156 6da1aa18 2023-12-01 thomas {{ end}}
157 6da1aa18 2023-12-01 thomas
158 6da1aa18 2023-12-01 thomas {{ finally }}
159 6da1aa18 2023-12-01 thomas {! free(dir); !}
160 6da1aa18 2023-12-01 thomas {{ end }}
161 6da1aa18 2023-12-01 thomas
162 161663e7 2023-03-11 thomas {{ define gotweb_render_page(struct template *tp,
163 161663e7 2023-03-11 thomas int (*body)(struct template *)) }}
164 e7e5fa49 2022-12-30 thomas {!
165 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
166 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
167 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
168 e7e5fa49 2022-12-30 thomas struct gotweb_url u_path;
169 3191e256 2022-12-30 thomas const char *prfx = c->document_uri;
170 e7e5fa49 2022-12-30 thomas const char *css = srv->custom_css;
171 e7e5fa49 2022-12-30 thomas
172 e7e5fa49 2022-12-30 thomas memset(&u_path, 0, sizeof(u_path));
173 e7e5fa49 2022-12-30 thomas u_path.index_page = -1;
174 e7e5fa49 2022-12-30 thomas u_path.page = -1;
175 e7e5fa49 2022-12-30 thomas u_path.action = SUMMARY;
176 e7e5fa49 2022-12-30 thomas !}
177 e7e5fa49 2022-12-30 thomas <!doctype html>
178 e7e5fa49 2022-12-30 thomas <html>
179 e7e5fa49 2022-12-30 thomas <head>
180 e7e5fa49 2022-12-30 thomas <meta charset="utf-8" />
181 e7e5fa49 2022-12-30 thomas <title>{{ srv->site_name }}</title>
182 fdd79f2f 2023-09-12 thomas <meta name="viewport" content="initial-scale=1.0" />
183 e7e5fa49 2022-12-30 thomas <meta name="msapplication-TileColor" content="#da532c" />
184 e7e5fa49 2022-12-30 thomas <meta name="theme-color" content="#ffffff"/>
185 e7e5fa49 2022-12-30 thomas <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
186 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
187 e7e5fa49 2022-12-30 thomas <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
188 e7e5fa49 2022-12-30 thomas <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
189 e7e5fa49 2022-12-30 thomas <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
190 e7e5fa49 2022-12-30 thomas <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
191 e7e5fa49 2022-12-30 thomas </head>
192 e7e5fa49 2022-12-30 thomas <body>
193 fdd79f2f 2023-09-12 thomas <header id="header">
194 fdd79f2f 2023-09-12 thomas <div id="got_link">
195 fdd79f2f 2023-09-12 thomas <a href="{{ srv->logo_url }}" target="_blank">
196 fdd79f2f 2023-09-12 thomas <img src="{{ prfx }}{{ srv->logo }}" />
197 fdd79f2f 2023-09-12 thomas </a>
198 e7e5fa49 2022-12-30 thomas </div>
199 fdd79f2f 2023-09-12 thomas </header>
200 fdd79f2f 2023-09-12 thomas <nav id="site_path">
201 fdd79f2f 2023-09-12 thomas <div id="site_link">
202 fdd79f2f 2023-09-12 thomas <a href="?index_page={{ printf "%d", qs->index_page }}">
203 fdd79f2f 2023-09-12 thomas {{ srv->site_link }}
204 fdd79f2f 2023-09-12 thomas </a>
205 fdd79f2f 2023-09-12 thomas {{ if qs->path }}
206 fdd79f2f 2023-09-12 thomas {! u_path.path = qs->path; !}
207 fdd79f2f 2023-09-12 thomas {{ " / " }}
208 fdd79f2f 2023-09-12 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
209 fdd79f2f 2023-09-12 thomas {{ qs->path }}
210 e7e5fa49 2022-12-30 thomas </a>
211 fdd79f2f 2023-09-12 thomas {{ end }}
212 df7661fb 2023-12-03 thomas {{ if qs->action == SUMMARY || qs->action == DIFF ||
213 df7661fb 2023-12-03 thomas qs->action == TAG || qs->action == TAGS }}
214 fdd79f2f 2023-09-12 thomas {{ " / " }}{{ gotweb_action_name(qs->action) }}
215 df7661fb 2023-12-03 thomas {{ else if qs->action != INDEX}}
216 df7661fb 2023-12-03 thomas {{ render breadcumbs(tp) }}
217 fdd79f2f 2023-09-12 thomas {{ end }}
218 e7e5fa49 2022-12-30 thomas </div>
219 fdd79f2f 2023-09-12 thomas </nav>
220 fdd79f2f 2023-09-12 thomas <main>
221 fdd79f2f 2023-09-12 thomas {{ render body(tp) }}
222 fdd79f2f 2023-09-12 thomas </main>
223 fdd79f2f 2023-09-12 thomas <footer id="site_owner_wrapper">
224 fdd79f2f 2023-09-12 thomas <p id="site_owner">
225 fdd79f2f 2023-09-12 thomas {{ if srv->show_site_owner }}
226 fdd79f2f 2023-09-12 thomas {{ srv->site_owner }}
227 fdd79f2f 2023-09-12 thomas {{ end }}
228 fdd79f2f 2023-09-12 thomas </p>
229 fdd79f2f 2023-09-12 thomas </footer>
230 e7e5fa49 2022-12-30 thomas </body>
231 e7e5fa49 2022-12-30 thomas </html>
232 164b5ddc 2023-03-11 thomas {{ end }}
233 164b5ddc 2023-03-11 thomas
234 164b5ddc 2023-03-11 thomas {{ define gotweb_render_error(struct template *tp) }}
235 164b5ddc 2023-03-11 thomas {!
236 164b5ddc 2023-03-11 thomas struct request *c = tp->tp_arg;
237 164b5ddc 2023-03-11 thomas struct transport *t = c->t;
238 164b5ddc 2023-03-11 thomas !}
239 164b5ddc 2023-03-11 thomas <div id="err_content">
240 164b5ddc 2023-03-11 thomas {{ if t->error }}
241 164b5ddc 2023-03-11 thomas {{ t->error->msg }}
242 164b5ddc 2023-03-11 thomas {{ else }}
243 164b5ddc 2023-03-11 thomas See daemon logs for details
244 164b5ddc 2023-03-11 thomas {{ end }}
245 164b5ddc 2023-03-11 thomas </div>
246 e7e5fa49 2022-12-30 thomas {{ end }}
247 e7e5fa49 2022-12-30 thomas
248 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
249 e7e5fa49 2022-12-30 thomas {!
250 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
251 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
252 e7e5fa49 2022-12-30 thomas !}
253 e7e5fa49 2022-12-30 thomas <div id="index_header">
254 fdd79f2f 2023-09-12 thomas <div class="index_project">
255 e7e5fa49 2022-12-30 thomas Project
256 e7e5fa49 2022-12-30 thomas </div>
257 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
258 fdd79f2f 2023-09-12 thomas <div class="index_project_description">
259 e7e5fa49 2022-12-30 thomas Description
260 e7e5fa49 2022-12-30 thomas </div>
261 e7e5fa49 2022-12-30 thomas {{ end }}
262 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
263 fdd79f2f 2023-09-12 thomas <div class="index_project_owner">
264 e7e5fa49 2022-12-30 thomas Owner
265 e7e5fa49 2022-12-30 thomas </div>
266 e7e5fa49 2022-12-30 thomas {{ end }}
267 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
268 fdd79f2f 2023-09-12 thomas <div class="index_project_age">
269 e7e5fa49 2022-12-30 thomas Last Change
270 e7e5fa49 2022-12-30 thomas </div>
271 e7e5fa49 2022-12-30 thomas {{ end }}
272 e7e5fa49 2022-12-30 thomas </div>
273 e7e5fa49 2022-12-30 thomas {{ end }}
274 e7e5fa49 2022-12-30 thomas
275 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
276 e7e5fa49 2022-12-30 thomas {!
277 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
278 e7e5fa49 2022-12-30 thomas struct server *srv = c->srv;
279 e7e5fa49 2022-12-30 thomas struct gotweb_url summary = {
280 e7e5fa49 2022-12-30 thomas .action = SUMMARY,
281 e7e5fa49 2022-12-30 thomas .index_page = -1,
282 e7e5fa49 2022-12-30 thomas .page = -1,
283 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
284 e7e5fa49 2022-12-30 thomas }, briefs = {
285 e7e5fa49 2022-12-30 thomas .action = BRIEFS,
286 e7e5fa49 2022-12-30 thomas .index_page = -1,
287 e7e5fa49 2022-12-30 thomas .page = -1,
288 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
289 e7e5fa49 2022-12-30 thomas }, commits = {
290 e7e5fa49 2022-12-30 thomas .action = COMMITS,
291 e7e5fa49 2022-12-30 thomas .index_page = -1,
292 e7e5fa49 2022-12-30 thomas .page = -1,
293 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
294 e7e5fa49 2022-12-30 thomas }, tags = {
295 e7e5fa49 2022-12-30 thomas .action = TAGS,
296 e7e5fa49 2022-12-30 thomas .index_page = -1,
297 e7e5fa49 2022-12-30 thomas .page = -1,
298 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
299 e7e5fa49 2022-12-30 thomas }, tree = {
300 e7e5fa49 2022-12-30 thomas .action = TREE,
301 e7e5fa49 2022-12-30 thomas .index_page = -1,
302 e7e5fa49 2022-12-30 thomas .page = -1,
303 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
304 d6795e9f 2022-12-30 thomas }, rss = {
305 d6795e9f 2022-12-30 thomas .action = RSS,
306 d6795e9f 2022-12-30 thomas .index_page = -1,
307 d6795e9f 2022-12-30 thomas .page = -1,
308 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
309 e7e5fa49 2022-12-30 thomas };
310 e7e5fa49 2022-12-30 thomas !}
311 e7e5fa49 2022-12-30 thomas <div class="index_wrapper">
312 e7e5fa49 2022-12-30 thomas <div class="index_project">
313 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
314 e7e5fa49 2022-12-30 thomas </div>
315 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_description }}
316 e7e5fa49 2022-12-30 thomas <div class="index_project_description">
317 e7e5fa49 2022-12-30 thomas {{ repo_dir->description }}
318 e7e5fa49 2022-12-30 thomas </div>
319 e7e5fa49 2022-12-30 thomas {{ end }}
320 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_owner }}
321 e7e5fa49 2022-12-30 thomas <div class="index_project_owner">
322 e7e5fa49 2022-12-30 thomas {{ repo_dir->owner }}
323 e7e5fa49 2022-12-30 thomas </div>
324 e7e5fa49 2022-12-30 thomas {{ end }}
325 e7e5fa49 2022-12-30 thomas {{ if srv->show_repo_age }}
326 e7e5fa49 2022-12-30 thomas <div class="index_project_age">
327 4cc0851e 2023-10-08 thomas {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
328 e7e5fa49 2022-12-30 thomas </div>
329 e7e5fa49 2022-12-30 thomas {{ end }}
330 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
331 e7e5fa49 2022-12-30 thomas <div class="navs">
332 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
333 e7e5fa49 2022-12-30 thomas {{ " | " }}
334 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
335 e7e5fa49 2022-12-30 thomas {{ " | " }}
336 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
337 e7e5fa49 2022-12-30 thomas {{ " | " }}
338 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
339 e7e5fa49 2022-12-30 thomas {{ " | " }}
340 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
341 d6795e9f 2022-12-30 thomas {{ " | " }}
342 d6795e9f 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
343 e7e5fa49 2022-12-30 thomas </div>
344 fdd79f2f 2023-09-12 thomas <hr />
345 e7e5fa49 2022-12-30 thomas </div>
346 e7e5fa49 2022-12-30 thomas </div>
347 e7e5fa49 2022-12-30 thomas {{ end }}
348 e7e5fa49 2022-12-30 thomas
349 e7e5fa49 2022-12-30 thomas {{ define gotweb_render_briefs(struct template *tp) }}
350 e7e5fa49 2022-12-30 thomas {!
351 e7e5fa49 2022-12-30 thomas struct request *c = tp->tp_arg;
352 e7e5fa49 2022-12-30 thomas struct transport *t = c->t;
353 e7e5fa49 2022-12-30 thomas struct querystring *qs = c->t->qs;
354 e7e5fa49 2022-12-30 thomas struct repo_commit *rc;
355 e7e5fa49 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
356 feaddee6 2023-12-03 thomas struct gotweb_url diff_url, patch_url, tree_url;
357 e7e5fa49 2022-12-30 thomas char *tmp;
358 e7e5fa49 2022-12-30 thomas
359 e7e5fa49 2022-12-30 thomas diff_url = (struct gotweb_url){
360 e7e5fa49 2022-12-30 thomas .action = DIFF,
361 feaddee6 2023-12-03 thomas .index_page = -1,
362 feaddee6 2023-12-03 thomas .page = -1,
363 feaddee6 2023-12-03 thomas .path = repo_dir->name,
364 feaddee6 2023-12-03 thomas .headref = qs->headref,
365 feaddee6 2023-12-03 thomas };
366 feaddee6 2023-12-03 thomas patch_url = (struct gotweb_url){
367 feaddee6 2023-12-03 thomas .action = PATCH,
368 e7e5fa49 2022-12-30 thomas .index_page = -1,
369 e7e5fa49 2022-12-30 thomas .page = -1,
370 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
371 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
372 e7e5fa49 2022-12-30 thomas };
373 e7e5fa49 2022-12-30 thomas tree_url = (struct gotweb_url){
374 e7e5fa49 2022-12-30 thomas .action = TREE,
375 e7e5fa49 2022-12-30 thomas .index_page = -1,
376 e7e5fa49 2022-12-30 thomas .page = -1,
377 e7e5fa49 2022-12-30 thomas .path = repo_dir->name,
378 e7e5fa49 2022-12-30 thomas .headref = qs->headref,
379 e7e5fa49 2022-12-30 thomas };
380 e7e5fa49 2022-12-30 thomas !}
381 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
382 fdd79f2f 2023-09-12 thomas <h2>Commit Briefs</h2>
383 fdd79f2f 2023-09-12 thomas </header>
384 e7e5fa49 2022-12-30 thomas <div id="briefs_content">
385 e7e5fa49 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
386 e7e5fa49 2022-12-30 thomas {!
387 e7e5fa49 2022-12-30 thomas diff_url.commit = rc->commit_id;
388 feaddee6 2023-12-03 thomas patch_url.commit = rc->commit_id;
389 e7e5fa49 2022-12-30 thomas tree_url.commit = rc->commit_id;
390 e7e5fa49 2022-12-30 thomas
391 64d39587 2023-01-14 thomas tmp = strchr(rc->committer, '<');
392 e7e5fa49 2022-12-30 thomas if (tmp)
393 e7e5fa49 2022-12-30 thomas *tmp = '\0';
394 e7e5fa49 2022-12-30 thomas
395 e7e5fa49 2022-12-30 thomas tmp = strchr(rc->commit_msg, '\n');
396 e7e5fa49 2022-12-30 thomas if (tmp)
397 e7e5fa49 2022-12-30 thomas *tmp = '\0';
398 e7e5fa49 2022-12-30 thomas !}
399 fdd79f2f 2023-09-12 thomas <div class='brief'>
400 fdd79f2f 2023-09-12 thomas <p class='brief_meta'>
401 fdd79f2f 2023-09-12 thomas <span class='briefs_age'>
402 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
403 fdd79f2f 2023-09-12 thomas </span>
404 fdd79f2f 2023-09-12 thomas {{" "}}
405 fdd79f2f 2023-09-12 thomas <span class="briefs_author">
406 fdd79f2f 2023-09-12 thomas {{ rc->committer }}
407 fdd79f2f 2023-09-12 thomas </span>
408 fdd79f2f 2023-09-12 thomas </p>
409 fdd79f2f 2023-09-12 thomas <p class="briefs_log">
410 fdd79f2f 2023-09-12 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
411 fdd79f2f 2023-09-12 thomas {{ rc->commit_msg }}
412 fdd79f2f 2023-09-12 thomas </a>
413 fdd79f2f 2023-09-12 thomas {{ if rc->refs_str }}
414 fdd79f2f 2023-09-12 thomas {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
415 fdd79f2f 2023-09-12 thomas {{ end }}
416 fdd79f2f 2023-09-12 thomas </a>
417 fdd79f2f 2023-09-12 thomas </p>
418 e7e5fa49 2022-12-30 thomas </div>
419 e7e5fa49 2022-12-30 thomas <div class="navs_wrapper">
420 e7e5fa49 2022-12-30 thomas <div class="navs">
421 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
422 e7e5fa49 2022-12-30 thomas {{ " | " }}
423 feaddee6 2023-12-03 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
424 feaddee6 2023-12-03 thomas {{ " | " }}
425 e7e5fa49 2022-12-30 thomas <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
426 e7e5fa49 2022-12-30 thomas </div>
427 e7e5fa49 2022-12-30 thomas </div>
428 fdd79f2f 2023-09-12 thomas <hr />
429 e7e5fa49 2022-12-30 thomas {{ end }}
430 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, BRIEFS) }}
431 2f4f0731 2022-12-30 thomas </div>
432 2f4f0731 2022-12-30 thomas {{ end }}
433 2f4f0731 2022-12-30 thomas
434 20bab626 2023-02-03 thomas {{ define gotweb_render_more(struct template *tp, int action) }}
435 20bab626 2023-02-03 thomas {!
436 20bab626 2023-02-03 thomas struct request *c = tp->tp_arg;
437 20bab626 2023-02-03 thomas struct transport *t = c->t;
438 20bab626 2023-02-03 thomas struct querystring *qs = t->qs;
439 20bab626 2023-02-03 thomas struct gotweb_url more = {
440 20bab626 2023-02-03 thomas .action = action,
441 20bab626 2023-02-03 thomas .index_page = -1,
442 20bab626 2023-02-03 thomas .path = qs->path,
443 20bab626 2023-02-03 thomas .commit = t->more_id,
444 20bab626 2023-02-03 thomas .headref = qs->headref,
445 882ee74d 2023-09-14 thomas .file = qs->file,
446 20bab626 2023-02-03 thomas };
447 20bab626 2023-02-03 thomas !}
448 20bab626 2023-02-03 thomas {{ if t->more_id }}
449 20bab626 2023-02-03 thomas <div id="np_wrapper">
450 20bab626 2023-02-03 thomas <div id="nav_more">
451 20bab626 2023-02-03 thomas <a href="{{ render gotweb_render_url(c, &more) }}">
452 bd6e9c73 2023-02-03 thomas More&nbsp;&darr;
453 20bab626 2023-02-03 thomas </a>
454 20bab626 2023-02-03 thomas </div>
455 20bab626 2023-02-03 thomas </div>
456 20bab626 2023-02-03 thomas {{ end }}
457 20bab626 2023-02-03 thomas {{ end }}
458 20bab626 2023-02-03 thomas
459 2f4f0731 2022-12-30 thomas {{ define gotweb_render_navs(struct template *tp) }}
460 2f4f0731 2022-12-30 thomas {!
461 2f4f0731 2022-12-30 thomas struct request *c = tp->tp_arg;
462 2f4f0731 2022-12-30 thomas struct transport *t = c->t;
463 2f4f0731 2022-12-30 thomas struct gotweb_url prev, next;
464 2f4f0731 2022-12-30 thomas int have_prev, have_next;
465 2f4f0731 2022-12-30 thomas
466 2f4f0731 2022-12-30 thomas gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
467 2f4f0731 2022-12-30 thomas !}
468 2f4f0731 2022-12-30 thomas <div id="np_wrapper">
469 2f4f0731 2022-12-30 thomas <div id="nav_prev">
470 2f4f0731 2022-12-30 thomas {{ if have_prev }}
471 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &prev) }}">
472 2f4f0731 2022-12-30 thomas Previous
473 2f4f0731 2022-12-30 thomas </a>
474 2f4f0731 2022-12-30 thomas {{ end }}
475 2f4f0731 2022-12-30 thomas </div>
476 2f4f0731 2022-12-30 thomas <div id="nav_next">
477 2f4f0731 2022-12-30 thomas {{ if have_next }}
478 2f4f0731 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &next) }}">
479 2f4f0731 2022-12-30 thomas Next
480 2f4f0731 2022-12-30 thomas </a>
481 2f4f0731 2022-12-30 thomas {{ end }}
482 2f4f0731 2022-12-30 thomas </div>
483 e7e5fa49 2022-12-30 thomas </div>
484 2f4f0731 2022-12-30 thomas {{ finally }}
485 2f4f0731 2022-12-30 thomas {!
486 2f4f0731 2022-12-30 thomas free(t->next_id);
487 2f4f0731 2022-12-30 thomas t->next_id = NULL;
488 2f4f0731 2022-12-30 thomas free(t->prev_id);
489 2f4f0731 2022-12-30 thomas t->prev_id = NULL;
490 2f4f0731 2022-12-30 thomas !}
491 e7e5fa49 2022-12-30 thomas {{ end }}
492 7ade8b27 2022-12-30 thomas
493 7ade8b27 2022-12-30 thomas {{ define gotweb_render_commits(struct template *tp) }}
494 7ade8b27 2022-12-30 thomas {!
495 7ade8b27 2022-12-30 thomas struct request *c = tp->tp_arg;
496 7ade8b27 2022-12-30 thomas struct transport *t = c->t;
497 7ade8b27 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
498 7ade8b27 2022-12-30 thomas struct repo_commit *rc;
499 feaddee6 2023-12-03 thomas struct gotweb_url diff, patch, tree;
500 7ade8b27 2022-12-30 thomas
501 7ade8b27 2022-12-30 thomas diff = (struct gotweb_url){
502 7ade8b27 2022-12-30 thomas .action = DIFF,
503 7ade8b27 2022-12-30 thomas .index_page = -1,
504 7ade8b27 2022-12-30 thomas .page = -1,
505 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
506 7ade8b27 2022-12-30 thomas };
507 feaddee6 2023-12-03 thomas patch = (struct gotweb_url){
508 feaddee6 2023-12-03 thomas .action = PATCH,
509 feaddee6 2023-12-03 thomas .index_page = -1,
510 feaddee6 2023-12-03 thomas .page = -1,
511 feaddee6 2023-12-03 thomas .path = repo_dir->name,
512 feaddee6 2023-12-03 thomas };
513 7ade8b27 2022-12-30 thomas tree = (struct gotweb_url){
514 7ade8b27 2022-12-30 thomas .action = TREE,
515 7ade8b27 2022-12-30 thomas .index_page = -1,
516 7ade8b27 2022-12-30 thomas .page = -1,
517 7ade8b27 2022-12-30 thomas .path = repo_dir->name,
518 7ade8b27 2022-12-30 thomas };
519 7ade8b27 2022-12-30 thomas !}
520 fdd79f2f 2023-09-12 thomas <header class="subtitle">
521 fdd79f2f 2023-09-12 thomas <h2>Commits</h2>
522 fdd79f2f 2023-09-12 thomas </header>
523 7ade8b27 2022-12-30 thomas <div class="commits_content">
524 7ade8b27 2022-12-30 thomas {{ tailq-foreach rc &t->repo_commits entry }}
525 7ade8b27 2022-12-30 thomas {!
526 7ade8b27 2022-12-30 thomas diff.commit = rc->commit_id;
527 feaddee6 2023-12-03 thomas patch.commit = rc->commit_id;
528 7ade8b27 2022-12-30 thomas tree.commit = rc->commit_id;
529 7ade8b27 2022-12-30 thomas !}
530 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
531 57cfad1e 2023-12-01 thomas <dl>
532 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
533 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
534 fdd79f2f 2023-09-12 thomas <dt>From:</dt>
535 fdd79f2f 2023-09-12 thomas <dd>{{ rc->author }}</dd>
536 54ffadaf 2023-01-14 thomas {{ if strcmp(rc->committer, rc->author) != 0 }}
537 fdd79f2f 2023-09-12 thomas <dt>Via:</dt>
538 fdd79f2f 2023-09-12 thomas <dd>{{ rc->committer }}</dd>
539 54ffadaf 2023-01-14 thomas {{ end }}
540 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
541 fdd79f2f 2023-09-12 thomas <dd>
542 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
543 fdd79f2f 2023-09-12 thomas </dd>
544 fdd79f2f 2023-09-12 thomas </dl>
545 7ade8b27 2022-12-30 thomas </div>
546 fdd79f2f 2023-09-12 thomas <hr />
547 bbf94fd6 2023-01-02 thomas <div class="commit">
548 bbf94fd6 2023-01-02 thomas {{ "\n" }}
549 bbf94fd6 2023-01-02 thomas {{ rc->commit_msg }}
550 bbf94fd6 2023-01-02 thomas </div>
551 7ade8b27 2022-12-30 thomas <div class="navs_wrapper">
552 7ade8b27 2022-12-30 thomas <div class="navs">
553 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
554 feaddee6 2023-12-03 thomas {{ " | " }}
555 feaddee6 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
556 7ade8b27 2022-12-30 thomas {{ " | " }}
557 7ade8b27 2022-12-30 thomas <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
558 7ade8b27 2022-12-30 thomas </div>
559 7ade8b27 2022-12-30 thomas </div>
560 fdd79f2f 2023-09-12 thomas <hr />
561 7ade8b27 2022-12-30 thomas {{ end }}
562 20bab626 2023-02-03 thomas {{ render gotweb_render_more(tp, COMMITS) }}
563 b82440e1 2023-01-06 thomas </div>
564 b82440e1 2023-01-06 thomas {{ end }}
565 b82440e1 2023-01-06 thomas
566 161663e7 2023-03-11 thomas {{ define gotweb_render_blob(struct template *tp) }}
567 b82440e1 2023-01-06 thomas {!
568 b82440e1 2023-01-06 thomas struct request *c = tp->tp_arg;
569 b82440e1 2023-01-06 thomas struct transport *t = c->t;
570 54f5c7d0 2023-12-01 thomas struct querystring *qs = t->qs;
571 161663e7 2023-03-11 thomas struct got_blob_object *blob = t->blob;
572 b82440e1 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
573 54f5c7d0 2023-12-01 thomas struct gotweb_url briefs_url, blame_url, raw_url;
574 54f5c7d0 2023-12-01 thomas
575 54f5c7d0 2023-12-01 thomas memset(&briefs_url, 0, sizeof(briefs_url));
576 54f5c7d0 2023-12-01 thomas briefs_url.index_page = -1,
577 54f5c7d0 2023-12-01 thomas briefs_url.page = -1,
578 54f5c7d0 2023-12-01 thomas briefs_url.action = BRIEFS,
579 54f5c7d0 2023-12-01 thomas briefs_url.path = qs->path,
580 54f5c7d0 2023-12-01 thomas briefs_url.commit = qs->commit,
581 54f5c7d0 2023-12-01 thomas briefs_url.folder = qs->folder,
582 54f5c7d0 2023-12-01 thomas briefs_url.file = qs->file,
583 54f5c7d0 2023-12-01 thomas
584 54f5c7d0 2023-12-01 thomas memcpy(&blame_url, &briefs_url, sizeof(blame_url));
585 54f5c7d0 2023-12-01 thomas blame_url.action = BLAME;
586 54f5c7d0 2023-12-01 thomas
587 54f5c7d0 2023-12-01 thomas memcpy(&raw_url, &briefs_url, sizeof(raw_url));
588 54f5c7d0 2023-12-01 thomas raw_url.action = BLOBRAW;
589 b82440e1 2023-01-06 thomas !}
590 fdd79f2f 2023-09-12 thomas <header class="subtitle">
591 fdd79f2f 2023-09-12 thomas <h2>Blob</h2>
592 fdd79f2f 2023-09-12 thomas </header>
593 b82440e1 2023-01-06 thomas <div id="blob_content">
594 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
595 57cfad1e 2023-12-01 thomas <dl>
596 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
597 fdd79f2f 2023-09-12 thomas <dd>
598 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
599 fdd79f2f 2023-09-12 thomas </dd>
600 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
601 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
602 54f5c7d0 2023-12-01 thomas <dt>Actions:</dt>
603 54f5c7d0 2023-12-01 thomas <dd>
604 54f5c7d0 2023-12-01 thomas <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
605 54f5c7d0 2023-12-01 thomas History
606 54f5c7d0 2023-12-01 thomas </a>
607 54f5c7d0 2023-12-01 thomas {{" | "}}
608 54f5c7d0 2023-12-01 thomas <a href="{{ render gotweb_render_url(c, &blame_url) }}">
609 54f5c7d0 2023-12-01 thomas Blame
610 54f5c7d0 2023-12-01 thomas </a>
611 54f5c7d0 2023-12-01 thomas {{" | "}}
612 54f5c7d0 2023-12-01 thomas <a href="{{ render gotweb_render_url(c, &raw_url) }}">
613 54f5c7d0 2023-12-01 thomas Raw File
614 54f5c7d0 2023-12-01 thomas </a>
615 54f5c7d0 2023-12-01 thomas </dd>
616 fdd79f2f 2023-09-12 thomas </dl>
617 b82440e1 2023-01-06 thomas </div>
618 fdd79f2f 2023-09-12 thomas <hr />
619 b82440e1 2023-01-06 thomas <div id="blob">
620 b82440e1 2023-01-06 thomas <pre>
621 b82440e1 2023-01-06 thomas {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
622 b82440e1 2023-01-06 thomas </pre>
623 b82440e1 2023-01-06 thomas </div>
624 7ade8b27 2022-12-30 thomas </div>
625 d6795e9f 2022-12-30 thomas {{ end }}
626 d6795e9f 2022-12-30 thomas
627 b82440e1 2023-01-06 thomas {{ define gotweb_render_blob_line(struct template *tp, const char *line,
628 b82440e1 2023-01-06 thomas size_t no) }}
629 b82440e1 2023-01-06 thomas {!
630 b82440e1 2023-01-06 thomas char lineno[16];
631 b82440e1 2023-01-06 thomas int r;
632 b82440e1 2023-01-06 thomas
633 b82440e1 2023-01-06 thomas r = snprintf(lineno, sizeof(lineno), "%zu", no);
634 b82440e1 2023-01-06 thomas if (r < 0 || (size_t)r >= sizeof(lineno))
635 b82440e1 2023-01-06 thomas return -1;
636 b82440e1 2023-01-06 thomas !}
637 b82440e1 2023-01-06 thomas <div class="blob_line" id="line{{ lineno }}">
638 fdd79f2f 2023-09-12 thomas <a href="#line{{ lineno }}">{{ lineno }}</a>
639 991e3353 2023-12-01 thomas {{" "}}
640 fdd79f2f 2023-09-12 thomas <span class="blob_code">{{ line }}</span>
641 3c14c1f2 2023-01-06 thomas </div>
642 3c14c1f2 2023-01-06 thomas {{ end }}
643 3c14c1f2 2023-01-06 thomas
644 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree(struct template *tp) }}
645 3c14c1f2 2023-01-06 thomas {!
646 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
647 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
648 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
649 3c14c1f2 2023-01-06 thomas !}
650 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
651 fdd79f2f 2023-09-12 thomas <h2>Tree</h2>
652 fdd79f2f 2023-09-12 thomas </header>
653 3c14c1f2 2023-01-06 thomas <div id="tree_content">
654 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
655 57cfad1e 2023-12-01 thomas <dl>
656 fdd79f2f 2023-09-12 thomas <dt>Tree:</dt>
657 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
658 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
659 fdd79f2f 2023-09-12 thomas <dd>
660 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
661 fdd79f2f 2023-09-12 thomas </dd>
662 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
663 cbe7b7d7 2023-10-08 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
664 fdd79f2f 2023-09-12 thomas </dl>
665 3c14c1f2 2023-01-06 thomas </div>
666 fdd79f2f 2023-09-12 thomas <hr />
667 fdd79f2f 2023-09-12 thomas <table id="tree">
668 3c14c1f2 2023-01-06 thomas {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
669 fdd79f2f 2023-09-12 thomas </table>
670 3c14c1f2 2023-01-06 thomas </div>
671 3c14c1f2 2023-01-06 thomas {{ end }}
672 3c14c1f2 2023-01-06 thomas
673 3c14c1f2 2023-01-06 thomas {{ define gotweb_render_tree_item(struct template *tp,
674 3c14c1f2 2023-01-06 thomas struct got_tree_entry *te) }}
675 3c14c1f2 2023-01-06 thomas {!
676 3c14c1f2 2023-01-06 thomas struct request *c = tp->tp_arg;
677 3c14c1f2 2023-01-06 thomas struct transport *t = c->t;
678 3c14c1f2 2023-01-06 thomas struct querystring *qs = t->qs;
679 3c14c1f2 2023-01-06 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
680 3c14c1f2 2023-01-06 thomas const char *modestr = "";
681 3c14c1f2 2023-01-06 thomas const char *name;
682 3c14c1f2 2023-01-06 thomas const char *folder;
683 3c14c1f2 2023-01-06 thomas char *dir = NULL;
684 3c14c1f2 2023-01-06 thomas mode_t mode;
685 3c14c1f2 2023-01-06 thomas struct gotweb_url url = {
686 3c14c1f2 2023-01-06 thomas .index_page = -1,
687 3c14c1f2 2023-01-06 thomas .page = -1,
688 3c14c1f2 2023-01-06 thomas .commit = rc->commit_id,
689 3c14c1f2 2023-01-06 thomas .path = qs->path,
690 3c14c1f2 2023-01-06 thomas };
691 3c14c1f2 2023-01-06 thomas
692 3c14c1f2 2023-01-06 thomas name = got_tree_entry_get_name(te);
693 3c14c1f2 2023-01-06 thomas mode = got_tree_entry_get_mode(te);
694 3c14c1f2 2023-01-06 thomas
695 3c14c1f2 2023-01-06 thomas folder = qs->folder ? qs->folder : "";
696 3c14c1f2 2023-01-06 thomas if (S_ISDIR(mode)) {
697 3c14c1f2 2023-01-06 thomas if (asprintf(&dir, "%s/%s", folder, name) == -1)
698 3c14c1f2 2023-01-06 thomas return (-1);
699 3c14c1f2 2023-01-06 thomas
700 3c14c1f2 2023-01-06 thomas url.action = TREE;
701 3c14c1f2 2023-01-06 thomas url.folder = dir;
702 3c14c1f2 2023-01-06 thomas } else {
703 3c14c1f2 2023-01-06 thomas url.action = BLOB;
704 3c14c1f2 2023-01-06 thomas url.folder = folder;
705 3c14c1f2 2023-01-06 thomas url.file = name;
706 3c14c1f2 2023-01-06 thomas }
707 3c14c1f2 2023-01-06 thomas
708 3c14c1f2 2023-01-06 thomas if (got_object_tree_entry_is_submodule(te))
709 3c14c1f2 2023-01-06 thomas modestr = "$";
710 3c14c1f2 2023-01-06 thomas else if (S_ISLNK(mode))
711 3c14c1f2 2023-01-06 thomas modestr = "@";
712 3c14c1f2 2023-01-06 thomas else if (S_ISDIR(mode))
713 3c14c1f2 2023-01-06 thomas modestr = "/";
714 3c14c1f2 2023-01-06 thomas else if (mode & S_IXUSR)
715 3c14c1f2 2023-01-06 thomas modestr = "*";
716 3c14c1f2 2023-01-06 thomas !}
717 fdd79f2f 2023-09-12 thomas <tr class="tree_wrapper">
718 3c14c1f2 2023-01-06 thomas {{ if S_ISDIR(mode) }}
719 fdd79f2f 2023-09-12 thomas <td class="tree_line" colspan=2>
720 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
721 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
722 3c14c1f2 2023-01-06 thomas </a>
723 fdd79f2f 2023-09-12 thomas </td>
724 3c14c1f2 2023-01-06 thomas {{ else }}
725 fdd79f2f 2023-09-12 thomas <td class="tree_line">
726 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
727 3c14c1f2 2023-01-06 thomas {{ name }}{{ modestr }}
728 3c14c1f2 2023-01-06 thomas </a>
729 fdd79f2f 2023-09-12 thomas </td>
730 fdd79f2f 2023-09-12 thomas <td class="tree_line_blank">
731 3c14c1f2 2023-01-06 thomas {! url.action = COMMITS; !}
732 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
733 3c14c1f2 2023-01-06 thomas commits
734 3c14c1f2 2023-01-06 thomas </a>
735 3c14c1f2 2023-01-06 thomas {{ " | " }}
736 3c14c1f2 2023-01-06 thomas {! url.action = BLAME; !}
737 3c14c1f2 2023-01-06 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
738 3c14c1f2 2023-01-06 thomas blame
739 3c14c1f2 2023-01-06 thomas </a>
740 fdd79f2f 2023-09-12 thomas </td>
741 3c14c1f2 2023-01-06 thomas {{ end }}
742 fdd79f2f 2023-09-12 thomas </tr>
743 3c14c1f2 2023-01-06 thomas {{ finally }}
744 3c14c1f2 2023-01-06 thomas {!
745 3c14c1f2 2023-01-06 thomas free(dir);
746 617497a6 2023-01-09 thomas !}
747 617497a6 2023-01-09 thomas {{ end }}
748 617497a6 2023-01-09 thomas
749 b3ba36c3 2023-01-14 thomas {{ define gotweb_render_tags(struct template *tp) }}
750 617497a6 2023-01-09 thomas {!
751 617497a6 2023-01-09 thomas struct request *c = tp->tp_arg;
752 617497a6 2023-01-09 thomas struct transport *t = c->t;
753 617497a6 2023-01-09 thomas struct querystring *qs = t->qs;
754 617497a6 2023-01-09 thomas struct repo_tag *rt;
755 617497a6 2023-01-09 thomas int commit_found;
756 617497a6 2023-01-09 thomas
757 617497a6 2023-01-09 thomas commit_found = qs->commit == NULL;
758 3c14c1f2 2023-01-06 thomas !}
759 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
760 fdd79f2f 2023-09-12 thomas <h2>Tags</h2>
761 fdd79f2f 2023-09-12 thomas </header>
762 617497a6 2023-01-09 thomas <div id="tags_content">
763 617497a6 2023-01-09 thomas {{ if t->tag_count == 0 }}
764 617497a6 2023-01-09 thomas <div id="err_content">
765 617497a6 2023-01-09 thomas This repository contains no tags
766 617497a6 2023-01-09 thomas </div>
767 617497a6 2023-01-09 thomas {{ else }}
768 617497a6 2023-01-09 thomas {{ tailq-foreach rt &t->repo_tags entry }}
769 617497a6 2023-01-09 thomas {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
770 617497a6 2023-01-09 thomas {! commit_found = 1; !}
771 617497a6 2023-01-09 thomas {{ render tag_item(tp, rt) }}
772 617497a6 2023-01-09 thomas {{ end }}
773 617497a6 2023-01-09 thomas {{ end }}
774 617497a6 2023-01-09 thomas {{ if t->next_id || t->prev_id }}
775 20bab626 2023-02-03 thomas {! qs->action = TAGS; !}
776 617497a6 2023-01-09 thomas {{ render gotweb_render_navs(tp) }}
777 617497a6 2023-01-09 thomas {{ end }}
778 617497a6 2023-01-09 thomas {{ end }}
779 617497a6 2023-01-09 thomas </div>
780 b82440e1 2023-01-06 thomas {{ end }}
781 b82440e1 2023-01-06 thomas
782 617497a6 2023-01-09 thomas {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
783 617497a6 2023-01-09 thomas {!
784 617497a6 2023-01-09 thomas struct request *c = tp->tp_arg;
785 617497a6 2023-01-09 thomas struct transport *t = c->t;
786 617497a6 2023-01-09 thomas struct repo_dir *repo_dir = t->repo_dir;
787 617497a6 2023-01-09 thomas char *tag_name = rt->tag_name;
788 617497a6 2023-01-09 thomas char *msg = rt->tag_commit;
789 617497a6 2023-01-09 thomas char *nl;
790 617497a6 2023-01-09 thomas struct gotweb_url url = {
791 617497a6 2023-01-09 thomas .action = TAG,
792 617497a6 2023-01-09 thomas .index_page = -1,
793 617497a6 2023-01-09 thomas .page = -1,
794 617497a6 2023-01-09 thomas .path = repo_dir->name,
795 617497a6 2023-01-09 thomas .commit = rt->commit_id,
796 617497a6 2023-01-09 thomas };
797 617497a6 2023-01-09 thomas
798 617497a6 2023-01-09 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
799 617497a6 2023-01-09 thomas tag_name += 10;
800 617497a6 2023-01-09 thomas
801 617497a6 2023-01-09 thomas if (msg) {
802 617497a6 2023-01-09 thomas nl = strchr(msg, '\n');
803 617497a6 2023-01-09 thomas if (nl)
804 617497a6 2023-01-09 thomas *nl = '\0';
805 617497a6 2023-01-09 thomas }
806 617497a6 2023-01-09 thomas !}
807 617497a6 2023-01-09 thomas <div class="tag_age">
808 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
809 617497a6 2023-01-09 thomas </div>
810 fdd79f2f 2023-09-12 thomas <div class="tag_name">{{ tag_name }}</div>
811 617497a6 2023-01-09 thomas <div class="tag_log">
812 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
813 617497a6 2023-01-09 thomas {{ msg }}
814 617497a6 2023-01-09 thomas </a>
815 617497a6 2023-01-09 thomas </div>
816 617497a6 2023-01-09 thomas <div class="navs_wrapper">
817 617497a6 2023-01-09 thomas <div class="navs">
818 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
819 617497a6 2023-01-09 thomas {{ " | " }}
820 617497a6 2023-01-09 thomas {! url.action = BRIEFS; !}
821 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
822 617497a6 2023-01-09 thomas {{ " | " }}
823 617497a6 2023-01-09 thomas {! url.action = COMMITS; !}
824 617497a6 2023-01-09 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
825 617497a6 2023-01-09 thomas </div>
826 617497a6 2023-01-09 thomas </div>
827 fdd79f2f 2023-09-12 thomas <hr />
828 617497a6 2023-01-09 thomas {{ end }}
829 145ca42a 2023-01-09 thomas
830 145ca42a 2023-01-09 thomas {{ define gotweb_render_tag(struct template *tp) }}
831 145ca42a 2023-01-09 thomas {!
832 145ca42a 2023-01-09 thomas struct request *c = tp->tp_arg;
833 145ca42a 2023-01-09 thomas struct transport *t = c->t;
834 145ca42a 2023-01-09 thomas struct repo_tag *rt;
835 145ca42a 2023-01-09 thomas const char *tag_name;
836 617497a6 2023-01-09 thomas
837 145ca42a 2023-01-09 thomas rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
838 145ca42a 2023-01-09 thomas tag_name = rt->tag_name;
839 145ca42a 2023-01-09 thomas
840 145ca42a 2023-01-09 thomas if (strncmp(tag_name, "refs/", 5) == 0)
841 145ca42a 2023-01-09 thomas tag_name += 5;
842 145ca42a 2023-01-09 thomas !}
843 fdd79f2f 2023-09-12 thomas <header class="subtitle">
844 fdd79f2f 2023-09-12 thomas <h2>Tag</h2>
845 fdd79f2f 2023-09-12 thomas </header>
846 145ca42a 2023-01-09 thomas <div id="tags_content">
847 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
848 57cfad1e 2023-12-01 thomas <dl>
849 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
850 fdd79f2f 2023-09-12 thomas <dd>
851 fdd79f2f 2023-09-12 thomas <code class="commit-id">{{ rt->commit_id }}</code>
852 145ca42a 2023-01-09 thomas {{ " " }}
853 145ca42a 2023-01-09 thomas <span class="refs_str">({{ tag_name }})</span>
854 fdd79f2f 2023-09-12 thomas </dd>
855 fdd79f2f 2023-09-12 thomas <dt>Tagger:</dt>
856 fdd79f2f 2023-09-12 thomas <dd>{{ rt->tagger }}</dd>
857 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
858 fdd79f2f 2023-09-12 thomas <dd>
859 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
860 fdd79f2f 2023-09-12 thomas </dd>
861 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
862 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rt->commit_msg }}</dd>
863 fdd79f2f 2023-09-12 thomas </dl>
864 fdd79f2f 2023-09-12 thomas <hr />
865 fdd79f2f 2023-09-12 thomas <pre id="tag_commit">
866 145ca42a 2023-01-09 thomas {{ rt->tag_commit }}
867 fdd79f2f 2023-09-12 thomas </pre>
868 dccd05b4 2023-01-10 thomas </div>
869 dccd05b4 2023-01-10 thomas </div>
870 dccd05b4 2023-01-10 thomas {{ end }}
871 dccd05b4 2023-01-10 thomas
872 161663e7 2023-03-11 thomas {{ define gotweb_render_diff(struct template *tp) }}
873 dccd05b4 2023-01-10 thomas {!
874 dccd05b4 2023-01-10 thomas struct request *c = tp->tp_arg;
875 dccd05b4 2023-01-10 thomas struct transport *t = c->t;
876 184e6e6f 2023-12-03 thomas struct querystring *qs = t->qs;
877 161663e7 2023-03-11 thomas FILE *fp = t->fp;
878 dccd05b4 2023-01-10 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
879 dccd05b4 2023-01-10 thomas char *line = NULL;
880 dccd05b4 2023-01-10 thomas size_t linesize = 0;
881 dccd05b4 2023-01-10 thomas ssize_t linelen;
882 184e6e6f 2023-12-03 thomas struct gotweb_url patch_url, tree_url = {
883 184e6e6f 2023-12-03 thomas .action = TREE,
884 184e6e6f 2023-12-03 thomas .index_page = -1,
885 184e6e6f 2023-12-03 thomas .page = -1,
886 184e6e6f 2023-12-03 thomas .path = qs->path,
887 184e6e6f 2023-12-03 thomas .commit = rc->commit_id,
888 184e6e6f 2023-12-03 thomas };
889 184e6e6f 2023-12-03 thomas
890 184e6e6f 2023-12-03 thomas memcpy(&patch_url, &tree_url, sizeof(patch_url));
891 184e6e6f 2023-12-03 thomas patch_url.action = PATCH;
892 dccd05b4 2023-01-10 thomas !}
893 fdd79f2f 2023-09-12 thomas <header class="subtitle">
894 fdd79f2f 2023-09-12 thomas <h2>Commit Diff</h2>
895 fdd79f2f 2023-09-12 thomas </header>
896 dccd05b4 2023-01-10 thomas <div id="diff_content">
897 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
898 57cfad1e 2023-12-01 thomas <dl>
899 fdd79f2f 2023-09-12 thomas <dt>Commit:</dt>
900 fdd79f2f 2023-09-12 thomas <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
901 fdd79f2f 2023-09-12 thomas <dt>From:</dt>
902 fdd79f2f 2023-09-12 thomas <dd>{{ rc->author }}</dd>
903 f7ee7604 2023-01-14 thomas {{ if strcmp(rc->committer, rc->author) != 0 }}
904 fdd79f2f 2023-09-12 thomas <dt>Via:</dt>
905 fdd79f2f 2023-09-12 thomas <dd>{{ rc->committer }}</dd>
906 f7ee7604 2023-01-14 thomas {{ end }}
907 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
908 fdd79f2f 2023-09-12 thomas <dd>
909 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
910 fdd79f2f 2023-09-12 thomas </dd>
911 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
912 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
913 184e6e6f 2023-12-03 thomas <dt>Actions:</dt>
914 184e6e6f 2023-12-03 thomas <dd>
915 184e6e6f 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &patch_url) }}">
916 184e6e6f 2023-12-03 thomas Patch
917 184e6e6f 2023-12-03 thomas </a>
918 184e6e6f 2023-12-03 thomas {{" | "}}
919 184e6e6f 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &tree_url) }}">
920 184e6e6f 2023-12-03 thomas Tree
921 184e6e6f 2023-12-03 thomas </a>
922 184e6e6f 2023-12-03 thomas </dd>
923 fdd79f2f 2023-09-12 thomas </dl>
924 145ca42a 2023-01-09 thomas </div>
925 fdd79f2f 2023-09-12 thomas <hr />
926 fdd79f2f 2023-09-12 thomas <pre id="diff">
927 dccd05b4 2023-01-10 thomas {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
928 dccd05b4 2023-01-10 thomas {{ render diff_line(tp, line) }}
929 dccd05b4 2023-01-10 thomas {{ end }}
930 fdd79f2f 2023-09-12 thomas </pre>
931 145ca42a 2023-01-09 thomas </div>
932 dccd05b4 2023-01-10 thomas {{ finally }}
933 dccd05b4 2023-01-10 thomas {! free(line); !}
934 145ca42a 2023-01-09 thomas {{ end }}
935 145ca42a 2023-01-09 thomas
936 dccd05b4 2023-01-10 thomas {{ define diff_line(struct template *tp, char *line )}}
937 dccd05b4 2023-01-10 thomas {!
938 dccd05b4 2023-01-10 thomas const char *color = NULL;
939 dccd05b4 2023-01-10 thomas char *nl;
940 dccd05b4 2023-01-10 thomas
941 dccd05b4 2023-01-10 thomas if (!strncmp(line, "-", 1))
942 dccd05b4 2023-01-10 thomas color = "diff_minus";
943 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "+", 1))
944 dccd05b4 2023-01-10 thomas color = "diff_plus";
945 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "@@", 2))
946 dccd05b4 2023-01-10 thomas color = "diff_chunk_header";
947 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "commit +", 8) ||
948 dccd05b4 2023-01-10 thomas !strncmp(line, "commit -", 8) ||
949 dccd05b4 2023-01-10 thomas !strncmp(line, "blob +", 6) ||
950 dccd05b4 2023-01-10 thomas !strncmp(line, "blob -", 6) ||
951 dccd05b4 2023-01-10 thomas !strncmp(line, "file +", 6) ||
952 dccd05b4 2023-01-10 thomas !strncmp(line, "file -", 6))
953 dccd05b4 2023-01-10 thomas color = "diff_meta";
954 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
955 dccd05b4 2023-01-10 thomas color = "diff_author";
956 dccd05b4 2023-01-10 thomas else if (!strncmp(line, "date:", 5))
957 dccd05b4 2023-01-10 thomas color = "diff_date";
958 dccd05b4 2023-01-10 thomas
959 dccd05b4 2023-01-10 thomas nl = strchr(line, '\n');
960 dccd05b4 2023-01-10 thomas if (nl)
961 dccd05b4 2023-01-10 thomas *nl = '\0';
962 dccd05b4 2023-01-10 thomas !}
963 fdd79f2f 2023-09-12 thomas <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
964 dccd05b4 2023-01-10 thomas {{ end }}
965 dccd05b4 2023-01-10 thomas
966 00abe30b 2023-01-14 thomas {{ define gotweb_render_branches(struct template *tp,
967 00abe30b 2023-01-14 thomas struct got_reflist_head *refs) }}
968 00abe30b 2023-01-14 thomas {!
969 00abe30b 2023-01-14 thomas struct got_reflist_entry *re;
970 00abe30b 2023-01-14 thomas !}
971 fdd79f2f 2023-09-12 thomas <header class='subtitle'>
972 fdd79f2f 2023-09-12 thomas <h2>Branches</h2>
973 fdd79f2f 2023-09-12 thomas </header>
974 00abe30b 2023-01-14 thomas <div id="branches_content">
975 00abe30b 2023-01-14 thomas {{ tailq-foreach re refs entry }}
976 00abe30b 2023-01-14 thomas {{ if !got_ref_is_symbolic(re->ref) }}
977 00abe30b 2023-01-14 thomas {{ render branch(tp, re) }}
978 00abe30b 2023-01-14 thomas {{ end }}
979 00abe30b 2023-01-14 thomas {{ end }}
980 00abe30b 2023-01-14 thomas </div>
981 00abe30b 2023-01-14 thomas {{ end }}
982 00abe30b 2023-01-14 thomas
983 00abe30b 2023-01-14 thomas {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
984 00abe30b 2023-01-14 thomas {!
985 00abe30b 2023-01-14 thomas const struct got_error *err;
986 00abe30b 2023-01-14 thomas struct request *c = tp->tp_arg;
987 00abe30b 2023-01-14 thomas struct querystring *qs = c->t->qs;
988 00abe30b 2023-01-14 thomas const char *refname;
989 53bf32b8 2023-01-23 thomas time_t age;
990 00abe30b 2023-01-14 thomas struct gotweb_url url = {
991 00abe30b 2023-01-14 thomas .action = SUMMARY,
992 00abe30b 2023-01-14 thomas .index_page = -1,
993 00abe30b 2023-01-14 thomas .page = -1,
994 00abe30b 2023-01-14 thomas .path = qs->path,
995 00abe30b 2023-01-14 thomas };
996 00abe30b 2023-01-14 thomas
997 00abe30b 2023-01-14 thomas refname = got_ref_get_name(re->ref);
998 00abe30b 2023-01-14 thomas
999 53bf32b8 2023-01-23 thomas err = got_get_repo_age(&age, c, refname);
1000 00abe30b 2023-01-14 thomas if (err) {
1001 00abe30b 2023-01-14 thomas log_warnx("%s: %s", __func__, err->msg);
1002 00abe30b 2023-01-14 thomas return -1;
1003 00abe30b 2023-01-14 thomas }
1004 00abe30b 2023-01-14 thomas
1005 00abe30b 2023-01-14 thomas if (strncmp(refname, "refs/heads/", 11) == 0)
1006 00abe30b 2023-01-14 thomas refname += 11;
1007 00abe30b 2023-01-14 thomas
1008 00abe30b 2023-01-14 thomas url.headref = refname;
1009 00abe30b 2023-01-14 thomas !}
1010 fdd79f2f 2023-09-12 thomas <section class="branches_wrapper">
1011 53bf32b8 2023-01-23 thomas <div class="branches_age">
1012 4cc0851e 2023-10-08 thomas {{ render datetime(tp, age, TM_DIFF) }}
1013 53bf32b8 2023-01-23 thomas </div>
1014 00abe30b 2023-01-14 thomas <div class="branch">
1015 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1016 00abe30b 2023-01-14 thomas </div>
1017 00abe30b 2023-01-14 thomas <div class="navs_wrapper">
1018 00abe30b 2023-01-14 thomas <div class="navs">
1019 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1020 00abe30b 2023-01-14 thomas {{" | "}}
1021 00abe30b 2023-01-14 thomas {! url.action = BRIEFS; !}
1022 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1023 00abe30b 2023-01-14 thomas {{" | "}}
1024 00abe30b 2023-01-14 thomas {! url.action = COMMITS; !}
1025 00abe30b 2023-01-14 thomas <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1026 00abe30b 2023-01-14 thomas </div>
1027 00abe30b 2023-01-14 thomas </div>
1028 fdd79f2f 2023-09-12 thomas <hr />
1029 fdd79f2f 2023-09-12 thomas </section>
1030 18e466eb 2023-01-14 thomas {{ end }}
1031 18e466eb 2023-01-14 thomas
1032 161663e7 2023-03-11 thomas {{ define gotweb_render_summary(struct template *tp) }}
1033 18e466eb 2023-01-14 thomas {!
1034 18e466eb 2023-01-14 thomas struct request *c = tp->tp_arg;
1035 18e466eb 2023-01-14 thomas struct server *srv = c->srv;
1036 18e466eb 2023-01-14 thomas struct transport *t = c->t;
1037 161663e7 2023-03-11 thomas struct got_reflist_head *refs = &t->refs;
1038 18e466eb 2023-01-14 thomas !}
1039 feaddee6 2023-12-03 thomas <dl id="summary_wrapper" class="page_header_wrapper">
1040 18e466eb 2023-01-14 thomas {{ if srv->show_repo_description }}
1041 fdd79f2f 2023-09-12 thomas <dt>Description:</dt>
1042 fdd79f2f 2023-09-12 thomas <dd>{{ t->repo_dir->description }}</dd>
1043 18e466eb 2023-01-14 thomas {{ end }}
1044 18e466eb 2023-01-14 thomas {{ if srv->show_repo_owner }}
1045 fdd79f2f 2023-09-12 thomas <dt>Owner:</dt>
1046 fdd79f2f 2023-09-12 thomas <dd>{{ t->repo_dir->owner }}</dd>
1047 18e466eb 2023-01-14 thomas {{ end }}
1048 18e466eb 2023-01-14 thomas {{ if srv->show_repo_age }}
1049 fdd79f2f 2023-09-12 thomas <dt>Last Change:</dt>
1050 fdd79f2f 2023-09-12 thomas <dd>
1051 4cc0851e 2023-10-08 thomas {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1052 fdd79f2f 2023-09-12 thomas </dd>
1053 18e466eb 2023-01-14 thomas {{ end }}
1054 18e466eb 2023-01-14 thomas {{ if srv->show_repo_cloneurl }}
1055 fdd79f2f 2023-09-12 thomas <dt>Clone URL:</dt>
1056 fdd79f2f 2023-09-12 thomas <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1057 18e466eb 2023-01-14 thomas {{ end }}
1058 fdd79f2f 2023-09-12 thomas </dl>
1059 18e466eb 2023-01-14 thomas {{ render gotweb_render_briefs(tp) }}
1060 18e466eb 2023-01-14 thomas {{ render gotweb_render_tags(tp) }}
1061 18e466eb 2023-01-14 thomas {{ render gotweb_render_branches(tp, refs) }}
1062 00abe30b 2023-01-14 thomas {{ end }}
1063 00abe30b 2023-01-14 thomas
1064 1cd5d437 2023-01-15 thomas {{ define gotweb_render_blame(struct template *tp) }}
1065 1cd5d437 2023-01-15 thomas {!
1066 1cd5d437 2023-01-15 thomas const struct got_error *err;
1067 1cd5d437 2023-01-15 thomas struct request *c = tp->tp_arg;
1068 1cd5d437 2023-01-15 thomas struct transport *t = c->t;
1069 4f4afeeb 2023-12-03 thomas struct querystring *qs = t->qs;
1070 1cd5d437 2023-01-15 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1071 4f4afeeb 2023-12-03 thomas struct gotweb_url briefs_url, blob_url, raw_url;
1072 4f4afeeb 2023-12-03 thomas
1073 4f4afeeb 2023-12-03 thomas memset(&briefs_url, 0, sizeof(briefs_url));
1074 4f4afeeb 2023-12-03 thomas briefs_url.index_page = -1,
1075 4f4afeeb 2023-12-03 thomas briefs_url.page = -1,
1076 4f4afeeb 2023-12-03 thomas briefs_url.action = BRIEFS,
1077 4f4afeeb 2023-12-03 thomas briefs_url.path = qs->path,
1078 4f4afeeb 2023-12-03 thomas briefs_url.commit = qs->commit,
1079 4f4afeeb 2023-12-03 thomas briefs_url.folder = qs->folder,
1080 4f4afeeb 2023-12-03 thomas briefs_url.file = qs->file,
1081 4f4afeeb 2023-12-03 thomas
1082 4f4afeeb 2023-12-03 thomas memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1083 4f4afeeb 2023-12-03 thomas blob_url.action = BLOB;
1084 4f4afeeb 2023-12-03 thomas
1085 4f4afeeb 2023-12-03 thomas memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1086 4f4afeeb 2023-12-03 thomas raw_url.action = BLOBRAW;
1087 1cd5d437 2023-01-15 thomas !}
1088 fdd79f2f 2023-09-12 thomas <header class="subtitle">
1089 fdd79f2f 2023-09-12 thomas <h2>Blame</h2>
1090 fdd79f2f 2023-09-12 thomas </header>
1091 1cd5d437 2023-01-15 thomas <div id="blame_content">
1092 57cfad1e 2023-12-01 thomas <div class="page_header_wrapper">
1093 57cfad1e 2023-12-01 thomas <dl>
1094 fdd79f2f 2023-09-12 thomas <dt>Date:</dt>
1095 fdd79f2f 2023-09-12 thomas <dd>
1096 4cc0851e 2023-10-08 thomas {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1097 fdd79f2f 2023-09-12 thomas </dd>
1098 fdd79f2f 2023-09-12 thomas <dt>Message:</dt>
1099 fdd79f2f 2023-09-12 thomas <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1100 4f4afeeb 2023-12-03 thomas <dt>Actions:</dt>
1101 4f4afeeb 2023-12-03 thomas <dd>
1102 4f4afeeb 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1103 4f4afeeb 2023-12-03 thomas History
1104 4f4afeeb 2023-12-03 thomas </a>
1105 4f4afeeb 2023-12-03 thomas {{" | "}}
1106 4f4afeeb 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1107 4f4afeeb 2023-12-03 thomas Blob
1108 4f4afeeb 2023-12-03 thomas </a>
1109 4f4afeeb 2023-12-03 thomas {{" | "}}
1110 4f4afeeb 2023-12-03 thomas <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1111 4f4afeeb 2023-12-03 thomas Raw File
1112 4f4afeeb 2023-12-03 thomas </a>
1113 4f4afeeb 2023-12-03 thomas </dd>
1114 fdd79f2f 2023-09-12 thomas </dl>
1115 1cd5d437 2023-01-15 thomas </div>
1116 fdd79f2f 2023-09-12 thomas <hr />
1117 fdd79f2f 2023-09-12 thomas <pre id="blame">
1118 1cd5d437 2023-01-15 thomas {!
1119 1cd5d437 2023-01-15 thomas err = got_output_file_blame(c, &blame_line);
1120 aa2aecab 2023-05-25 thomas if (err && err->code != GOT_ERR_CANCELLED)
1121 1cd5d437 2023-01-15 thomas log_warnx("%s: got_output_file_blame: %s", __func__,
1122 1cd5d437 2023-01-15 thomas err->msg);
1123 aa2aecab 2023-05-25 thomas if (err)
1124 1cd5d437 2023-01-15 thomas return (-1);
1125 1cd5d437 2023-01-15 thomas !}
1126 fdd79f2f 2023-09-12 thomas </pre>
1127 1cd5d437 2023-01-15 thomas </div>
1128 1cd5d437 2023-01-15 thomas {{ end }}
1129 1cd5d437 2023-01-15 thomas
1130 1cd5d437 2023-01-15 thomas {{ define blame_line(struct template *tp, const char *line,
1131 1cd5d437 2023-01-15 thomas struct blame_line *bline, int lprec, int lcur) }}
1132 1cd5d437 2023-01-15 thomas {!
1133 1cd5d437 2023-01-15 thomas struct request *c = tp->tp_arg;
1134 1cd5d437 2023-01-15 thomas struct transport *t = c->t;
1135 1cd5d437 2023-01-15 thomas struct repo_dir *repo_dir = t->repo_dir;
1136 1cd5d437 2023-01-15 thomas char *committer, *s;
1137 1cd5d437 2023-01-15 thomas struct gotweb_url url = {
1138 1cd5d437 2023-01-15 thomas .action = DIFF,
1139 1cd5d437 2023-01-15 thomas .index_page = -1,
1140 1cd5d437 2023-01-15 thomas .page = -1,
1141 1cd5d437 2023-01-15 thomas .path = repo_dir->name,
1142 1cd5d437 2023-01-15 thomas .commit = bline->id_str,
1143 1cd5d437 2023-01-15 thomas };
1144 1cd5d437 2023-01-15 thomas
1145 1cd5d437 2023-01-15 thomas s = strchr(bline->committer, '<');
1146 1cd5d437 2023-01-15 thomas committer = s ? s + 1 : bline->committer;
1147 1cd5d437 2023-01-15 thomas
1148 1cd5d437 2023-01-15 thomas s = strchr(committer, '@');
1149 1cd5d437 2023-01-15 thomas if (s)
1150 1cd5d437 2023-01-15 thomas *s = '\0';
1151 1cd5d437 2023-01-15 thomas !}
1152 83d26b5a 2023-12-03 thomas <div class="blame_line">
1153 83d26b5a 2023-12-03 thomas <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1154 83d26b5a 2023-12-03 thomas <span class="blame_hash">
1155 1cd5d437 2023-01-15 thomas <a href="{{ render gotweb_render_url(c, &url) }}">
1156 1cd5d437 2023-01-15 thomas {{ printf "%.8s", bline->id_str }}
1157 1cd5d437 2023-01-15 thomas </a>
1158 83d26b5a 2023-12-03 thomas </span>
1159 83d26b5a 2023-12-03 thomas {{" "}}
1160 83d26b5a 2023-12-03 thomas <span class="blame_date">{{ bline->datebuf }}</span>
1161 83d26b5a 2023-12-03 thomas {{" "}}
1162 83d26b5a 2023-12-03 thomas <span class="blame_author">{{ printf "%.9s", committer }}</span>
1163 83d26b5a 2023-12-03 thomas {{" "}}
1164 83d26b5a 2023-12-03 thomas <span class="blame_code">{{ line }}</span>
1165 1cd5d437 2023-01-15 thomas </div>
1166 feaddee6 2023-12-03 thomas {{ end }}
1167 feaddee6 2023-12-03 thomas
1168 feaddee6 2023-12-03 thomas {{ define gotweb_render_patch(struct template *tp) }}
1169 feaddee6 2023-12-03 thomas {!
1170 feaddee6 2023-12-03 thomas struct request *c = tp->tp_arg;
1171 feaddee6 2023-12-03 thomas struct transport *t = c->t;
1172 feaddee6 2023-12-03 thomas struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1173 feaddee6 2023-12-03 thomas struct tm tm;
1174 feaddee6 2023-12-03 thomas char buf[BUFSIZ], datebuf[64];
1175 feaddee6 2023-12-03 thomas size_t r;
1176 feaddee6 2023-12-03 thomas
1177 feaddee6 2023-12-03 thomas if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1178 feaddee6 2023-12-03 thomas strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1179 feaddee6 2023-12-03 thomas return (-1);
1180 feaddee6 2023-12-03 thomas !}
1181 feaddee6 2023-12-03 thomas commit {{ rc->commit_id }} {{ "\n" }}
1182 feaddee6 2023-12-03 thomas from: {{ rc->author | unsafe }} {{ "\n" }}
1183 feaddee6 2023-12-03 thomas {{ if strcmp(rc->committer, rc->author) != 0 }}
1184 feaddee6 2023-12-03 thomas via: {{ rc->committer | unsafe }} {{ "\n" }}
1185 1cd5d437 2023-01-15 thomas {{ end }}
1186 feaddee6 2023-12-03 thomas date: {{ datebuf }} {{ "\n" }}
1187 feaddee6 2023-12-03 thomas {{ "\n" }}
1188 feaddee6 2023-12-03 thomas {{ rc->commit_msg | unsafe }} {{ "\n" }}
1189 feaddee6 2023-12-03 thomas {!
1190 feaddee6 2023-12-03 thomas if (template_flush(tp) == -1)
1191 feaddee6 2023-12-03 thomas return (-1);
1192 feaddee6 2023-12-03 thomas for (;;) {
1193 feaddee6 2023-12-03 thomas r = fread(buf, 1, sizeof(buf), t->fp);
1194 feaddee6 2023-12-03 thomas if (fcgi_write(c, buf, r) == -1 ||
1195 feaddee6 2023-12-03 thomas r != sizeof(buf))
1196 feaddee6 2023-12-03 thomas break;
1197 feaddee6 2023-12-03 thomas }
1198 feaddee6 2023-12-03 thomas !}
1199 feaddee6 2023-12-03 thomas {{ end }}
1200 1cd5d437 2023-01-15 thomas
1201 d6795e9f 2022-12-30 thomas {{ define gotweb_render_rss(struct template *tp) }}
1202 d6795e9f 2022-12-30 thomas {!
1203 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
1204 d6795e9f 2022-12-30 thomas struct server *srv = c->srv;
1205 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
1206 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
1207 d6795e9f 2022-12-30 thomas struct repo_tag *rt;
1208 d6795e9f 2022-12-30 thomas struct gotweb_url summary = {
1209 d6795e9f 2022-12-30 thomas .action = SUMMARY,
1210 d6795e9f 2022-12-30 thomas .index_page = -1,
1211 d6795e9f 2022-12-30 thomas .page = -1,
1212 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
1213 d6795e9f 2022-12-30 thomas };
1214 d6795e9f 2022-12-30 thomas !}
1215 d6795e9f 2022-12-30 thomas <?xml version="1.0" encoding="UTF-8"?>
1216 d6795e9f 2022-12-30 thomas <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1217 d6795e9f 2022-12-30 thomas <channel>
1218 d6795e9f 2022-12-30 thomas <title>Tags of {{ repo_dir->name }}</title>
1219 d6795e9f 2022-12-30 thomas <link>
1220 d6795e9f 2022-12-30 thomas <![CDATA[
1221 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &summary) }}
1222 d6795e9f 2022-12-30 thomas ]]>
1223 d6795e9f 2022-12-30 thomas </link>
1224 d6795e9f 2022-12-30 thomas {{ if srv->show_repo_description }}
1225 d6795e9f 2022-12-30 thomas <description>{{ repo_dir->description }}</description>
1226 d6795e9f 2022-12-30 thomas {{ end }}
1227 d6795e9f 2022-12-30 thomas {{ tailq-foreach rt &t->repo_tags entry }}
1228 d6795e9f 2022-12-30 thomas {{ render rss_tag_item(tp, rt) }}
1229 d6795e9f 2022-12-30 thomas {{ end }}
1230 d6795e9f 2022-12-30 thomas </channel>
1231 d6795e9f 2022-12-30 thomas </rss>
1232 d6795e9f 2022-12-30 thomas {{ end }}
1233 d6795e9f 2022-12-30 thomas
1234 d6795e9f 2022-12-30 thomas {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1235 d6795e9f 2022-12-30 thomas {!
1236 d6795e9f 2022-12-30 thomas struct request *c = tp->tp_arg;
1237 d6795e9f 2022-12-30 thomas struct transport *t = c->t;
1238 d6795e9f 2022-12-30 thomas struct repo_dir *repo_dir = t->repo_dir;
1239 10fa70e2 2023-10-08 thomas struct tm tm;
1240 10fa70e2 2023-10-08 thomas char rfc822[128];
1241 10fa70e2 2023-10-08 thomas int r;
1242 d6795e9f 2022-12-30 thomas char *tag_name = rt->tag_name;
1243 d6795e9f 2022-12-30 thomas struct gotweb_url tag = {
1244 d6795e9f 2022-12-30 thomas .action = TAG,
1245 d6795e9f 2022-12-30 thomas .index_page = -1,
1246 d6795e9f 2022-12-30 thomas .page = -1,
1247 d6795e9f 2022-12-30 thomas .path = repo_dir->name,
1248 d6795e9f 2022-12-30 thomas .commit = rt->commit_id,
1249 d6795e9f 2022-12-30 thomas };
1250 d6795e9f 2022-12-30 thomas
1251 d6795e9f 2022-12-30 thomas if (strncmp(tag_name, "refs/tags/", 10) == 0)
1252 d6795e9f 2022-12-30 thomas tag_name += 10;
1253 10fa70e2 2023-10-08 thomas
1254 10fa70e2 2023-10-08 thomas if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1255 10fa70e2 2023-10-08 thomas return -1;
1256 10fa70e2 2023-10-08 thomas r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1257 10fa70e2 2023-10-08 thomas if (r == 0)
1258 10fa70e2 2023-10-08 thomas return 0;
1259 d6795e9f 2022-12-30 thomas !}
1260 d6795e9f 2022-12-30 thomas <item>
1261 d6795e9f 2022-12-30 thomas <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1262 d6795e9f 2022-12-30 thomas <link>
1263 d6795e9f 2022-12-30 thomas <![CDATA[
1264 d6795e9f 2022-12-30 thomas {{ render gotweb_render_absolute_url(c, &tag) }}
1265 d6795e9f 2022-12-30 thomas ]]>
1266 d6795e9f 2022-12-30 thomas </link>
1267 d6795e9f 2022-12-30 thomas <description>
1268 d6795e9f 2022-12-30 thomas <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1269 d6795e9f 2022-12-30 thomas </description>
1270 d6795e9f 2022-12-30 thomas {{ render rss_author(tp, rt->tagger) }}
1271 d6795e9f 2022-12-30 thomas <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1272 d6795e9f 2022-12-30 thomas <pubDate>
1273 10fa70e2 2023-10-08 thomas {{ rfc822 }}
1274 d6795e9f 2022-12-30 thomas </pubDate>
1275 d6795e9f 2022-12-30 thomas </item>
1276 7ade8b27 2022-12-30 thomas {{ end }}
1277 d6795e9f 2022-12-30 thomas
1278 d6795e9f 2022-12-30 thomas {{ define rss_author(struct template *tp, char *author) }}
1279 d6795e9f 2022-12-30 thomas {!
1280 d6795e9f 2022-12-30 thomas char *t, *mail;
1281 d6795e9f 2022-12-30 thomas
1282 d6795e9f 2022-12-30 thomas /* what to do if the author name contains a paren? */
1283 d6795e9f 2022-12-30 thomas if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1284 d6795e9f 2022-12-30 thomas return 0;
1285 d6795e9f 2022-12-30 thomas
1286 d6795e9f 2022-12-30 thomas t = strchr(author, '<');
1287 d6795e9f 2022-12-30 thomas if (t == NULL)
1288 d6795e9f 2022-12-30 thomas return 0;
1289 d6795e9f 2022-12-30 thomas *t = '\0';
1290 d6795e9f 2022-12-30 thomas mail = t+1;
1291 d6795e9f 2022-12-30 thomas
1292 d6795e9f 2022-12-30 thomas while (isspace((unsigned char)*--t))
1293 d6795e9f 2022-12-30 thomas *t = '\0';
1294 d6795e9f 2022-12-30 thomas
1295 d6795e9f 2022-12-30 thomas t = strchr(mail, '>');
1296 d6795e9f 2022-12-30 thomas if (t == NULL)
1297 d6795e9f 2022-12-30 thomas return 0;
1298 d6795e9f 2022-12-30 thomas *t = '\0';
1299 d6795e9f 2022-12-30 thomas !}
1300 d6795e9f 2022-12-30 thomas <author>
1301 d6795e9f 2022-12-30 thomas {{ mail }} {{" "}} ({{ author }})
1302 d6795e9f 2022-12-30 thomas </author>
1303 d6795e9f 2022-12-30 thomas {{ end }}