Blob


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