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 <sys/types.h>
20 #include <sys/queue.h>
21 #include <sys/stat.h>
23 #include <ctype.h>
24 #include <event.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sha1.h>
30 #include <imsg.h>
32 #include "got_error.h"
33 #include "got_object.h"
34 #include "got_reference.h"
36 #include "proc.h"
38 #include "gotwebd.h"
39 #include "tmpl.h"
41 static int gotweb_render_blob_line(struct template *, const char *, size_t);
42 static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
43 static int blame_line(struct template *, const char *, struct blame_line *,
44 int, int);
46 static inline int gotweb_render_more(struct template *, int);
48 static inline int diff_line(struct template *, char *);
49 static inline int tag_item(struct template *, struct repo_tag *);
50 static inline int branch(struct template *, struct got_reflist_entry *);
51 static inline int rss_tag_item(struct template *, struct repo_tag *);
52 static inline int rss_author(struct template *, char *);
54 !}
56 {{ define gotweb_render_header(struct template *tp) }}
57 {!
58 struct request *c = tp->tp_arg;
59 struct server *srv = c->srv;
60 struct querystring *qs = c->t->qs;
61 struct gotweb_url u_path;
62 const char *prfx = c->document_uri;
63 const char *css = srv->custom_css;
65 memset(&u_path, 0, sizeof(u_path));
66 u_path.index_page = -1;
67 u_path.page = -1;
68 u_path.action = SUMMARY;
69 !}
70 <!doctype html>
71 <html>
72 <head>
73 <meta charset="utf-8" />
74 <title>{{ srv->site_name }}</title>
75 <meta name="viewport" content="initial-scale=.75" />
76 <meta name="msapplication-TileColor" content="#da532c" />
77 <meta name="theme-color" content="#ffffff"/>
78 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
79 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
80 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
81 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
82 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
83 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
84 </head>
85 <body>
86 <div id="gw_body">
87 <div id="header">
88 <div id="got_link">
89 <a href="{{ srv->logo_url }}" target="_blank">
90 <img src="{{ prfx }}{{ srv->logo }}" />
91 </a>
92 </div>
93 </div>
94 <div id="site_path">
95 <div id="site_link">
96 <a href="?index_page={{ printf "%d", qs->index_page }}">
97 {{ srv->site_link }}
98 </a>
99 {{ if qs->path }}
100 {! u_path.path = qs->path; !}
101 {{ " / " }}
102 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
103 {{ qs->path }}
104 </a>
105 {{ end }}
106 {{ if qs->action != INDEX }}
107 {{ " / " }}{{ gotweb_action_name(qs->action) }}
108 {{ end }}
109 </div>
110 </div>
111 <div id="content">
112 {{ end }}
114 {{ define gotweb_render_footer(struct template *tp) }}
115 {!
116 struct request *c = tp->tp_arg;
117 struct server *srv = c->srv;
118 !}
119 <div id="site_owner_wrapper">
120 <div id="site_owner">
121 {{ if srv->show_site_owner }}
122 {{ srv->site_owner }}
123 {{ end }}
124 </div>
125 </div>
126 </div>
127 </div>
128 </body>
129 </html>
130 {{ end }}
132 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
133 {!
134 struct request *c = tp->tp_arg;
135 struct server *srv = c->srv;
136 !}
137 <div id="index_header">
138 <div id="index_header_project">
139 Project
140 </div>
141 {{ if srv->show_repo_description }}
142 <div id="index_header_description">
143 Description
144 </div>
145 {{ end }}
146 {{ if srv->show_repo_owner }}
147 <div id="index_header_owner">
148 Owner
149 </div>
150 {{ end }}
151 {{ if srv->show_repo_age }}
152 <div id="index_header_age">
153 Last Change
154 </div>
155 {{ end }}
156 </div>
157 {{ end }}
159 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
160 {!
161 struct request *c = tp->tp_arg;
162 struct server *srv = c->srv;
163 struct gotweb_url summary = {
164 .action = SUMMARY,
165 .index_page = -1,
166 .page = -1,
167 .path = repo_dir->name,
168 }, briefs = {
169 .action = BRIEFS,
170 .index_page = -1,
171 .page = -1,
172 .path = repo_dir->name,
173 }, commits = {
174 .action = COMMITS,
175 .index_page = -1,
176 .page = -1,
177 .path = repo_dir->name,
178 }, tags = {
179 .action = TAGS,
180 .index_page = -1,
181 .page = -1,
182 .path = repo_dir->name,
183 }, tree = {
184 .action = TREE,
185 .index_page = -1,
186 .page = -1,
187 .path = repo_dir->name,
188 }, rss = {
189 .action = RSS,
190 .index_page = -1,
191 .page = -1,
192 .path = repo_dir->name,
193 };
194 !}
195 <div class="index_wrapper">
196 <div class="index_project">
197 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
198 </div>
199 {{ if srv->show_repo_description }}
200 <div class="index_project_description">
201 {{ repo_dir->description }}
202 </div>
203 {{ end }}
204 {{ if srv->show_repo_owner }}
205 <div class="index_project_owner">
206 {{ repo_dir->owner }}
207 </div>
208 {{ end }}
209 {{ if srv->show_repo_age }}
210 <div class="index_project_age">
211 {{ render gotweb_render_age(tp, repo_dir->age, TM_DIFF) }}
212 </div>
213 {{ end }}
214 <div class="navs_wrapper">
215 <div class="navs">
216 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
217 {{ " | " }}
218 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
219 {{ " | " }}
220 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
221 {{ " | " }}
222 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
223 {{ " | " }}
224 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
225 {{ " | " }}
226 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
227 </div>
228 <div class="dotted_line"></div>
229 </div>
230 </div>
231 {{ end }}
233 {{ define gotweb_render_briefs(struct template *tp) }}
234 {!
235 const struct got_error *error;
236 struct request *c = tp->tp_arg;
237 struct server *srv = c->srv;
238 struct transport *t = c->t;
239 struct querystring *qs = c->t->qs;
240 struct repo_commit *rc;
241 struct repo_dir *repo_dir = t->repo_dir;
242 struct gotweb_url diff_url, tree_url;
243 char *tmp;
245 diff_url = (struct gotweb_url){
246 .action = DIFF,
247 .index_page = -1,
248 .page = -1,
249 .path = repo_dir->name,
250 .headref = qs->headref,
251 };
252 tree_url = (struct gotweb_url){
253 .action = TREE,
254 .index_page = -1,
255 .page = -1,
256 .path = repo_dir->name,
257 .headref = qs->headref,
258 };
260 if (qs->action == SUMMARY) {
261 qs->action = BRIEFS;
262 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
263 } else
264 error = got_get_repo_commits(c, srv->max_commits_display);
265 if (error)
266 return -1;
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 struct got_blob_object *blob) }}
437 {!
438 struct request *c = tp->tp_arg;
439 struct transport *t = c->t;
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, FILE *fp) }}
714 {!
715 struct request *c = tp->tp_arg;
716 struct transport *t = c->t;
717 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
718 char *line = NULL;
719 size_t linesize = 0;
720 ssize_t linelen;
721 !}
722 <div id="diff_title_wrapper">
723 <div id="diff_title">Commit Diff</div>
724 </div>
725 <div id="diff_content">
726 <div id="diff_header_wrapper">
727 <div id="diff_header">
728 <div class="header_commit_title">Commit:</div>
729 <div class="header_commit">{{ rc->commit_id }}</div>
730 <div class="header_author_title">From:</div>
731 <div class="header_author">{{ rc->author }}</div>
732 {{ if strcmp(rc->committer, rc->author) != 0 }}
733 <div class="header_author_title">Via:</div>
734 <div class="header_author">{{ rc->committer }}</div>
735 {{ end }}
736 <div class="header_age_title">Date:</div>
737 <div class="header_age">
738 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
739 </div>
740 <div id="header_commit_msg_title">Message</div>
741 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
742 </div>
743 </div>
744 <div class="dotted_line"></div>
745 <div id="diff">
746 {{ "\n" }}
747 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
748 {{ render diff_line(tp, line) }}
749 {{ end }}
750 </div>
751 </div>
752 {{ finally }}
753 {! free(line); !}
754 {{ end }}
756 {{ define diff_line(struct template *tp, char *line )}}
757 {!
758 const char *color = NULL;
759 char *nl;
761 if (!strncmp(line, "-", 1))
762 color = "diff_minus";
763 else if (!strncmp(line, "+", 1))
764 color = "diff_plus";
765 else if (!strncmp(line, "@@", 2))
766 color = "diff_chunk_header";
767 else if (!strncmp(line, "commit +", 8) ||
768 !strncmp(line, "commit -", 8) ||
769 !strncmp(line, "blob +", 6) ||
770 !strncmp(line, "blob -", 6) ||
771 !strncmp(line, "file +", 6) ||
772 !strncmp(line, "file -", 6))
773 color = "diff_meta";
774 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
775 color = "diff_author";
776 else if (!strncmp(line, "date:", 5))
777 color = "diff_date";
779 nl = strchr(line, '\n');
780 if (nl)
781 *nl = '\0';
782 !}
783 <div class="diff_line {{ color }}">{{ line }}</div>
784 {{ end }}
786 {{ define gotweb_render_branches(struct template *tp,
787 struct got_reflist_head *refs) }}
788 {!
789 struct got_reflist_entry *re;
790 !}
791 <div id="branches_title_wrapper">
792 <div id="branches_title">Branches</div>
793 </div>
794 <div id="branches_content">
795 {{ tailq-foreach re refs entry }}
796 {{ if !got_ref_is_symbolic(re->ref) }}
797 {{ render branch(tp, re) }}
798 {{ end }}
799 {{ end }}
800 </div>
801 {{ end }}
803 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
804 {!
805 const struct got_error *err;
806 struct request *c = tp->tp_arg;
807 struct querystring *qs = c->t->qs;
808 const char *refname;
809 time_t age;
810 struct gotweb_url url = {
811 .action = SUMMARY,
812 .index_page = -1,
813 .page = -1,
814 .path = qs->path,
815 };
817 refname = got_ref_get_name(re->ref);
819 err = got_get_repo_age(&age, c, refname);
820 if (err) {
821 log_warnx("%s: %s", __func__, err->msg);
822 return -1;
825 if (strncmp(refname, "refs/heads/", 11) == 0)
826 refname += 11;
828 url.headref = refname;
829 !}
830 <div class="branches_wrapper">
831 <div class="branches_age">
832 {{ render gotweb_render_age(tp, age, TM_DIFF) }}
833 </div>
834 <div class="branches_space">&nbsp;</div>
835 <div class="branch">
836 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
837 </div>
838 <div class="navs_wrapper">
839 <div class="navs">
840 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
841 {{" | "}}
842 {! url.action = BRIEFS; !}
843 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
844 {{" | "}}
845 {! url.action = COMMITS; !}
846 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
847 </div>
848 </div>
849 <div class="dotted_line"></div>
850 </div>
851 {{ end }}
853 {{ define gotweb_render_summary(struct template *tp,
854 struct got_reflist_head *refs) }}
855 {!
856 struct request *c = tp->tp_arg;
857 struct server *srv = c->srv;
858 struct transport *t = c->t;
859 !}
860 <div id="summary_wrapper">
861 {{ if srv->show_repo_description }}
862 <div id="description_title">Description:</div>
863 <div id="description">{{ t->repo_dir->description }}</div>
864 {{ end }}
865 {{ if srv->show_repo_owner }}
866 <div id="repo_owner_title">Owner:</div>
867 <div id="repo_owner">{{ t->repo_dir->owner }}</div>
868 {{ end }}
869 {{ if srv->show_repo_age }}
870 <div id="last_change_title">Last Change:</div>
871 <div id="last_change">
872 {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
873 </div>
874 {{ end }}
875 {{ if srv->show_repo_cloneurl }}
876 <div id="cloneurl_title">Clone URL:</div>
877 <div id="cloneurl">{{ t->repo_dir->url }}</div>
878 {{ end }}
879 </div>
880 {{ render gotweb_render_briefs(tp) }}
881 {{ render gotweb_render_tags(tp) }}
882 {{ render gotweb_render_branches(tp, refs) }}
883 {{ end }}
885 {{ define gotweb_render_blame(struct template *tp) }}
886 {!
887 const struct got_error *err;
888 struct request *c = tp->tp_arg;
889 struct transport *t = c->t;
890 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
891 !}
892 <div id="blame_title_wrapper">
893 <div id="blame_title">Blame</div>
894 </div>
895 <div id="blame_content">
896 <div id="blame_header_wrapper">
897 <div id="blame_header">
898 <div class="header_age_title">Date:</div>
899 <div class="header_age">
900 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
901 </div>
902 <div id="header_commit_msg_title">Message:</div>
903 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
904 </div>
905 </div>
906 <div class="dotted_line"></div>
907 <div id="blame">
908 {{ "\n" }}
909 {!
910 err = got_output_file_blame(c, &blame_line);
911 if (err) {
912 log_warnx("%s: got_output_file_blame: %s", __func__,
913 err->msg);
914 return (-1);
916 !}
917 </div>
918 </div>
919 {{ end }}
921 {{ define blame_line(struct template *tp, const char *line,
922 struct blame_line *bline, int lprec, int lcur) }}
923 {!
924 struct request *c = tp->tp_arg;
925 struct transport *t = c->t;
926 struct repo_dir *repo_dir = t->repo_dir;
927 char *committer, *s;
928 struct gotweb_url url = {
929 .action = DIFF,
930 .index_page = -1,
931 .page = -1,
932 .path = repo_dir->name,
933 .commit = bline->id_str,
934 };
936 s = strchr(bline->committer, '<');
937 committer = s ? s + 1 : bline->committer;
939 s = strchr(committer, '@');
940 if (s)
941 *s = '\0';
942 !}
943 <div class="blame_wrapper">
944 <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
945 <div class="blame_hash">
946 <a href="{{ render gotweb_render_url(c, &url) }}">
947 {{ printf "%.8s", bline->id_str }}
948 </a>
949 </div>
950 <div class="blame_date">{{ bline->datebuf }}</div>
951 <div class="blame_author">{{ printf "%.9s", committer }}</div>
952 <div class="blame_code">{{ line }}</div>
953 </div>
954 {{ end }}
956 {{ define gotweb_render_rss(struct template *tp) }}
957 {!
958 struct request *c = tp->tp_arg;
959 struct server *srv = c->srv;
960 struct transport *t = c->t;
961 struct repo_dir *repo_dir = t->repo_dir;
962 struct repo_tag *rt;
963 struct gotweb_url summary = {
964 .action = SUMMARY,
965 .index_page = -1,
966 .page = -1,
967 .path = repo_dir->name,
968 };
969 !}
970 <?xml version="1.0" encoding="UTF-8"?>
971 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
972 <channel>
973 <title>Tags of {{ repo_dir->name }}</title>
974 <link>
975 <![CDATA[
976 {{ render gotweb_render_absolute_url(c, &summary) }}
977 ]]>
978 </link>
979 {{ if srv->show_repo_description }}
980 <description>{{ repo_dir->description }}</description>
981 {{ end }}
982 {{ tailq-foreach rt &t->repo_tags entry }}
983 {{ render rss_tag_item(tp, rt) }}
984 {{ end }}
985 </channel>
986 </rss>
987 {{ end }}
989 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
990 {!
991 struct request *c = tp->tp_arg;
992 struct transport *t = c->t;
993 struct repo_dir *repo_dir = t->repo_dir;
994 char *tag_name = rt->tag_name;
995 struct gotweb_url tag = {
996 .action = TAG,
997 .index_page = -1,
998 .page = -1,
999 .path = repo_dir->name,
1000 .commit = rt->commit_id,
1003 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1004 tag_name += 10;
1006 <item>
1007 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1008 <link>
1009 <![CDATA[
1010 {{ render gotweb_render_absolute_url(c, &tag) }}
1011 ]]>
1012 </link>
1013 <description>
1014 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1015 </description>
1016 {{ render rss_author(tp, rt->tagger) }}
1017 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1018 <pubDate>
1019 {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
1020 </pubDate>
1021 </item>
1022 {{ end }}
1024 {{ define rss_author(struct template *tp, char *author) }}
1026 char *t, *mail;
1028 /* what to do if the author name contains a paren? */
1029 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1030 return 0;
1032 t = strchr(author, '<');
1033 if (t == NULL)
1034 return 0;
1035 *t = '\0';
1036 mail = t+1;
1038 while (isspace((unsigned char)*--t))
1039 *t = '\0';
1041 t = strchr(mail, '>');
1042 if (t == NULL)
1043 return 0;
1044 *t = '\0';
1046 <author>
1047 {{ mail }} {{" "}} ({{ author }})
1048 </author>
1049 {{ end }}