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 <sha2.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 const struct got_error *error;
246 struct request *c = tp->tp_arg;
247 struct server *srv = c->srv;
248 struct transport *t = c->t;
249 struct querystring *qs = c->t->qs;
250 struct repo_commit *rc;
251 struct repo_dir *repo_dir = t->repo_dir;
252 struct gotweb_url diff_url, tree_url;
253 char *tmp;
255 diff_url = (struct gotweb_url){
256 .action = DIFF,
257 .index_page = -1,
258 .page = -1,
259 .path = repo_dir->name,
260 .headref = qs->headref,
261 };
262 tree_url = (struct gotweb_url){
263 .action = TREE,
264 .index_page = -1,
265 .page = -1,
266 .path = repo_dir->name,
267 .headref = qs->headref,
268 };
270 if (qs->action == SUMMARY) {
271 qs->action = BRIEFS;
272 error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
273 } else
274 error = got_get_repo_commits(c, srv->max_commits_display);
275 if (error)
276 return -1;
277 !}
278 <div id="briefs_title_wrapper">
279 <div id="briefs_title">Commit Briefs</div>
280 </div>
281 <div id="briefs_content">
282 {{ tailq-foreach rc &t->repo_commits entry }}
283 {!
284 diff_url.commit = rc->commit_id;
285 tree_url.commit = rc->commit_id;
287 tmp = strchr(rc->committer, '<');
288 if (tmp)
289 *tmp = '\0';
291 tmp = strchr(rc->commit_msg, '\n');
292 if (tmp)
293 *tmp = '\0';
294 !}
295 <div class="briefs_age">
296 {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
297 </div>
298 <div class="briefs_author">
299 {{ rc->committer }}
300 </div>
301 <div class="briefs_log">
302 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
303 {{ rc->commit_msg }}
304 </a>
305 {{ if rc->refs_str }}
306 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
307 {{ end }}
308 </a>
309 </div>
310 <div class="navs_wrapper">
311 <div class="navs">
312 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
313 {{ " | " }}
314 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
315 </div>
316 </div>
317 <div class="dotted_line"></div>
318 {{ end }}
319 {{ render gotweb_render_more(tp, BRIEFS) }}
320 </div>
321 {{ end }}
323 {{ define gotweb_render_more(struct template *tp, int action) }}
324 {!
325 struct request *c = tp->tp_arg;
326 struct transport *t = c->t;
327 struct querystring *qs = t->qs;
328 struct gotweb_url more = {
329 .action = action,
330 .index_page = -1,
331 .path = qs->path,
332 .commit = t->more_id,
333 .headref = qs->headref,
334 };
335 !}
336 {{ if t->more_id }}
337 <div id="np_wrapper">
338 <div id="nav_more">
339 <a href="{{ render gotweb_render_url(c, &more) }}">
340 More&nbsp;&darr;
341 </a>
342 </div>
343 </div>
344 {{ end }}
345 {{ end }}
347 {{ define gotweb_render_navs(struct template *tp) }}
348 {!
349 struct request *c = tp->tp_arg;
350 struct transport *t = c->t;
351 struct gotweb_url prev, next;
352 int have_prev, have_next;
354 gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
355 !}
356 <div id="np_wrapper">
357 <div id="nav_prev">
358 {{ if have_prev }}
359 <a href="{{ render gotweb_render_url(c, &prev) }}">
360 Previous
361 </a>
362 {{ end }}
363 </div>
364 <div id="nav_next">
365 {{ if have_next }}
366 <a href="{{ render gotweb_render_url(c, &next) }}">
367 Next
368 </a>
369 {{ end }}
370 </div>
371 </div>
372 {{ finally }}
373 {!
374 free(t->next_id);
375 t->next_id = NULL;
376 free(t->prev_id);
377 t->prev_id = NULL;
378 !}
379 {{ end }}
381 {{ define gotweb_render_commits(struct template *tp) }}
382 {!
383 struct request *c = tp->tp_arg;
384 struct transport *t = c->t;
385 struct repo_dir *repo_dir = t->repo_dir;
386 struct repo_commit *rc;
387 struct gotweb_url diff, tree;
389 diff = (struct gotweb_url){
390 .action = DIFF,
391 .index_page = -1,
392 .page = -1,
393 .path = repo_dir->name,
394 };
395 tree = (struct gotweb_url){
396 .action = TREE,
397 .index_page = -1,
398 .page = -1,
399 .path = repo_dir->name,
400 };
401 !}
402 <div class="commits_title_wrapper">
403 <div class="commits_title">Commits</div>
404 </div>
405 <div class="commits_content">
406 {{ tailq-foreach rc &t->repo_commits entry }}
407 {!
408 diff.commit = rc->commit_id;
409 tree.commit = rc->commit_id;
410 !}
411 <div class="commits_header_wrapper">
412 <div class="commits_header">
413 <div class="header_commit_title">Commit:</div>
414 <div class="header_commit">{{ rc->commit_id }}</div>
415 <div class="header_author_title">From:</div>
416 <div class="header_author">{{ rc->author }}</div>
417 {{ if strcmp(rc->committer, rc->author) != 0 }}
418 <div class="header_author_title">Via:</div>
419 <div class="header_author">{{ rc->committer }}</div>
420 {{ end }}
421 <div class="header_age_title">Date:</div>
422 <div class="header_age">
423 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
424 </div>
425 </div>
426 </div>
427 <div class="dotted_line"></div>
428 <div class="commit">
429 {{ "\n" }}
430 {{ rc->commit_msg }}
431 </div>
432 <div class="navs_wrapper">
433 <div class="navs">
434 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
435 {{ " | " }}
436 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
437 </div>
438 </div>
439 <div class="dotted_line"></div>
440 {{ end }}
441 {{ render gotweb_render_more(tp, COMMITS) }}
442 </div>
443 {{ end }}
445 {{ define gotweb_render_blob(struct template *tp) }}
446 {!
447 struct request *c = tp->tp_arg;
448 struct transport *t = c->t;
449 struct got_blob_object *blob = t->blob;
450 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
451 !}
452 <div id="blob_title_wrapper">
453 <div id="blob_title">Blob</div>
454 </div>
455 <div id="blob_content">
456 <div id="blob_header_wrapper">
457 <div id="blob_header">
458 <div class="header_age_title">Date:</div>
459 <div class="header_age">
460 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
461 </div>
462 <div id="header_commit_msg_title">Message:</div>
463 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
464 </div>
465 </div>
466 <div class="dotted_line"></div>
467 <div id="blob">
468 <pre>
469 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
470 </pre>
471 </div>
472 </div>
473 {{ end }}
475 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
476 size_t no) }}
477 {!
478 char lineno[16];
479 int r;
481 r = snprintf(lineno, sizeof(lineno), "%zu", no);
482 if (r < 0 || (size_t)r >= sizeof(lineno))
483 return -1;
484 !}
485 <div class="blob_line" id="line{{ lineno }}">
486 <div class="blob_number">
487 <a href="#line{{ lineno }}">{{ lineno }}</a>
488 </div>
489 <div class="blob_code">{{ line }}</div>
490 </div>
491 {{ end }}
493 {{ define gotweb_render_tree(struct template *tp) }}
494 {!
495 struct request *c = tp->tp_arg;
496 struct transport *t = c->t;
497 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
498 !}
499 <div id="tree_title_wrapper">
500 <div id="tree_title">Tree</div>
501 </div>
502 <div id="tree_content">
503 <div id="tree_header_wrapper">
504 <div id="tree_header">
505 <div id="header_tree_title">Tree:</div>
506 <div id="header_tree">{{ rc->tree_id }}</div>
507 <div class="header_age_title">Date:</div>
508 <div class="header_age">
509 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
510 </div>
511 <div id="header_commit_msg_title">Message:</div>
512 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
513 </div>
514 </div>
515 <div class="dotted_line"></div>
516 <div id="tree">
517 {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
518 </div>
519 </div>
520 {{ end }}
522 {{ define gotweb_render_tree_item(struct template *tp,
523 struct got_tree_entry *te) }}
524 {!
525 struct request *c = tp->tp_arg;
526 struct transport *t = c->t;
527 struct querystring *qs = t->qs;
528 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
529 const char *modestr = "";
530 const char *name;
531 const char *folder;
532 char *dir = NULL;
533 mode_t mode;
534 struct gotweb_url url = {
535 .index_page = -1,
536 .page = -1,
537 .commit = rc->commit_id,
538 .path = qs->path,
539 };
541 name = got_tree_entry_get_name(te);
542 mode = got_tree_entry_get_mode(te);
544 folder = qs->folder ? qs->folder : "";
545 if (S_ISDIR(mode)) {
546 if (asprintf(&dir, "%s/%s", folder, name) == -1)
547 return (-1);
549 url.action = TREE;
550 url.folder = dir;
551 } else {
552 url.action = BLOB;
553 url.folder = folder;
554 url.file = name;
557 if (got_object_tree_entry_is_submodule(te))
558 modestr = "$";
559 else if (S_ISLNK(mode))
560 modestr = "@";
561 else if (S_ISDIR(mode))
562 modestr = "/";
563 else if (mode & S_IXUSR)
564 modestr = "*";
565 !}
566 <div class="tree_wrapper">
567 {{ if S_ISDIR(mode) }}
568 <div class="tree_line">
569 <a href="{{ render gotweb_render_url(c, &url) }}">
570 {{ name }}{{ modestr }}
571 </a>
572 </div>
573 <div class="tree_line_blank">&nbsp;</div>
574 {{ else }}
575 <div class="tree_line">
576 <a href="{{ render gotweb_render_url(c, &url) }}">
577 {{ name }}{{ modestr }}
578 </a>
579 </div>
580 <div class="tree_line_blank">
581 {! url.action = COMMITS; !}
582 <a href="{{ render gotweb_render_url(c, &url) }}">
583 commits
584 </a>
585 {{ " | " }}
586 {! url.action = BLAME; !}
587 <a href="{{ render gotweb_render_url(c, &url) }}">
588 blame
589 </a>
590 </div>
591 {{ end }}
592 </div>
593 {{ finally }}
594 {!
595 free(dir);
596 !}
597 {{ end }}
599 {{ define gotweb_render_tags(struct template *tp) }}
600 {!
601 struct request *c = tp->tp_arg;
602 struct transport *t = c->t;
603 struct querystring *qs = t->qs;
604 struct repo_tag *rt;
605 int commit_found;
607 commit_found = qs->commit == NULL;
608 !}
609 <div id="tags_title_wrapper">
610 <div id="tags_title">Tags</div>
611 </div>
612 <div id="tags_content">
613 {{ if t->tag_count == 0 }}
614 <div id="err_content">
615 This repository contains no tags
616 </div>
617 {{ else }}
618 {{ tailq-foreach rt &t->repo_tags entry }}
619 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
620 {! commit_found = 1; !}
621 {{ render tag_item(tp, rt) }}
622 {{ end }}
623 {{ end }}
624 {{ if t->next_id || t->prev_id }}
625 {! qs->action = TAGS; !}
626 {{ render gotweb_render_navs(tp) }}
627 {{ end }}
628 {{ end }}
629 </div>
630 {{ end }}
632 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
633 {!
634 struct request *c = tp->tp_arg;
635 struct transport *t = c->t;
636 struct repo_dir *repo_dir = t->repo_dir;
637 char *tag_name = rt->tag_name;
638 char *msg = rt->tag_commit;
639 char *nl;
640 struct gotweb_url url = {
641 .action = TAG,
642 .index_page = -1,
643 .page = -1,
644 .path = repo_dir->name,
645 .commit = rt->commit_id,
646 };
648 if (strncmp(tag_name, "refs/tags/", 10) == 0)
649 tag_name += 10;
651 if (msg) {
652 nl = strchr(msg, '\n');
653 if (nl)
654 *nl = '\0';
656 !}
657 <div class="tag_age">
658 {{ render gotweb_render_age(tp, rt->tagger_time, TM_DIFF) }}
659 </div>
660 <div class="tag">{{ tag_name }}</div>
661 <div class="tag_log">
662 <a href="{{ render gotweb_render_url(c, &url) }}">
663 {{ msg }}
664 </a>
665 </div>
666 <div class="navs_wrapper">
667 <div class="navs">
668 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
669 {{ " | " }}
670 {! url.action = BRIEFS; !}
671 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
672 {{ " | " }}
673 {! url.action = COMMITS; !}
674 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
675 </div>
676 </div>
677 <div class="dotted_line"></div>
678 {{ end }}
680 {{ define gotweb_render_tag(struct template *tp) }}
681 {!
682 struct request *c = tp->tp_arg;
683 struct transport *t = c->t;
684 struct repo_tag *rt;
685 const char *tag_name;
687 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
688 tag_name = rt->tag_name;
690 if (strncmp(tag_name, "refs/", 5) == 0)
691 tag_name += 5;
692 !}
693 <div id="tags_title_wrapper">
694 <div id="tags_title">Tag</div>
695 </div>
696 <div id="tags_content">
697 <div id="tag_header_wrapper">
698 <div id="tag_header">
699 <div class="header_commit_title">Commit:</div>
700 <div class="header_commit">
701 {{ rt->commit_id }}
702 {{ " " }}
703 <span class="refs_str">({{ tag_name }})</span>
704 </div>
705 <div class="header_author_title">Tagger:</div>
706 <div class="header_author">{{ rt->tagger }}</div>
707 <div class="header_age_title">Date:</div>
708 <div class="header_age">
709 {{ render gotweb_render_age(tp, rt->tagger_time, TM_LONG)}}
710 </div>
711 <div id="header_commit_msg_title">Message:</div>
712 <div id="header_commit_msg">{{ rt->commit_msg }}</div>
713 </div>
714 <div class="dotted_line"></div>
715 <div id="tag_commit">
716 {{ "\n" }}
717 {{ rt->tag_commit }}
718 </div>
719 </div>
720 </div>
721 {{ end }}
723 {{ define gotweb_render_diff(struct template *tp) }}
724 {!
725 struct request *c = tp->tp_arg;
726 struct transport *t = c->t;
727 FILE *fp = t->fp;
728 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
729 char *line = NULL;
730 size_t linesize = 0;
731 ssize_t linelen;
732 !}
733 <div id="diff_title_wrapper">
734 <div id="diff_title">Commit Diff</div>
735 </div>
736 <div id="diff_content">
737 <div id="diff_header_wrapper">
738 <div id="diff_header">
739 <div class="header_commit_title">Commit:</div>
740 <div class="header_commit">{{ rc->commit_id }}</div>
741 <div class="header_author_title">From:</div>
742 <div class="header_author">{{ rc->author }}</div>
743 {{ if strcmp(rc->committer, rc->author) != 0 }}
744 <div class="header_author_title">Via:</div>
745 <div class="header_author">{{ rc->committer }}</div>
746 {{ end }}
747 <div class="header_age_title">Date:</div>
748 <div class="header_age">
749 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
750 </div>
751 <div id="header_commit_msg_title">Message:</div>
752 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
753 </div>
754 </div>
755 <div class="dotted_line"></div>
756 <div id="diff">
757 {{ "\n" }}
758 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
759 {{ render diff_line(tp, line) }}
760 {{ end }}
761 </div>
762 </div>
763 {{ finally }}
764 {! free(line); !}
765 {{ end }}
767 {{ define diff_line(struct template *tp, char *line )}}
768 {!
769 const char *color = NULL;
770 char *nl;
772 if (!strncmp(line, "-", 1))
773 color = "diff_minus";
774 else if (!strncmp(line, "+", 1))
775 color = "diff_plus";
776 else if (!strncmp(line, "@@", 2))
777 color = "diff_chunk_header";
778 else if (!strncmp(line, "commit +", 8) ||
779 !strncmp(line, "commit -", 8) ||
780 !strncmp(line, "blob +", 6) ||
781 !strncmp(line, "blob -", 6) ||
782 !strncmp(line, "file +", 6) ||
783 !strncmp(line, "file -", 6))
784 color = "diff_meta";
785 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
786 color = "diff_author";
787 else if (!strncmp(line, "date:", 5))
788 color = "diff_date";
790 nl = strchr(line, '\n');
791 if (nl)
792 *nl = '\0';
793 !}
794 <div class="diff_line {{ color }}">{{ line }}</div>
795 {{ end }}
797 {{ define gotweb_render_branches(struct template *tp,
798 struct got_reflist_head *refs) }}
799 {!
800 struct got_reflist_entry *re;
801 !}
802 <div id="branches_title_wrapper">
803 <div id="branches_title">Branches</div>
804 </div>
805 <div id="branches_content">
806 {{ tailq-foreach re refs entry }}
807 {{ if !got_ref_is_symbolic(re->ref) }}
808 {{ render branch(tp, re) }}
809 {{ end }}
810 {{ end }}
811 </div>
812 {{ end }}
814 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
815 {!
816 const struct got_error *err;
817 struct request *c = tp->tp_arg;
818 struct querystring *qs = c->t->qs;
819 const char *refname;
820 time_t age;
821 struct gotweb_url url = {
822 .action = SUMMARY,
823 .index_page = -1,
824 .page = -1,
825 .path = qs->path,
826 };
828 refname = got_ref_get_name(re->ref);
830 err = got_get_repo_age(&age, c, refname);
831 if (err) {
832 log_warnx("%s: %s", __func__, err->msg);
833 return -1;
836 if (strncmp(refname, "refs/heads/", 11) == 0)
837 refname += 11;
839 url.headref = refname;
840 !}
841 <div class="branches_wrapper">
842 <div class="branches_age">
843 {{ render gotweb_render_age(tp, age, TM_DIFF) }}
844 </div>
845 <div class="branches_space">&nbsp;</div>
846 <div class="branch">
847 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
848 </div>
849 <div class="navs_wrapper">
850 <div class="navs">
851 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
852 {{" | "}}
853 {! url.action = BRIEFS; !}
854 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
855 {{" | "}}
856 {! url.action = COMMITS; !}
857 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
858 </div>
859 </div>
860 <div class="dotted_line"></div>
861 </div>
862 {{ end }}
864 {{ define gotweb_render_summary(struct template *tp) }}
865 {!
866 struct request *c = tp->tp_arg;
867 struct server *srv = c->srv;
868 struct transport *t = c->t;
869 struct got_reflist_head *refs = &t->refs;
870 !}
871 <div id="summary_wrapper">
872 {{ if srv->show_repo_description }}
873 <div id="description_title">Description:</div>
874 <div id="description">{{ t->repo_dir->description }}</div>
875 {{ end }}
876 {{ if srv->show_repo_owner }}
877 <div id="repo_owner_title">Owner:</div>
878 <div id="repo_owner">{{ t->repo_dir->owner }}</div>
879 {{ end }}
880 {{ if srv->show_repo_age }}
881 <div id="last_change_title">Last Change:</div>
882 <div id="last_change">
883 {{ render gotweb_render_age(tp, t->repo_dir->age, TM_DIFF) }}
884 </div>
885 {{ end }}
886 {{ if srv->show_repo_cloneurl }}
887 <div id="cloneurl_title">Clone URL:</div>
888 <div id="cloneurl">{{ t->repo_dir->url }}</div>
889 {{ end }}
890 </div>
891 {{ render gotweb_render_briefs(tp) }}
892 {{ render gotweb_render_tags(tp) }}
893 {{ render gotweb_render_branches(tp, refs) }}
894 {{ end }}
896 {{ define gotweb_render_blame(struct template *tp) }}
897 {!
898 const struct got_error *err;
899 struct request *c = tp->tp_arg;
900 struct transport *t = c->t;
901 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
902 !}
903 <div id="blame_title_wrapper">
904 <div id="blame_title">Blame</div>
905 </div>
906 <div id="blame_content">
907 <div id="blame_header_wrapper">
908 <div id="blame_header">
909 <div class="header_age_title">Date:</div>
910 <div class="header_age">
911 {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
912 </div>
913 <div id="header_commit_msg_title">Message:</div>
914 <div id="header_commit_msg">{{ rc->commit_msg }}</div>
915 </div>
916 </div>
917 <div class="dotted_line"></div>
918 <div id="blame">
919 {{ "\n" }}
920 {!
921 err = got_output_file_blame(c, &blame_line);
922 if (err) {
923 log_warnx("%s: got_output_file_blame: %s", __func__,
924 err->msg);
925 return (-1);
927 !}
928 </div>
929 </div>
930 {{ end }}
932 {{ define blame_line(struct template *tp, const char *line,
933 struct blame_line *bline, int lprec, int lcur) }}
934 {!
935 struct request *c = tp->tp_arg;
936 struct transport *t = c->t;
937 struct repo_dir *repo_dir = t->repo_dir;
938 char *committer, *s;
939 struct gotweb_url url = {
940 .action = DIFF,
941 .index_page = -1,
942 .page = -1,
943 .path = repo_dir->name,
944 .commit = bline->id_str,
945 };
947 s = strchr(bline->committer, '<');
948 committer = s ? s + 1 : bline->committer;
950 s = strchr(committer, '@');
951 if (s)
952 *s = '\0';
953 !}
954 <div class="blame_wrapper">
955 <div class="blame_number">{{ printf "%.*d", lprec, lcur }}</div>
956 <div class="blame_hash">
957 <a href="{{ render gotweb_render_url(c, &url) }}">
958 {{ printf "%.8s", bline->id_str }}
959 </a>
960 </div>
961 <div class="blame_date">{{ bline->datebuf }}</div>
962 <div class="blame_author">{{ printf "%.9s", committer }}</div>
963 <div class="blame_code">{{ line }}</div>
964 </div>
965 {{ end }}
967 {{ define gotweb_render_rss(struct template *tp) }}
968 {!
969 struct request *c = tp->tp_arg;
970 struct server *srv = c->srv;
971 struct transport *t = c->t;
972 struct repo_dir *repo_dir = t->repo_dir;
973 struct repo_tag *rt;
974 struct gotweb_url summary = {
975 .action = SUMMARY,
976 .index_page = -1,
977 .page = -1,
978 .path = repo_dir->name,
979 };
980 !}
981 <?xml version="1.0" encoding="UTF-8"?>
982 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
983 <channel>
984 <title>Tags of {{ repo_dir->name }}</title>
985 <link>
986 <![CDATA[
987 {{ render gotweb_render_absolute_url(c, &summary) }}
988 ]]>
989 </link>
990 {{ if srv->show_repo_description }}
991 <description>{{ repo_dir->description }}</description>
992 {{ end }}
993 {{ tailq-foreach rt &t->repo_tags entry }}
994 {{ render rss_tag_item(tp, rt) }}
995 {{ end }}
996 </channel>
997 </rss>
998 {{ end }}
1000 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1002 struct request *c = tp->tp_arg;
1003 struct transport *t = c->t;
1004 struct repo_dir *repo_dir = t->repo_dir;
1005 char *tag_name = rt->tag_name;
1006 struct gotweb_url tag = {
1007 .action = TAG,
1008 .index_page = -1,
1009 .page = -1,
1010 .path = repo_dir->name,
1011 .commit = rt->commit_id,
1014 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1015 tag_name += 10;
1017 <item>
1018 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1019 <link>
1020 <![CDATA[
1021 {{ render gotweb_render_absolute_url(c, &tag) }}
1022 ]]>
1023 </link>
1024 <description>
1025 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1026 </description>
1027 {{ render rss_author(tp, rt->tagger) }}
1028 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1029 <pubDate>
1030 {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
1031 </pubDate>
1032 </item>
1033 {{ end }}
1035 {{ define rss_author(struct template *tp, char *author) }}
1037 char *t, *mail;
1039 /* what to do if the author name contains a paren? */
1040 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1041 return 0;
1043 t = strchr(author, '<');
1044 if (t == NULL)
1045 return 0;
1046 *t = '\0';
1047 mail = t+1;
1049 while (isspace((unsigned char)*--t))
1050 *t = '\0';
1052 t = strchr(mail, '>');
1053 if (t == NULL)
1054 return 0;
1055 *t = '\0';
1057 <author>
1058 {{ mail }} {{" "}} ({{ author }})
1059 </author>
1060 {{ end }}