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 tree_listing(struct template *);
55 static inline int diff_line(struct template *, char *);
56 static inline int tag_item(struct template *, struct repo_tag *);
57 static inline int branch(struct template *, struct got_reflist_entry *);
58 static inline int rss_tag_item(struct template *, struct repo_tag *);
59 static inline int rss_author(struct template *, char *);
62 nextsep(char *s, char **t)
80 {{ define datetime(struct template *tp, time_t t, int fmt) }}
86 if (gmtime_r(&t, &tm) == NULL)
89 if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
92 if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
95 <time datetime="{{ rfc3339 }}">
96 {{ if fmt == TM_DIFF }}
97 {{ render gotweb_render_age(tp, t) }}
99 {{ datebuf }} {{ " UTC" }}
104 {{ define breadcumbs(struct template *tp) }}
106 struct request *c = tp->tp_arg;
107 struct querystring *qs = c->t->qs;
108 struct gotweb_url url;
109 const char *folder = qs->folder;
110 const char *action = "tree";
111 char *t, *s = NULL, *dir = NULL;
114 memset(&url, 0, sizeof(url));
119 url.commit = qs->commit;
121 if (qs->action != TREE && qs->action != BLOB) {
122 action = gotweb_action_name(qs->action);
123 url.action = qs->action;
126 if (folder && *folder != '\0') {
127 while (*folder == '/')
129 dir = strdup(folder);
136 <a href="{{ render gotweb_render_url(c, &url) }}">{{ action }}</a>
139 {{ while (s = nextsep(s, &t)) != NULL }}
146 <a href="{{ render gotweb_render_url(c, &url) }}">
163 {{ define gotweb_render_page(struct template *tp,
164 int (*body)(struct template *)) }}
166 struct request *c = tp->tp_arg;
167 struct server *srv = c->srv;
168 struct querystring *qs = c->t->qs;
169 struct gotweb_url u_path;
170 const char *prfx = c->document_uri;
171 const char *css = srv->custom_css;
173 memset(&u_path, 0, sizeof(u_path));
174 u_path.index_page = -1;
176 u_path.action = SUMMARY;
181 <meta charset="utf-8" />
182 <title>{{ srv->site_name }}</title>
183 <meta name="viewport" content="initial-scale=1.0" />
184 <meta name="msapplication-TileColor" content="#da532c" />
185 <meta name="theme-color" content="#ffffff"/>
186 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
187 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
188 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
189 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
190 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
191 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
196 <a href="{{ srv->logo_url }}" target="_blank">
197 <img src="{{ prfx }}{{ srv->logo }}" />
203 <a href="?index_page={{ printf "%d", qs->index_page }}">
207 {! u_path.path = qs->path; !}
209 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
213 {{ if qs->action == SUMMARY || qs->action == DIFF ||
214 qs->action == TAG || qs->action == TAGS }}
215 {{ " / " }}{{ gotweb_action_name(qs->action) }}
216 {{ else if qs->action != INDEX}}
217 {{ render breadcumbs(tp) }}
222 {{ render body(tp) }}
224 <footer id="site_owner_wrapper">
226 {{ if srv->show_site_owner }}
227 {{ srv->site_owner }}
235 {{ define gotweb_render_error(struct template *tp) }}
237 struct request *c = tp->tp_arg;
238 struct transport *t = c->t;
240 <div id="err_content">
244 See daemon logs for details
249 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
251 struct request *c = tp->tp_arg;
252 struct server *srv = c->srv;
254 <div id="index_header">
255 <div class="index_project">
258 {{ if srv->show_repo_description }}
259 <div class="index_project_description">
263 {{ if srv->show_repo_owner }}
264 <div class="index_project_owner">
268 {{ if srv->show_repo_age }}
269 <div class="index_project_age">
276 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
278 struct request *c = tp->tp_arg;
279 struct server *srv = c->srv;
280 struct gotweb_url summary = {
284 .path = repo_dir->name,
289 .path = repo_dir->name,
294 .path = repo_dir->name,
299 .path = repo_dir->name,
304 .path = repo_dir->name,
309 .path = repo_dir->name,
312 <div class="index_wrapper">
313 <div class="index_project">
314 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
316 {{ if srv->show_repo_description }}
317 <div class="index_project_description">
318 {{ repo_dir->description }}
321 {{ if srv->show_repo_owner }}
322 <div class="index_project_owner">
323 {{ repo_dir->owner }}
326 {{ if srv->show_repo_age }}
327 <div class="index_project_age">
328 {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
331 <div class="navs_wrapper">
333 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
335 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
337 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
339 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
341 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
343 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
350 {{ define gotweb_render_briefs(struct template *tp) }}
352 struct request *c = tp->tp_arg;
353 struct transport *t = c->t;
354 struct querystring *qs = c->t->qs;
355 struct repo_commit *rc;
356 struct repo_dir *repo_dir = t->repo_dir;
357 struct gotweb_url diff_url, patch_url, tree_url;
360 diff_url = (struct gotweb_url){
364 .path = repo_dir->name,
365 .headref = qs->headref,
367 patch_url = (struct gotweb_url){
371 .path = repo_dir->name,
372 .headref = qs->headref,
374 tree_url = (struct gotweb_url){
378 .path = repo_dir->name,
379 .headref = qs->headref,
382 <header class='subtitle'>
383 <h2>Commit Briefs</h2>
385 <div id="briefs_content">
386 {{ tailq-foreach rc &t->repo_commits entry }}
388 diff_url.commit = rc->commit_id;
389 patch_url.commit = rc->commit_id;
390 tree_url.commit = rc->commit_id;
392 tmp = strchr(rc->committer, '<');
396 body = strchr(rc->commit_msg, '\n');
399 while (*body == '\n')
404 <p class='brief_meta'>
405 <span class='briefs_age'>
406 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
409 <span class="briefs_author">
413 {{ if body && *body != '\0' }}
414 <details class="briefs_log">
416 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
419 {{ if rc->refs_str }}
420 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
423 <span class="briefs_toggle" aria-hidden="true">
431 <p class="briefs_log">
432 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
435 {{ if rc->refs_str }}
436 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
441 <div class="navs_wrapper">
443 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
445 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
447 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
452 {{ render gotweb_render_more(tp, BRIEFS) }}
456 {{ define gotweb_render_more(struct template *tp, int action) }}
458 struct request *c = tp->tp_arg;
459 struct transport *t = c->t;
460 struct querystring *qs = t->qs;
461 struct gotweb_url more = {
465 .commit = t->more_id,
466 .headref = qs->headref,
471 more.commit = t->tags_more_id;
474 <div id="np_wrapper">
476 <a href="{{ render gotweb_render_url(c, &more) }}">
484 {{ define gotweb_render_navs(struct template *tp) }}
486 struct request *c = tp->tp_arg;
487 struct gotweb_url prev, next;
488 int have_prev, have_next;
490 gotweb_index_navs(c, &prev, &have_prev, &next, &have_next);
492 <div id="np_wrapper">
495 <a href="{{ render gotweb_render_url(c, &prev) }}">
502 <a href="{{ render gotweb_render_url(c, &next) }}">
510 {{ define gotweb_render_commits(struct template *tp) }}
512 struct request *c = tp->tp_arg;
513 struct transport *t = c->t;
514 struct repo_dir *repo_dir = t->repo_dir;
515 struct repo_commit *rc;
516 struct gotweb_url diff, patch, tree;
518 diff = (struct gotweb_url){
522 .path = repo_dir->name,
524 patch = (struct gotweb_url){
528 .path = repo_dir->name,
530 tree = (struct gotweb_url){
534 .path = repo_dir->name,
537 <header class="subtitle">
540 <div class="commits_content">
541 {{ tailq-foreach rc &t->repo_commits entry }}
543 diff.commit = rc->commit_id;
544 patch.commit = rc->commit_id;
545 tree.commit = rc->commit_id;
547 <div class="page_header_wrapper">
550 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
552 <dd>{{ rc->author }}</dd>
553 {{ if strcmp(rc->committer, rc->author) != 0 }}
555 <dd>{{ rc->committer }}</dd>
559 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
568 <div class="navs_wrapper">
570 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
572 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
574 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
579 {{ render gotweb_render_more(tp, COMMITS) }}
583 {{ define gotweb_render_blob(struct template *tp) }}
585 struct request *c = tp->tp_arg;
586 struct transport *t = c->t;
587 struct querystring *qs = t->qs;
588 struct got_blob_object *blob = t->blob;
589 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
590 struct gotweb_url briefs_url, blame_url, raw_url;
592 memset(&briefs_url, 0, sizeof(briefs_url));
593 briefs_url.index_page = -1,
594 briefs_url.page = -1,
595 briefs_url.action = BRIEFS,
596 briefs_url.path = qs->path,
597 briefs_url.commit = qs->commit,
598 briefs_url.folder = qs->folder,
599 briefs_url.file = qs->file,
601 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
602 blame_url.action = BLAME;
604 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
605 raw_url.action = BLOBRAW;
607 <header class="subtitle">
610 <div id="blob_content">
611 <div class="page_header_wrapper">
615 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
618 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
621 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
625 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
629 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
638 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
644 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
650 r = snprintf(lineno, sizeof(lineno), "%zu", no);
651 if (r < 0 || (size_t)r >= sizeof(lineno))
654 <div class="blob_line" id="line{{ lineno }}">
655 <a href="#line{{ lineno }}">{{ lineno }}</a>
657 <span class="blob_code">{{ line }}</span>
661 {{ define tree_listing(struct template *tp) }}
663 const struct got_error *error;
664 struct request *c = tp->tp_arg;
665 struct transport *t = c->t;
666 struct querystring *qs = c->t->qs;
667 struct gotweb_url url;
674 {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }}
678 error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c,
679 qs->folder, readme, qs->commit);
685 memset(&url, 0, sizeof(url));
689 url.path = t->qs->path;
691 url.folder = t->qs->folder;
692 url.commit = t->qs->commit;
696 <a href="{{ render gotweb_render_url(c, &url) }}">
703 error = got_object_blob_read_block(&len, t->blob);
710 buf = got_object_blob_get_read_buf(t->blob);
711 if (tp_write_htmlescape(tp, buf, len) == -1) {
724 {{ define gotweb_render_tree(struct template *tp) }}
726 struct request *c = tp->tp_arg;
727 struct transport *t = c->t;
728 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
730 <header class='subtitle'>
733 <div id="tree_content">
734 <div class="page_header_wrapper">
737 <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
740 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
743 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
747 {{ render tree_listing(tp) }}
751 {{ define gotweb_render_tree_item(struct template *tp,
752 struct got_tree_entry *te) }}
754 struct request *c = tp->tp_arg;
755 struct transport *t = c->t;
756 struct querystring *qs = t->qs;
757 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
758 const char *modestr = "";
763 struct gotweb_url url = {
766 .commit = rc->commit_id,
770 name = got_tree_entry_get_name(te);
771 mode = got_tree_entry_get_mode(te);
773 folder = qs->folder ? qs->folder : "";
775 if (asprintf(&dir, "%s/%s", folder, name) == -1)
786 if (got_object_tree_entry_is_submodule(te))
788 else if (S_ISLNK(mode))
790 else if (S_ISDIR(mode))
792 else if (mode & S_IXUSR)
795 <tr class="tree_wrapper">
796 {{ if S_ISDIR(mode) }}
797 <td class="tree_line" colspan=2>
798 <a href="{{ render gotweb_render_url(c, &url) }}">
799 {{ name }}{{ modestr }}
803 <td class="tree_line">
804 <a href="{{ render gotweb_render_url(c, &url) }}">
805 {{ name }}{{ modestr }}
808 <td class="tree_line_blank">
809 {! url.action = COMMITS; !}
810 <a href="{{ render gotweb_render_url(c, &url) }}">
814 {! url.action = BLAME; !}
815 <a href="{{ render gotweb_render_url(c, &url) }}">
827 {{ define gotweb_render_tags(struct template *tp) }}
829 struct request *c = tp->tp_arg;
830 struct transport *t = c->t;
831 struct querystring *qs = t->qs;
835 commit_found = qs->commit == NULL;
837 <header class='subtitle'>
840 <div id="tags_content">
841 {{ if t->tag_count == 0 }}
842 <div id="err_content">
843 This repository contains no tags
846 {{ tailq-foreach rt &t->repo_tags entry }}
847 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
848 {! commit_found = 1; !}
849 {{ render tag_item(tp, rt) }}
852 {{ render gotweb_render_more(tp, TAGS) }}
857 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
859 struct request *c = tp->tp_arg;
860 struct transport *t = c->t;
861 struct repo_dir *repo_dir = t->repo_dir;
862 char *tag_name = rt->tag_name;
863 char *msg = rt->tag_commit;
865 struct gotweb_url url = {
869 .path = repo_dir->name,
870 .commit = rt->commit_id,
873 if (strncmp(tag_name, "refs/tags/", 10) == 0)
877 nl = strchr(msg, '\n');
882 <div class="tag_age">
883 {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
885 <div class="tag_name">{{ tag_name }}</div>
886 <div class="tag_log">
887 <a href="{{ render gotweb_render_url(c, &url) }}">
891 <div class="navs_wrapper">
893 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
895 {! url.action = BRIEFS; !}
896 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
898 {! url.action = COMMITS; !}
899 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
905 {{ define gotweb_render_tag(struct template *tp) }}
907 struct request *c = tp->tp_arg;
908 struct transport *t = c->t;
910 const char *tag_name;
912 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
913 tag_name = rt->tag_name;
915 if (strncmp(tag_name, "refs/", 5) == 0)
918 <header class="subtitle">
921 <div id="tags_content">
922 <div class="page_header_wrapper">
926 <code class="commit-id">{{ rt->commit_id }}</code>
928 <span class="refs_str">({{ tag_name }})</span>
931 <dd>{{ rt->tagger }}</dd>
934 {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
937 <dd class="commit-msg">{{ rt->commit_msg }}</dd>
940 <pre id="tag_commit">
947 {{ define gotweb_render_diff(struct template *tp) }}
949 struct request *c = tp->tp_arg;
950 struct transport *t = c->t;
951 struct querystring *qs = t->qs;
953 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
957 struct gotweb_url patch_url, tree_url = {
962 .commit = rc->commit_id,
965 memcpy(&patch_url, &tree_url, sizeof(patch_url));
966 patch_url.action = PATCH;
968 <header class="subtitle">
971 <div id="diff_content">
972 <div class="page_header_wrapper">
975 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
977 <dd>{{ rc->author }}</dd>
978 {{ if strcmp(rc->committer, rc->author) != 0 }}
980 <dd>{{ rc->committer }}</dd>
984 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
987 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
990 <a href="{{ render gotweb_render_url(c, &patch_url) }}">
994 <a href="{{ render gotweb_render_url(c, &tree_url) }}">
1002 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
1003 {{ render diff_line(tp, line) }}
1011 {{ define diff_line(struct template *tp, char *line )}}
1013 const char *color = NULL;
1016 if (!strncmp(line, "-", 1))
1017 color = "diff_minus";
1018 else if (!strncmp(line, "+", 1))
1019 color = "diff_plus";
1020 else if (!strncmp(line, "@@", 2))
1021 color = "diff_chunk_header";
1022 else if (!strncmp(line, "commit +", 8) ||
1023 !strncmp(line, "commit -", 8) ||
1024 !strncmp(line, "blob +", 6) ||
1025 !strncmp(line, "blob -", 6) ||
1026 !strncmp(line, "file +", 6) ||
1027 !strncmp(line, "file -", 6))
1028 color = "diff_meta";
1029 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
1030 color = "diff_author";
1031 else if (!strncmp(line, "date:", 5))
1032 color = "diff_date";
1034 nl = strchr(line, '\n');
1038 <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
1041 {{ define gotweb_render_branches(struct template *tp,
1042 struct got_reflist_head *refs) }}
1044 struct got_reflist_entry *re;
1046 <header class='subtitle'>
1049 <div id="branches_content">
1050 {{ tailq-foreach re refs entry }}
1051 {{ if !got_ref_is_symbolic(re->ref) }}
1052 {{ render branch(tp, re) }}
1058 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
1060 const struct got_error *err;
1061 struct request *c = tp->tp_arg;
1062 struct querystring *qs = c->t->qs;
1063 const char *refname;
1065 struct gotweb_url url = {
1072 refname = got_ref_get_name(re->ref);
1074 err = got_get_repo_age(&age, c, refname);
1076 log_warnx("%s: %s", __func__, err->msg);
1080 if (strncmp(refname, "refs/heads/", 11) == 0)
1083 url.headref = refname;
1085 <section class="branches_wrapper">
1086 <div class="branches_age">
1087 {{ render datetime(tp, age, TM_DIFF) }}
1089 <div class="branch">
1090 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1092 <div class="navs_wrapper">
1094 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1096 {! url.action = BRIEFS; !}
1097 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1099 {! url.action = COMMITS; !}
1100 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1107 {{ define gotweb_render_summary(struct template *tp) }}
1109 struct request *c = tp->tp_arg;
1110 struct server *srv = c->srv;
1111 struct transport *t = c->t;
1112 struct got_reflist_head *refs = &t->refs;
1114 <dl id="summary_wrapper" class="page_header_wrapper">
1115 {{ if srv->show_repo_description }}
1116 <dt>Description:</dt>
1117 <dd>{{ t->repo_dir->description }}</dd>
1119 {{ if srv->show_repo_owner }}
1121 <dd>{{ t->repo_dir->owner }}</dd>
1123 {{ if srv->show_repo_age }}
1124 <dt>Last Change:</dt>
1126 {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1129 {{ if srv->show_repo_cloneurl }}
1131 <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1134 {{ render gotweb_render_briefs(tp) }}
1135 {{ render gotweb_render_branches(tp, refs) }}
1136 {{ render gotweb_render_tags(tp) }}
1137 <header class='subtitle'>
1140 <div id="tree_content">
1141 {{ render tree_listing(tp) }}
1145 {{ define gotweb_render_blame(struct template *tp) }}
1147 const struct got_error *err;
1148 struct request *c = tp->tp_arg;
1149 struct transport *t = c->t;
1150 struct querystring *qs = t->qs;
1151 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1152 struct gotweb_url briefs_url, blob_url, raw_url;
1154 memset(&briefs_url, 0, sizeof(briefs_url));
1155 briefs_url.index_page = -1,
1156 briefs_url.page = -1,
1157 briefs_url.action = BRIEFS,
1158 briefs_url.path = qs->path,
1159 briefs_url.commit = qs->commit,
1160 briefs_url.folder = qs->folder,
1161 briefs_url.file = qs->file,
1163 memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1164 blob_url.action = BLOB;
1166 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1167 raw_url.action = BLOBRAW;
1169 <header class="subtitle">
1172 <div id="blame_content">
1173 <div class="page_header_wrapper">
1177 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1180 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1183 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1187 <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1191 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1200 err = got_output_file_blame(c, &blame_line);
1201 if (err && err->code != GOT_ERR_CANCELLED)
1202 log_warnx("%s: got_output_file_blame: %s", __func__,
1211 {{ define blame_line(struct template *tp, const char *line,
1212 struct blame_line *bline, int lprec, int lcur) }}
1214 struct request *c = tp->tp_arg;
1215 struct transport *t = c->t;
1216 struct repo_dir *repo_dir = t->repo_dir;
1217 char *committer, *s;
1218 struct gotweb_url url = {
1222 .path = repo_dir->name,
1223 .commit = bline->id_str,
1226 s = strchr(bline->committer, '<');
1227 committer = s ? s + 1 : bline->committer;
1229 s = strchr(committer, '@');
1233 <div class="blame_line">
1234 <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1235 <span class="blame_hash">
1236 <a href="{{ render gotweb_render_url(c, &url) }}">
1237 {{ printf "%.8s", bline->id_str }}
1241 <span class="blame_date">{{ bline->datebuf }}</span>
1243 <span class="blame_author">{{ printf "%.9s", committer }}</span>
1245 <span class="blame_code">{{ line }}</span>
1249 {{ define gotweb_render_patch(struct template *tp) }}
1251 struct request *c = tp->tp_arg;
1252 struct transport *t = c->t;
1253 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1255 char buf[BUFSIZ], datebuf[64];
1258 if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1259 strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1262 commit {{ rc->commit_id }} {{ "\n" }}
1263 from: {{ rc->author | unsafe }} {{ "\n" }}
1264 {{ if strcmp(rc->committer, rc->author) != 0 }}
1265 via: {{ rc->committer | unsafe }} {{ "\n" }}
1267 date: {{ datebuf }} {{ "\n" }}
1269 {{ rc->commit_msg | unsafe }} {{ "\n" }}
1271 if (template_flush(tp) == -1)
1274 r = fread(buf, 1, sizeof(buf), t->fp);
1275 if (fcgi_write(c, buf, r) == -1 ||
1282 {{ define gotweb_render_rss(struct template *tp) }}
1284 struct request *c = tp->tp_arg;
1285 struct server *srv = c->srv;
1286 struct transport *t = c->t;
1287 struct repo_dir *repo_dir = t->repo_dir;
1288 struct repo_tag *rt;
1289 struct gotweb_url summary = {
1293 .path = repo_dir->name,
1296 <?xml version="1.0" encoding="UTF-8"?>
1297 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1299 <title>Tags of {{ repo_dir->name }}</title>
1302 {{ render gotweb_render_absolute_url(c, &summary) }}
1305 {{ if srv->show_repo_description }}
1306 <description>{{ repo_dir->description }}</description>
1308 {{ tailq-foreach rt &t->repo_tags entry }}
1309 {{ render rss_tag_item(tp, rt) }}
1315 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1317 struct request *c = tp->tp_arg;
1318 struct transport *t = c->t;
1319 struct repo_dir *repo_dir = t->repo_dir;
1323 char *tag_name = rt->tag_name;
1324 struct gotweb_url tag = {
1328 .path = repo_dir->name,
1329 .commit = rt->commit_id,
1332 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1335 if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1337 r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1342 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1345 {{ render gotweb_render_absolute_url(c, &tag) }}
1349 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1351 {{ render rss_author(tp, rt->tagger) }}
1352 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1359 {{ define rss_author(struct template *tp, char *author) }}
1363 /* what to do if the author name contains a paren? */
1364 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1367 t = strchr(author, '<');
1373 while (isspace((unsigned char)*--t))
1376 t = strchr(mail, '>');
1382 {{ mail }} {{" "}} ({{ author }})