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