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 "got_compat.h"
21 #include <sys/types.h>
22 #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 const char *action = "tree";
110 char *t, *s = NULL, *dir = NULL;
113 memset(&url, 0, sizeof(url));
118 url.commit = qs->commit;
120 if (qs->action != TREE && qs->action != BLOB) {
121 action = gotweb_action_name(qs->action);
122 url.action = qs->action;
125 if (folder && *folder != '\0') {
126 while (*folder == '/')
128 dir = strdup(folder);
135 <a href="{{ render gotweb_render_url(c, &url) }}">{{ action }}</a>
138 {{ while (s = nextsep(s, &t)) != NULL }}
145 <a href="{{ render gotweb_render_url(c, &url) }}">
162 {{ define gotweb_render_page(struct template *tp,
163 int (*body)(struct template *)) }}
165 struct request *c = tp->tp_arg;
166 struct server *srv = c->srv;
167 struct querystring *qs = c->t->qs;
168 struct gotweb_url u_path;
169 const char *prfx = c->document_uri;
170 const char *css = srv->custom_css;
172 memset(&u_path, 0, sizeof(u_path));
173 u_path.index_page = -1;
175 u_path.action = SUMMARY;
180 <meta charset="utf-8" />
181 <title>{{ srv->site_name }}</title>
182 <meta name="viewport" content="initial-scale=1.0" />
183 <meta name="msapplication-TileColor" content="#da532c" />
184 <meta name="theme-color" content="#ffffff"/>
185 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
186 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
187 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
188 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
189 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
190 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
195 <a href="{{ srv->logo_url }}" target="_blank">
196 <img src="{{ prfx }}{{ srv->logo }}" />
202 <a href="?index_page={{ printf "%d", qs->index_page }}">
206 {! u_path.path = qs->path; !}
208 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
212 {{ if qs->action == SUMMARY || qs->action == DIFF ||
213 qs->action == TAG || qs->action == TAGS }}
214 {{ " / " }}{{ gotweb_action_name(qs->action) }}
215 {{ else if qs->action != INDEX}}
216 {{ render breadcumbs(tp) }}
221 {{ render body(tp) }}
223 <footer id="site_owner_wrapper">
225 {{ if srv->show_site_owner }}
226 {{ srv->site_owner }}
234 {{ define gotweb_render_error(struct template *tp) }}
236 struct request *c = tp->tp_arg;
237 struct transport *t = c->t;
239 <div id="err_content">
243 See daemon logs for details
248 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
250 struct request *c = tp->tp_arg;
251 struct server *srv = c->srv;
253 <div id="index_header">
254 <div class="index_project">
257 {{ if srv->show_repo_description }}
258 <div class="index_project_description">
262 {{ if srv->show_repo_owner }}
263 <div class="index_project_owner">
267 {{ if srv->show_repo_age }}
268 <div class="index_project_age">
275 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
277 struct request *c = tp->tp_arg;
278 struct server *srv = c->srv;
279 struct gotweb_url summary = {
283 .path = repo_dir->name,
288 .path = repo_dir->name,
293 .path = repo_dir->name,
298 .path = repo_dir->name,
303 .path = repo_dir->name,
308 .path = repo_dir->name,
311 <div class="index_wrapper">
312 <div class="index_project">
313 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
315 {{ if srv->show_repo_description }}
316 <div class="index_project_description">
317 {{ repo_dir->description }}
320 {{ if srv->show_repo_owner }}
321 <div class="index_project_owner">
322 {{ repo_dir->owner }}
325 {{ if srv->show_repo_age }}
326 <div class="index_project_age">
327 {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
330 <div class="navs_wrapper">
332 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
334 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
336 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
338 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
340 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
342 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
349 {{ define gotweb_render_briefs(struct template *tp) }}
351 struct request *c = tp->tp_arg;
352 struct transport *t = c->t;
353 struct querystring *qs = c->t->qs;
354 struct repo_commit *rc;
355 struct repo_dir *repo_dir = t->repo_dir;
356 struct gotweb_url diff_url, patch_url, tree_url;
359 diff_url = (struct gotweb_url){
363 .path = repo_dir->name,
364 .headref = qs->headref,
366 patch_url = (struct gotweb_url){
370 .path = repo_dir->name,
371 .headref = qs->headref,
373 tree_url = (struct gotweb_url){
377 .path = repo_dir->name,
378 .headref = qs->headref,
381 <header class='subtitle'>
382 <h2>Commit Briefs</h2>
384 <div id="briefs_content">
385 {{ tailq-foreach rc &t->repo_commits entry }}
387 diff_url.commit = rc->commit_id;
388 patch_url.commit = rc->commit_id;
389 tree_url.commit = rc->commit_id;
391 tmp = strchr(rc->committer, '<');
395 tmp = strchr(rc->commit_msg, '\n');
400 <p class='brief_meta'>
401 <span class='briefs_age'>
402 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
405 <span class="briefs_author">
409 <p class="briefs_log">
410 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
413 {{ if rc->refs_str }}
414 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
419 <div class="navs_wrapper">
421 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
423 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
425 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
430 {{ render gotweb_render_more(tp, BRIEFS) }}
434 {{ define gotweb_render_more(struct template *tp, int action) }}
436 struct request *c = tp->tp_arg;
437 struct transport *t = c->t;
438 struct querystring *qs = t->qs;
439 struct gotweb_url more = {
443 .commit = t->more_id,
444 .headref = qs->headref,
449 <div id="np_wrapper">
451 <a href="{{ render gotweb_render_url(c, &more) }}">
459 {{ define gotweb_render_navs(struct template *tp) }}
461 struct request *c = tp->tp_arg;
462 struct transport *t = c->t;
463 struct gotweb_url prev, next;
464 int have_prev, have_next;
466 gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
468 <div id="np_wrapper">
471 <a href="{{ render gotweb_render_url(c, &prev) }}">
478 <a href="{{ render gotweb_render_url(c, &next) }}">
493 {{ define gotweb_render_commits(struct template *tp) }}
495 struct request *c = tp->tp_arg;
496 struct transport *t = c->t;
497 struct repo_dir *repo_dir = t->repo_dir;
498 struct repo_commit *rc;
499 struct gotweb_url diff, patch, tree;
501 diff = (struct gotweb_url){
505 .path = repo_dir->name,
507 patch = (struct gotweb_url){
511 .path = repo_dir->name,
513 tree = (struct gotweb_url){
517 .path = repo_dir->name,
520 <header class="subtitle">
523 <div class="commits_content">
524 {{ tailq-foreach rc &t->repo_commits entry }}
526 diff.commit = rc->commit_id;
527 patch.commit = rc->commit_id;
528 tree.commit = rc->commit_id;
530 <div class="page_header_wrapper">
533 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
535 <dd>{{ rc->author }}</dd>
536 {{ if strcmp(rc->committer, rc->author) != 0 }}
538 <dd>{{ rc->committer }}</dd>
542 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
551 <div class="navs_wrapper">
553 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
555 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
557 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
562 {{ render gotweb_render_more(tp, COMMITS) }}
566 {{ define gotweb_render_blob(struct template *tp) }}
568 struct request *c = tp->tp_arg;
569 struct transport *t = c->t;
570 struct querystring *qs = t->qs;
571 struct got_blob_object *blob = t->blob;
572 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
573 struct gotweb_url briefs_url, blame_url, raw_url;
575 memset(&briefs_url, 0, sizeof(briefs_url));
576 briefs_url.index_page = -1,
577 briefs_url.page = -1,
578 briefs_url.action = BRIEFS,
579 briefs_url.path = qs->path,
580 briefs_url.commit = qs->commit,
581 briefs_url.folder = qs->folder,
582 briefs_url.file = qs->file,
584 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
585 blame_url.action = BLAME;
587 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
588 raw_url.action = BLOBRAW;
590 <header class="subtitle">
593 <div id="blob_content">
594 <div class="page_header_wrapper">
598 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
601 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
604 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
608 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
612 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
621 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
627 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
633 r = snprintf(lineno, sizeof(lineno), "%zu", no);
634 if (r < 0 || (size_t)r >= sizeof(lineno))
637 <div class="blob_line" id="line{{ lineno }}">
638 <a href="#line{{ lineno }}">{{ lineno }}</a>
640 <span class="blob_code">{{ line }}</span>
644 {{ define gotweb_render_tree(struct template *tp) }}
646 struct request *c = tp->tp_arg;
647 struct transport *t = c->t;
648 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
650 <header class='subtitle'>
653 <div id="tree_content">
654 <div class="page_header_wrapper">
657 <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
660 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
663 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
668 {{ render got_output_repo_tree(c, gotweb_render_tree_item) }}
673 {{ define gotweb_render_tree_item(struct template *tp,
674 struct got_tree_entry *te) }}
676 struct request *c = tp->tp_arg;
677 struct transport *t = c->t;
678 struct querystring *qs = t->qs;
679 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
680 const char *modestr = "";
685 struct gotweb_url url = {
688 .commit = rc->commit_id,
692 name = got_tree_entry_get_name(te);
693 mode = got_tree_entry_get_mode(te);
695 folder = qs->folder ? qs->folder : "";
697 if (asprintf(&dir, "%s/%s", folder, name) == -1)
708 if (got_object_tree_entry_is_submodule(te))
710 else if (S_ISLNK(mode))
712 else if (S_ISDIR(mode))
714 else if (mode & S_IXUSR)
717 <tr class="tree_wrapper">
718 {{ if S_ISDIR(mode) }}
719 <td class="tree_line" colspan=2>
720 <a href="{{ render gotweb_render_url(c, &url) }}">
721 {{ name }}{{ modestr }}
725 <td class="tree_line">
726 <a href="{{ render gotweb_render_url(c, &url) }}">
727 {{ name }}{{ modestr }}
730 <td class="tree_line_blank">
731 {! url.action = COMMITS; !}
732 <a href="{{ render gotweb_render_url(c, &url) }}">
736 {! url.action = BLAME; !}
737 <a href="{{ render gotweb_render_url(c, &url) }}">
749 {{ define gotweb_render_tags(struct template *tp) }}
751 struct request *c = tp->tp_arg;
752 struct transport *t = c->t;
753 struct querystring *qs = t->qs;
757 commit_found = qs->commit == NULL;
759 <header class='subtitle'>
762 <div id="tags_content">
763 {{ if t->tag_count == 0 }}
764 <div id="err_content">
765 This repository contains no tags
768 {{ tailq-foreach rt &t->repo_tags entry }}
769 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
770 {! commit_found = 1; !}
771 {{ render tag_item(tp, rt) }}
774 {{ if t->next_id || t->prev_id }}
775 {! qs->action = TAGS; !}
776 {{ render gotweb_render_navs(tp) }}
782 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
784 struct request *c = tp->tp_arg;
785 struct transport *t = c->t;
786 struct repo_dir *repo_dir = t->repo_dir;
787 char *tag_name = rt->tag_name;
788 char *msg = rt->tag_commit;
790 struct gotweb_url url = {
794 .path = repo_dir->name,
795 .commit = rt->commit_id,
798 if (strncmp(tag_name, "refs/tags/", 10) == 0)
802 nl = strchr(msg, '\n');
807 <div class="tag_age">
808 {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
810 <div class="tag_name">{{ tag_name }}</div>
811 <div class="tag_log">
812 <a href="{{ render gotweb_render_url(c, &url) }}">
816 <div class="navs_wrapper">
818 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
820 {! url.action = BRIEFS; !}
821 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
823 {! url.action = COMMITS; !}
824 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
830 {{ define gotweb_render_tag(struct template *tp) }}
832 struct request *c = tp->tp_arg;
833 struct transport *t = c->t;
835 const char *tag_name;
837 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
838 tag_name = rt->tag_name;
840 if (strncmp(tag_name, "refs/", 5) == 0)
843 <header class="subtitle">
846 <div id="tags_content">
847 <div class="page_header_wrapper">
851 <code class="commit-id">{{ rt->commit_id }}</code>
853 <span class="refs_str">({{ tag_name }})</span>
856 <dd>{{ rt->tagger }}</dd>
859 {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
862 <dd class="commit-msg">{{ rt->commit_msg }}</dd>
865 <pre id="tag_commit">
872 {{ define gotweb_render_diff(struct template *tp) }}
874 struct request *c = tp->tp_arg;
875 struct transport *t = c->t;
876 struct querystring *qs = t->qs;
878 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
882 struct gotweb_url patch_url, tree_url = {
887 .commit = rc->commit_id,
890 memcpy(&patch_url, &tree_url, sizeof(patch_url));
891 patch_url.action = PATCH;
893 <header class="subtitle">
896 <div id="diff_content">
897 <div class="page_header_wrapper">
900 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
902 <dd>{{ rc->author }}</dd>
903 {{ if strcmp(rc->committer, rc->author) != 0 }}
905 <dd>{{ rc->committer }}</dd>
909 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
912 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
915 <a href="{{ render gotweb_render_url(c, &patch_url) }}">
919 <a href="{{ render gotweb_render_url(c, &tree_url) }}">
927 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
928 {{ render diff_line(tp, line) }}
936 {{ define diff_line(struct template *tp, char *line )}}
938 const char *color = NULL;
941 if (!strncmp(line, "-", 1))
942 color = "diff_minus";
943 else if (!strncmp(line, "+", 1))
945 else if (!strncmp(line, "@@", 2))
946 color = "diff_chunk_header";
947 else if (!strncmp(line, "commit +", 8) ||
948 !strncmp(line, "commit -", 8) ||
949 !strncmp(line, "blob +", 6) ||
950 !strncmp(line, "blob -", 6) ||
951 !strncmp(line, "file +", 6) ||
952 !strncmp(line, "file -", 6))
954 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
955 color = "diff_author";
956 else if (!strncmp(line, "date:", 5))
959 nl = strchr(line, '\n');
963 <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
966 {{ define gotweb_render_branches(struct template *tp,
967 struct got_reflist_head *refs) }}
969 struct got_reflist_entry *re;
971 <header class='subtitle'>
974 <div id="branches_content">
975 {{ tailq-foreach re refs entry }}
976 {{ if !got_ref_is_symbolic(re->ref) }}
977 {{ render branch(tp, re) }}
983 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
985 const struct got_error *err;
986 struct request *c = tp->tp_arg;
987 struct querystring *qs = c->t->qs;
990 struct gotweb_url url = {
997 refname = got_ref_get_name(re->ref);
999 err = got_get_repo_age(&age, c, refname);
1001 log_warnx("%s: %s", __func__, err->msg);
1005 if (strncmp(refname, "refs/heads/", 11) == 0)
1008 url.headref = refname;
1010 <section class="branches_wrapper">
1011 <div class="branches_age">
1012 {{ render datetime(tp, age, TM_DIFF) }}
1014 <div class="branch">
1015 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1017 <div class="navs_wrapper">
1019 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1021 {! url.action = BRIEFS; !}
1022 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1024 {! url.action = COMMITS; !}
1025 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1032 {{ define gotweb_render_summary(struct template *tp) }}
1034 struct request *c = tp->tp_arg;
1035 struct server *srv = c->srv;
1036 struct transport *t = c->t;
1037 struct got_reflist_head *refs = &t->refs;
1039 <dl id="summary_wrapper" class="page_header_wrapper">
1040 {{ if srv->show_repo_description }}
1041 <dt>Description:</dt>
1042 <dd>{{ t->repo_dir->description }}</dd>
1044 {{ if srv->show_repo_owner }}
1046 <dd>{{ t->repo_dir->owner }}</dd>
1048 {{ if srv->show_repo_age }}
1049 <dt>Last Change:</dt>
1051 {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1054 {{ if srv->show_repo_cloneurl }}
1056 <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1059 {{ render gotweb_render_briefs(tp) }}
1060 {{ render gotweb_render_tags(tp) }}
1061 {{ render gotweb_render_branches(tp, refs) }}
1064 {{ define gotweb_render_blame(struct template *tp) }}
1066 const struct got_error *err;
1067 struct request *c = tp->tp_arg;
1068 struct transport *t = c->t;
1069 struct querystring *qs = t->qs;
1070 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1071 struct gotweb_url briefs_url, blob_url, raw_url;
1073 memset(&briefs_url, 0, sizeof(briefs_url));
1074 briefs_url.index_page = -1,
1075 briefs_url.page = -1,
1076 briefs_url.action = BRIEFS,
1077 briefs_url.path = qs->path,
1078 briefs_url.commit = qs->commit,
1079 briefs_url.folder = qs->folder,
1080 briefs_url.file = qs->file,
1082 memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1083 blob_url.action = BLOB;
1085 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1086 raw_url.action = BLOBRAW;
1088 <header class="subtitle">
1091 <div id="blame_content">
1092 <div class="page_header_wrapper">
1096 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1099 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1102 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1106 <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1110 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1119 err = got_output_file_blame(c, &blame_line);
1120 if (err && err->code != GOT_ERR_CANCELLED)
1121 log_warnx("%s: got_output_file_blame: %s", __func__,
1130 {{ define blame_line(struct template *tp, const char *line,
1131 struct blame_line *bline, int lprec, int lcur) }}
1133 struct request *c = tp->tp_arg;
1134 struct transport *t = c->t;
1135 struct repo_dir *repo_dir = t->repo_dir;
1136 char *committer, *s;
1137 struct gotweb_url url = {
1141 .path = repo_dir->name,
1142 .commit = bline->id_str,
1145 s = strchr(bline->committer, '<');
1146 committer = s ? s + 1 : bline->committer;
1148 s = strchr(committer, '@');
1152 <div class="blame_line">
1153 <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1154 <span class="blame_hash">
1155 <a href="{{ render gotweb_render_url(c, &url) }}">
1156 {{ printf "%.8s", bline->id_str }}
1160 <span class="blame_date">{{ bline->datebuf }}</span>
1162 <span class="blame_author">{{ printf "%.9s", committer }}</span>
1164 <span class="blame_code">{{ line }}</span>
1168 {{ define gotweb_render_patch(struct template *tp) }}
1170 struct request *c = tp->tp_arg;
1171 struct transport *t = c->t;
1172 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1174 char buf[BUFSIZ], datebuf[64];
1177 if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1178 strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1181 commit {{ rc->commit_id }} {{ "\n" }}
1182 from: {{ rc->author | unsafe }} {{ "\n" }}
1183 {{ if strcmp(rc->committer, rc->author) != 0 }}
1184 via: {{ rc->committer | unsafe }} {{ "\n" }}
1186 date: {{ datebuf }} {{ "\n" }}
1188 {{ rc->commit_msg | unsafe }} {{ "\n" }}
1190 if (template_flush(tp) == -1)
1193 r = fread(buf, 1, sizeof(buf), t->fp);
1194 if (fcgi_write(c, buf, r) == -1 ||
1201 {{ define gotweb_render_rss(struct template *tp) }}
1203 struct request *c = tp->tp_arg;
1204 struct server *srv = c->srv;
1205 struct transport *t = c->t;
1206 struct repo_dir *repo_dir = t->repo_dir;
1207 struct repo_tag *rt;
1208 struct gotweb_url summary = {
1212 .path = repo_dir->name,
1215 <?xml version="1.0" encoding="UTF-8"?>
1216 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1218 <title>Tags of {{ repo_dir->name }}</title>
1221 {{ render gotweb_render_absolute_url(c, &summary) }}
1224 {{ if srv->show_repo_description }}
1225 <description>{{ repo_dir->description }}</description>
1227 {{ tailq-foreach rt &t->repo_tags entry }}
1228 {{ render rss_tag_item(tp, rt) }}
1234 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1236 struct request *c = tp->tp_arg;
1237 struct transport *t = c->t;
1238 struct repo_dir *repo_dir = t->repo_dir;
1242 char *tag_name = rt->tag_name;
1243 struct gotweb_url tag = {
1247 .path = repo_dir->name,
1248 .commit = rt->commit_id,
1251 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1254 if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1256 r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1261 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1264 {{ render gotweb_render_absolute_url(c, &tag) }}
1268 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1270 {{ render rss_author(tp, rt->tagger) }}
1271 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1278 {{ define rss_author(struct template *tp, char *author) }}
1282 /* what to do if the author name contains a paren? */
1283 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1286 t = strchr(author, '<');
1292 while (isspace((unsigned char)*--t))
1295 t = strchr(mail, '>');
1301 {{ mail }} {{" "}} ({{ author }})