3 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
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.
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.
19 #include <sys/types.h>
20 #include <sys/queue.h>
33 #include "got_error.h"
34 #include "got_object.h"
35 #include "got_reference.h"
45 static int breadcumbs(struct template *);
46 static int datetime(struct template *, time_t, int);
47 static int gotweb_render_blob_line(struct template *, const char *, size_t);
48 static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
49 static int blame_line(struct template *, const char *, struct blame_line *,
52 static inline int gotweb_render_more(struct template *, int);
54 static inline int diff_line(struct template *, char *);
55 static inline int tag_item(struct template *, struct repo_tag *);
56 static inline int branch(struct template *, struct got_reflist_entry *);
57 static inline int rss_tag_item(struct template *, struct repo_tag *);
58 static inline int rss_author(struct template *, char *);
61 nextsep(char *s, char **t)
79 {{ define datetime(struct template *tp, time_t t, int fmt) }}
85 if (gmtime_r(&t, &tm) == NULL)
88 if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
91 if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
94 <time datetime="{{ rfc3339 }}">
95 {{ if fmt == TM_DIFF }}
96 {{ render gotweb_render_age(tp, t) }}
98 {{ datebuf }} {{ " UTC" }}
103 {{ define breadcumbs(struct template *tp) }}
105 struct request *c = tp->tp_arg;
106 struct querystring *qs = c->t->qs;
107 struct gotweb_url url;
108 const char *folder = qs->folder;
109 char *t, *s = NULL, *dir = NULL;
112 memset(&url, 0, sizeof(url));
117 url.commit = qs->commit;
119 if (folder && *folder != '\0') {
120 while (*folder == '/')
122 dir = strdup(folder);
129 <a href="{{ render gotweb_render_url(c, &url) }}">tree</a>
132 {{ while (s = nextsep(s, &t)) != NULL }}
139 <a href="{{ render gotweb_render_url(c, &url) }}">
156 {{ define gotweb_render_page(struct template *tp,
157 int (*body)(struct template *)) }}
159 struct request *c = tp->tp_arg;
160 struct server *srv = c->srv;
161 struct querystring *qs = c->t->qs;
162 struct gotweb_url u_path;
163 const char *prfx = c->document_uri;
164 const char *css = srv->custom_css;
166 memset(&u_path, 0, sizeof(u_path));
167 u_path.index_page = -1;
169 u_path.action = SUMMARY;
174 <meta charset="utf-8" />
175 <title>{{ srv->site_name }}</title>
176 <meta name="viewport" content="initial-scale=1.0" />
177 <meta name="msapplication-TileColor" content="#da532c" />
178 <meta name="theme-color" content="#ffffff"/>
179 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
180 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
181 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
182 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
183 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
184 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
189 <a href="{{ srv->logo_url }}" target="_blank">
190 <img src="{{ prfx }}{{ srv->logo }}" />
196 <a href="?index_page={{ printf "%d", qs->index_page }}">
200 {! u_path.path = qs->path; !}
202 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
206 {{ if qs->action == TREE || qs->action == BLOB }}
207 {{ render breadcumbs(tp) }}
208 {{ else if qs->action != INDEX }}
209 {{ " / " }}{{ gotweb_action_name(qs->action) }}
214 {{ render body(tp) }}
216 <footer id="site_owner_wrapper">
218 {{ if srv->show_site_owner }}
219 {{ srv->site_owner }}
227 {{ define gotweb_render_error(struct template *tp) }}
229 struct request *c = tp->tp_arg;
230 struct transport *t = c->t;
232 <div id="err_content">
236 See daemon logs for details
241 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
243 struct request *c = tp->tp_arg;
244 struct server *srv = c->srv;
246 <div id="index_header">
247 <div class="index_project">
250 {{ if srv->show_repo_description }}
251 <div class="index_project_description">
255 {{ if srv->show_repo_owner }}
256 <div class="index_project_owner">
260 {{ if srv->show_repo_age }}
261 <div class="index_project_age">
268 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
270 struct request *c = tp->tp_arg;
271 struct server *srv = c->srv;
272 struct gotweb_url summary = {
276 .path = repo_dir->name,
281 .path = repo_dir->name,
286 .path = repo_dir->name,
291 .path = repo_dir->name,
296 .path = repo_dir->name,
301 .path = repo_dir->name,
304 <div class="index_wrapper">
305 <div class="index_project">
306 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
308 {{ if srv->show_repo_description }}
309 <div class="index_project_description">
310 {{ repo_dir->description }}
313 {{ if srv->show_repo_owner }}
314 <div class="index_project_owner">
315 {{ repo_dir->owner }}
318 {{ if srv->show_repo_age }}
319 <div class="index_project_age">
320 {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
323 <div class="navs_wrapper">
325 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
327 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
329 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
331 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
333 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
335 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
342 {{ define gotweb_render_briefs(struct template *tp) }}
344 struct request *c = tp->tp_arg;
345 struct transport *t = c->t;
346 struct querystring *qs = c->t->qs;
347 struct repo_commit *rc;
348 struct repo_dir *repo_dir = t->repo_dir;
349 struct gotweb_url diff_url, patch_url, tree_url;
352 diff_url = (struct gotweb_url){
356 .path = repo_dir->name,
357 .headref = qs->headref,
359 patch_url = (struct gotweb_url){
363 .path = repo_dir->name,
364 .headref = qs->headref,
366 tree_url = (struct gotweb_url){
370 .path = repo_dir->name,
371 .headref = qs->headref,
374 <header class='subtitle'>
375 <h2>Commit Briefs</h2>
377 <div id="briefs_content">
378 {{ tailq-foreach rc &t->repo_commits entry }}
380 diff_url.commit = rc->commit_id;
381 patch_url.commit = rc->commit_id;
382 tree_url.commit = rc->commit_id;
384 tmp = strchr(rc->committer, '<');
388 tmp = strchr(rc->commit_msg, '\n');
393 <p class='brief_meta'>
394 <span class='briefs_age'>
395 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
398 <span class="briefs_author">
402 <p class="briefs_log">
403 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
406 {{ if rc->refs_str }}
407 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
412 <div class="navs_wrapper">
414 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
416 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
418 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
423 {{ render gotweb_render_more(tp, BRIEFS) }}
427 {{ define gotweb_render_more(struct template *tp, int action) }}
429 struct request *c = tp->tp_arg;
430 struct transport *t = c->t;
431 struct querystring *qs = t->qs;
432 struct gotweb_url more = {
436 .commit = t->more_id,
437 .headref = qs->headref,
442 <div id="np_wrapper">
444 <a href="{{ render gotweb_render_url(c, &more) }}">
452 {{ define gotweb_render_navs(struct template *tp) }}
454 struct request *c = tp->tp_arg;
455 struct transport *t = c->t;
456 struct gotweb_url prev, next;
457 int have_prev, have_next;
459 gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
461 <div id="np_wrapper">
464 <a href="{{ render gotweb_render_url(c, &prev) }}">
471 <a href="{{ render gotweb_render_url(c, &next) }}">
486 {{ define gotweb_render_commits(struct template *tp) }}
488 struct request *c = tp->tp_arg;
489 struct transport *t = c->t;
490 struct repo_dir *repo_dir = t->repo_dir;
491 struct repo_commit *rc;
492 struct gotweb_url diff, patch, tree;
494 diff = (struct gotweb_url){
498 .path = repo_dir->name,
500 patch = (struct gotweb_url){
504 .path = repo_dir->name,
506 tree = (struct gotweb_url){
510 .path = repo_dir->name,
513 <header class="subtitle">
516 <div class="commits_content">
517 {{ tailq-foreach rc &t->repo_commits entry }}
519 diff.commit = rc->commit_id;
520 patch.commit = rc->commit_id;
521 tree.commit = rc->commit_id;
523 <div class="page_header_wrapper">
526 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
528 <dd>{{ rc->author }}</dd>
529 {{ if strcmp(rc->committer, rc->author) != 0 }}
531 <dd>{{ rc->committer }}</dd>
535 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
544 <div class="navs_wrapper">
546 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
548 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
550 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
555 {{ render gotweb_render_more(tp, COMMITS) }}
559 {{ define gotweb_render_blob(struct template *tp) }}
561 struct request *c = tp->tp_arg;
562 struct transport *t = c->t;
563 struct querystring *qs = t->qs;
564 struct got_blob_object *blob = t->blob;
565 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
566 struct gotweb_url briefs_url, blame_url, raw_url;
568 memset(&briefs_url, 0, sizeof(briefs_url));
569 briefs_url.index_page = -1,
570 briefs_url.page = -1,
571 briefs_url.action = BRIEFS,
572 briefs_url.path = qs->path,
573 briefs_url.commit = qs->commit,
574 briefs_url.folder = qs->folder,
575 briefs_url.file = qs->file,
577 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
578 blame_url.action = BLAME;
580 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
581 raw_url.action = BLOBRAW;
583 <header class="subtitle">
586 <div id="blob_content">
587 <div class="page_header_wrapper">
591 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
594 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
597 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
601 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
605 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
614 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
620 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
626 r = snprintf(lineno, sizeof(lineno), "%zu", no);
627 if (r < 0 || (size_t)r >= sizeof(lineno))
630 <div class="blob_line" id="line{{ lineno }}">
631 <a href="#line{{ lineno }}">{{ lineno }}</a>
633 <span class="blob_code">{{ line }}</span>
637 {{ define gotweb_render_tree(struct template *tp) }}
639 struct request *c = tp->tp_arg;
640 struct transport *t = c->t;
641 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
643 <header class='subtitle'>
646 <div id="tree_content">
647 <div class="page_header_wrapper">
650 <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
653 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
656 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
661 {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
666 {{ define gotweb_render_tree_item(struct template *tp,
667 struct got_tree_entry *te) }}
669 struct request *c = tp->tp_arg;
670 struct transport *t = c->t;
671 struct querystring *qs = t->qs;
672 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
673 const char *modestr = "";
678 struct gotweb_url url = {
681 .commit = rc->commit_id,
685 name = got_tree_entry_get_name(te);
686 mode = got_tree_entry_get_mode(te);
688 folder = qs->folder ? qs->folder : "";
690 if (asprintf(&dir, "%s/%s", folder, name) == -1)
701 if (got_object_tree_entry_is_submodule(te))
703 else if (S_ISLNK(mode))
705 else if (S_ISDIR(mode))
707 else if (mode & S_IXUSR)
710 <tr class="tree_wrapper">
711 {{ if S_ISDIR(mode) }}
712 <td class="tree_line" colspan=2>
713 <a href="{{ render gotweb_render_url(c, &url) }}">
714 {{ name }}{{ modestr }}
718 <td class="tree_line">
719 <a href="{{ render gotweb_render_url(c, &url) }}">
720 {{ name }}{{ modestr }}
723 <td class="tree_line_blank">
724 {! url.action = COMMITS; !}
725 <a href="{{ render gotweb_render_url(c, &url) }}">
729 {! url.action = BLAME; !}
730 <a href="{{ render gotweb_render_url(c, &url) }}">
742 {{ define gotweb_render_tags(struct template *tp) }}
744 struct request *c = tp->tp_arg;
745 struct transport *t = c->t;
746 struct querystring *qs = t->qs;
750 commit_found = qs->commit == NULL;
752 <header class='subtitle'>
755 <div id="tags_content">
756 {{ if t->tag_count == 0 }}
757 <div id="err_content">
758 This repository contains no tags
761 {{ tailq-foreach rt &t->repo_tags entry }}
762 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
763 {! commit_found = 1; !}
764 {{ render tag_item(tp, rt) }}
767 {{ if t->next_id || t->prev_id }}
768 {! qs->action = TAGS; !}
769 {{ render gotweb_render_navs(tp) }}
775 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
777 struct request *c = tp->tp_arg;
778 struct transport *t = c->t;
779 struct repo_dir *repo_dir = t->repo_dir;
780 char *tag_name = rt->tag_name;
781 char *msg = rt->tag_commit;
783 struct gotweb_url url = {
787 .path = repo_dir->name,
788 .commit = rt->commit_id,
791 if (strncmp(tag_name, "refs/tags/", 10) == 0)
795 nl = strchr(msg, '\n');
800 <div class="tag_age">
801 {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
803 <div class="tag_name">{{ tag_name }}</div>
804 <div class="tag_log">
805 <a href="{{ render gotweb_render_url(c, &url) }}">
809 <div class="navs_wrapper">
811 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
813 {! url.action = BRIEFS; !}
814 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
816 {! url.action = COMMITS; !}
817 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
823 {{ define gotweb_render_tag(struct template *tp) }}
825 struct request *c = tp->tp_arg;
826 struct transport *t = c->t;
828 const char *tag_name;
830 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
831 tag_name = rt->tag_name;
833 if (strncmp(tag_name, "refs/", 5) == 0)
836 <header class="subtitle">
839 <div id="tags_content">
840 <div class="page_header_wrapper">
844 <code class="commit-id">{{ rt->commit_id }}</code>
846 <span class="refs_str">({{ tag_name }})</span>
849 <dd>{{ rt->tagger }}</dd>
852 {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
855 <dd class="commit-msg">{{ rt->commit_msg }}</dd>
858 <pre id="tag_commit">
865 {{ define gotweb_render_diff(struct template *tp) }}
867 struct request *c = tp->tp_arg;
868 struct transport *t = c->t;
869 struct querystring *qs = t->qs;
871 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
875 struct gotweb_url patch_url, tree_url = {
880 .commit = rc->commit_id,
883 memcpy(&patch_url, &tree_url, sizeof(patch_url));
884 patch_url.action = PATCH;
886 <header class="subtitle">
889 <div id="diff_content">
890 <div class="page_header_wrapper">
893 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
895 <dd>{{ rc->author }}</dd>
896 {{ if strcmp(rc->committer, rc->author) != 0 }}
898 <dd>{{ rc->committer }}</dd>
902 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
905 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
908 <a href="{{ render gotweb_render_url(c, &patch_url) }}">
912 <a href="{{ render gotweb_render_url(c, &tree_url) }}">
920 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
921 {{ render diff_line(tp, line) }}
929 {{ define diff_line(struct template *tp, char *line )}}
931 const char *color = NULL;
934 if (!strncmp(line, "-", 1))
935 color = "diff_minus";
936 else if (!strncmp(line, "+", 1))
938 else if (!strncmp(line, "@@", 2))
939 color = "diff_chunk_header";
940 else if (!strncmp(line, "commit +", 8) ||
941 !strncmp(line, "commit -", 8) ||
942 !strncmp(line, "blob +", 6) ||
943 !strncmp(line, "blob -", 6) ||
944 !strncmp(line, "file +", 6) ||
945 !strncmp(line, "file -", 6))
947 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
948 color = "diff_author";
949 else if (!strncmp(line, "date:", 5))
952 nl = strchr(line, '\n');
956 <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
959 {{ define gotweb_render_branches(struct template *tp,
960 struct got_reflist_head *refs) }}
962 struct got_reflist_entry *re;
964 <header class='subtitle'>
967 <div id="branches_content">
968 {{ tailq-foreach re refs entry }}
969 {{ if !got_ref_is_symbolic(re->ref) }}
970 {{ render branch(tp, re) }}
976 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
978 const struct got_error *err;
979 struct request *c = tp->tp_arg;
980 struct querystring *qs = c->t->qs;
983 struct gotweb_url url = {
990 refname = got_ref_get_name(re->ref);
992 err = got_get_repo_age(&age, c, refname);
994 log_warnx("%s: %s", __func__, err->msg);
998 if (strncmp(refname, "refs/heads/", 11) == 0)
1001 url.headref = refname;
1003 <section class="branches_wrapper">
1004 <div class="branches_age">
1005 {{ render datetime(tp, age, TM_DIFF) }}
1007 <div class="branch">
1008 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1010 <div class="navs_wrapper">
1012 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1014 {! url.action = BRIEFS; !}
1015 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1017 {! url.action = COMMITS; !}
1018 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1025 {{ define gotweb_render_summary(struct template *tp) }}
1027 struct request *c = tp->tp_arg;
1028 struct server *srv = c->srv;
1029 struct transport *t = c->t;
1030 struct got_reflist_head *refs = &t->refs;
1032 <dl id="summary_wrapper" class="page_header_wrapper">
1033 {{ if srv->show_repo_description }}
1034 <dt>Description:</dt>
1035 <dd>{{ t->repo_dir->description }}</dd>
1037 {{ if srv->show_repo_owner }}
1039 <dd>{{ t->repo_dir->owner }}</dd>
1041 {{ if srv->show_repo_age }}
1042 <dt>Last Change:</dt>
1044 {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1047 {{ if srv->show_repo_cloneurl }}
1049 <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1052 {{ render gotweb_render_briefs(tp) }}
1053 {{ render gotweb_render_tags(tp) }}
1054 {{ render gotweb_render_branches(tp, refs) }}
1057 {{ define gotweb_render_blame(struct template *tp) }}
1059 const struct got_error *err;
1060 struct request *c = tp->tp_arg;
1061 struct transport *t = c->t;
1062 struct querystring *qs = t->qs;
1063 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1064 struct gotweb_url briefs_url, blob_url, raw_url;
1066 memset(&briefs_url, 0, sizeof(briefs_url));
1067 briefs_url.index_page = -1,
1068 briefs_url.page = -1,
1069 briefs_url.action = BRIEFS,
1070 briefs_url.path = qs->path,
1071 briefs_url.commit = qs->commit,
1072 briefs_url.folder = qs->folder,
1073 briefs_url.file = qs->file,
1075 memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1076 blob_url.action = BLOB;
1078 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1079 raw_url.action = BLOBRAW;
1081 <header class="subtitle">
1084 <div id="blame_content">
1085 <div class="page_header_wrapper">
1089 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1092 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1095 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1099 <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1103 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1112 err = got_output_file_blame(c, &blame_line);
1113 if (err && err->code != GOT_ERR_CANCELLED)
1114 log_warnx("%s: got_output_file_blame: %s", __func__,
1123 {{ define blame_line(struct template *tp, const char *line,
1124 struct blame_line *bline, int lprec, int lcur) }}
1126 struct request *c = tp->tp_arg;
1127 struct transport *t = c->t;
1128 struct repo_dir *repo_dir = t->repo_dir;
1129 char *committer, *s;
1130 struct gotweb_url url = {
1134 .path = repo_dir->name,
1135 .commit = bline->id_str,
1138 s = strchr(bline->committer, '<');
1139 committer = s ? s + 1 : bline->committer;
1141 s = strchr(committer, '@');
1145 <div class="blame_line">
1146 <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1147 <span class="blame_hash">
1148 <a href="{{ render gotweb_render_url(c, &url) }}">
1149 {{ printf "%.8s", bline->id_str }}
1153 <span class="blame_date">{{ bline->datebuf }}</span>
1155 <span class="blame_author">{{ printf "%.9s", committer }}</span>
1157 <span class="blame_code">{{ line }}</span>
1161 {{ define gotweb_render_patch(struct template *tp) }}
1163 struct request *c = tp->tp_arg;
1164 struct transport *t = c->t;
1165 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1167 char buf[BUFSIZ], datebuf[64];
1170 if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1171 strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1174 commit {{ rc->commit_id }} {{ "\n" }}
1175 from: {{ rc->author | unsafe }} {{ "\n" }}
1176 {{ if strcmp(rc->committer, rc->author) != 0 }}
1177 via: {{ rc->committer | unsafe }} {{ "\n" }}
1179 date: {{ datebuf }} {{ "\n" }}
1181 {{ rc->commit_msg | unsafe }} {{ "\n" }}
1183 if (template_flush(tp) == -1)
1186 r = fread(buf, 1, sizeof(buf), t->fp);
1187 if (fcgi_write(c, buf, r) == -1 ||
1194 {{ define gotweb_render_rss(struct template *tp) }}
1196 struct request *c = tp->tp_arg;
1197 struct server *srv = c->srv;
1198 struct transport *t = c->t;
1199 struct repo_dir *repo_dir = t->repo_dir;
1200 struct repo_tag *rt;
1201 struct gotweb_url summary = {
1205 .path = repo_dir->name,
1208 <?xml version="1.0" encoding="UTF-8"?>
1209 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1211 <title>Tags of {{ repo_dir->name }}</title>
1214 {{ render gotweb_render_absolute_url(c, &summary) }}
1217 {{ if srv->show_repo_description }}
1218 <description>{{ repo_dir->description }}</description>
1220 {{ tailq-foreach rt &t->repo_tags entry }}
1221 {{ render rss_tag_item(tp, rt) }}
1227 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1229 struct request *c = tp->tp_arg;
1230 struct transport *t = c->t;
1231 struct repo_dir *repo_dir = t->repo_dir;
1235 char *tag_name = rt->tag_name;
1236 struct gotweb_url tag = {
1240 .path = repo_dir->name,
1241 .commit = rt->commit_id,
1244 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1247 if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1249 r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1254 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1257 {{ render gotweb_render_absolute_url(c, &tag) }}
1261 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1263 {{ render rss_author(tp, rt->tagger) }}
1264 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1271 {{ define rss_author(struct template *tp, char *author) }}
1275 /* what to do if the author name contains a paren? */
1276 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1279 t = strchr(author, '<');
1285 while (isspace((unsigned char)*--t))
1288 t = strchr(mail, '>');
1294 {{ mail }} {{" "}} ({{ author }})