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 body = strchr(rc->commit_msg, '\n');
391 while (*body == '\n')
396 <p class='brief_meta'>
397 <span class='briefs_age'>
398 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
401 <span class="briefs_author">
405 {{ if body && *body != '\0' }}
406 <details class="briefs_log">
408 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
411 {{ if rc->refs_str }}
412 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
415 <span class="briefs_toggle" aria-hidden="true">
416 {{ " ⋅⋅⋅ " | unsafe }}
423 <p class="briefs_log">
424 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
427 {{ if rc->refs_str }}
428 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
433 <div class="navs_wrapper">
435 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
437 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
439 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
444 {{ render gotweb_render_more(tp, BRIEFS) }}
448 {{ define gotweb_render_more(struct template *tp, int action) }}
450 struct request *c = tp->tp_arg;
451 struct transport *t = c->t;
452 struct querystring *qs = t->qs;
453 struct gotweb_url more = {
457 .commit = t->more_id,
458 .headref = qs->headref,
463 <div id="np_wrapper">
465 <a href="{{ render gotweb_render_url(c, &more) }}">
473 {{ define gotweb_render_navs(struct template *tp) }}
475 struct request *c = tp->tp_arg;
476 struct transport *t = c->t;
477 struct gotweb_url prev, next;
478 int have_prev, have_next;
480 gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
482 <div id="np_wrapper">
485 <a href="{{ render gotweb_render_url(c, &prev) }}">
492 <a href="{{ render gotweb_render_url(c, &next) }}">
507 {{ define gotweb_render_commits(struct template *tp) }}
509 struct request *c = tp->tp_arg;
510 struct transport *t = c->t;
511 struct repo_dir *repo_dir = t->repo_dir;
512 struct repo_commit *rc;
513 struct gotweb_url diff, patch, tree;
515 diff = (struct gotweb_url){
519 .path = repo_dir->name,
521 patch = (struct gotweb_url){
525 .path = repo_dir->name,
527 tree = (struct gotweb_url){
531 .path = repo_dir->name,
534 <header class="subtitle">
537 <div class="commits_content">
538 {{ tailq-foreach rc &t->repo_commits entry }}
540 diff.commit = rc->commit_id;
541 patch.commit = rc->commit_id;
542 tree.commit = rc->commit_id;
544 <div class="page_header_wrapper">
547 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
549 <dd>{{ rc->author }}</dd>
550 {{ if strcmp(rc->committer, rc->author) != 0 }}
552 <dd>{{ rc->committer }}</dd>
556 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
565 <div class="navs_wrapper">
567 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
569 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
571 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
576 {{ render gotweb_render_more(tp, COMMITS) }}
580 {{ define gotweb_render_blob(struct template *tp) }}
582 struct request *c = tp->tp_arg;
583 struct transport *t = c->t;
584 struct querystring *qs = t->qs;
585 struct got_blob_object *blob = t->blob;
586 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
587 struct gotweb_url briefs_url, blame_url, raw_url;
589 memset(&briefs_url, 0, sizeof(briefs_url));
590 briefs_url.index_page = -1,
591 briefs_url.page = -1,
592 briefs_url.action = BRIEFS,
593 briefs_url.path = qs->path,
594 briefs_url.commit = qs->commit,
595 briefs_url.folder = qs->folder,
596 briefs_url.file = qs->file,
598 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
599 blame_url.action = BLAME;
601 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
602 raw_url.action = BLOBRAW;
604 <header class="subtitle">
607 <div id="blob_content">
608 <div class="page_header_wrapper">
612 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
615 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
618 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
622 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
626 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
635 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
641 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
647 r = snprintf(lineno, sizeof(lineno), "%zu", no);
648 if (r < 0 || (size_t)r >= sizeof(lineno))
651 <div class="blob_line" id="line{{ lineno }}">
652 <a href="#line{{ lineno }}">{{ lineno }}</a>
654 <span class="blob_code">{{ line }}</span>
658 {{ define gotweb_render_tree(struct template *tp) }}
660 const struct got_error *error;
661 struct request *c = tp->tp_arg;
662 struct transport *t = c->t;
663 struct querystring *qs = t->qs;
664 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
665 struct gotweb_url url;
671 <header class='subtitle'>
674 <div id="tree_content">
675 <div class="page_header_wrapper">
678 <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
681 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
684 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
689 {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }}
693 error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c,
694 qs->folder, readme, qs->commit);
701 memset(&url, 0, sizeof(url));
705 url.path = t->qs->path;
707 url.folder = t->qs->folder;
708 url.commit = t->qs->commit;
712 <a href="{{ render gotweb_render_url(c, &url) }}">
719 error = got_object_blob_read_block(&len, t->blob);
726 buf = got_object_blob_get_read_buf(t->blob);
727 if (tp_write_htmlescape(tp, buf, len) == -1) {
741 {{ define gotweb_render_tree_item(struct template *tp,
742 struct got_tree_entry *te) }}
744 struct request *c = tp->tp_arg;
745 struct transport *t = c->t;
746 struct querystring *qs = t->qs;
747 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
748 const char *modestr = "";
753 struct gotweb_url url = {
756 .commit = rc->commit_id,
760 name = got_tree_entry_get_name(te);
761 mode = got_tree_entry_get_mode(te);
763 folder = qs->folder ? qs->folder : "";
765 if (asprintf(&dir, "%s/%s", folder, name) == -1)
776 if (got_object_tree_entry_is_submodule(te))
778 else if (S_ISLNK(mode))
780 else if (S_ISDIR(mode))
782 else if (mode & S_IXUSR)
785 <tr class="tree_wrapper">
786 {{ if S_ISDIR(mode) }}
787 <td class="tree_line" colspan=2>
788 <a href="{{ render gotweb_render_url(c, &url) }}">
789 {{ name }}{{ modestr }}
793 <td class="tree_line">
794 <a href="{{ render gotweb_render_url(c, &url) }}">
795 {{ name }}{{ modestr }}
798 <td class="tree_line_blank">
799 {! url.action = COMMITS; !}
800 <a href="{{ render gotweb_render_url(c, &url) }}">
804 {! url.action = BLAME; !}
805 <a href="{{ render gotweb_render_url(c, &url) }}">
817 {{ define gotweb_render_tags(struct template *tp) }}
819 struct request *c = tp->tp_arg;
820 struct transport *t = c->t;
821 struct querystring *qs = t->qs;
825 commit_found = qs->commit == NULL;
827 <header class='subtitle'>
830 <div id="tags_content">
831 {{ if t->tag_count == 0 }}
832 <div id="err_content">
833 This repository contains no tags
836 {{ tailq-foreach rt &t->repo_tags entry }}
837 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
838 {! commit_found = 1; !}
839 {{ render tag_item(tp, rt) }}
842 {{ if t->next_id || t->prev_id }}
843 {! qs->action = TAGS; !}
844 {{ render gotweb_render_navs(tp) }}
850 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
852 struct request *c = tp->tp_arg;
853 struct transport *t = c->t;
854 struct repo_dir *repo_dir = t->repo_dir;
855 char *tag_name = rt->tag_name;
856 char *msg = rt->tag_commit;
858 struct gotweb_url url = {
862 .path = repo_dir->name,
863 .commit = rt->commit_id,
866 if (strncmp(tag_name, "refs/tags/", 10) == 0)
870 nl = strchr(msg, '\n');
875 <div class="tag_age">
876 {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
878 <div class="tag_name">{{ tag_name }}</div>
879 <div class="tag_log">
880 <a href="{{ render gotweb_render_url(c, &url) }}">
884 <div class="navs_wrapper">
886 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
888 {! url.action = BRIEFS; !}
889 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
891 {! url.action = COMMITS; !}
892 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
898 {{ define gotweb_render_tag(struct template *tp) }}
900 struct request *c = tp->tp_arg;
901 struct transport *t = c->t;
903 const char *tag_name;
905 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
906 tag_name = rt->tag_name;
908 if (strncmp(tag_name, "refs/", 5) == 0)
911 <header class="subtitle">
914 <div id="tags_content">
915 <div class="page_header_wrapper">
919 <code class="commit-id">{{ rt->commit_id }}</code>
921 <span class="refs_str">({{ tag_name }})</span>
924 <dd>{{ rt->tagger }}</dd>
927 {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
930 <dd class="commit-msg">{{ rt->commit_msg }}</dd>
933 <pre id="tag_commit">
940 {{ define gotweb_render_diff(struct template *tp) }}
942 struct request *c = tp->tp_arg;
943 struct transport *t = c->t;
944 struct querystring *qs = t->qs;
946 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
950 struct gotweb_url patch_url, tree_url = {
955 .commit = rc->commit_id,
958 memcpy(&patch_url, &tree_url, sizeof(patch_url));
959 patch_url.action = PATCH;
961 <header class="subtitle">
964 <div id="diff_content">
965 <div class="page_header_wrapper">
968 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
970 <dd>{{ rc->author }}</dd>
971 {{ if strcmp(rc->committer, rc->author) != 0 }}
973 <dd>{{ rc->committer }}</dd>
977 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
980 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
983 <a href="{{ render gotweb_render_url(c, &patch_url) }}">
986 {{ " — " | unsafe }}
987 <a href="{{ render gotweb_render_url(c, &tree_url) }}">
995 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
996 {{ render diff_line(tp, line) }}
1004 {{ define diff_line(struct template *tp, char *line )}}
1006 const char *color = NULL;
1009 if (!strncmp(line, "-", 1))
1010 color = "diff_minus";
1011 else if (!strncmp(line, "+", 1))
1012 color = "diff_plus";
1013 else if (!strncmp(line, "@@", 2))
1014 color = "diff_chunk_header";
1015 else if (!strncmp(line, "commit +", 8) ||
1016 !strncmp(line, "commit -", 8) ||
1017 !strncmp(line, "blob +", 6) ||
1018 !strncmp(line, "blob -", 6) ||
1019 !strncmp(line, "file +", 6) ||
1020 !strncmp(line, "file -", 6))
1021 color = "diff_meta";
1022 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
1023 color = "diff_author";
1024 else if (!strncmp(line, "date:", 5))
1025 color = "diff_date";
1027 nl = strchr(line, '\n');
1031 <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
1034 {{ define gotweb_render_branches(struct template *tp,
1035 struct got_reflist_head *refs) }}
1037 struct got_reflist_entry *re;
1039 <header class='subtitle'>
1042 <div id="branches_content">
1043 {{ tailq-foreach re refs entry }}
1044 {{ if !got_ref_is_symbolic(re->ref) }}
1045 {{ render branch(tp, re) }}
1051 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
1053 const struct got_error *err;
1054 struct request *c = tp->tp_arg;
1055 struct querystring *qs = c->t->qs;
1056 const char *refname;
1058 struct gotweb_url url = {
1065 refname = got_ref_get_name(re->ref);
1067 err = got_get_repo_age(&age, c, refname);
1069 log_warnx("%s: %s", __func__, err->msg);
1073 if (strncmp(refname, "refs/heads/", 11) == 0)
1076 url.headref = refname;
1078 <section class="branches_wrapper">
1079 <div class="branches_age">
1080 {{ render datetime(tp, age, TM_DIFF) }}
1082 <div class="branch">
1083 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1085 <div class="navs_wrapper">
1087 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1089 {! url.action = BRIEFS; !}
1090 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1092 {! url.action = COMMITS; !}
1093 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1100 {{ define gotweb_render_summary(struct template *tp) }}
1102 struct request *c = tp->tp_arg;
1103 struct server *srv = c->srv;
1104 struct transport *t = c->t;
1105 struct got_reflist_head *refs = &t->refs;
1107 <dl id="summary_wrapper" class="page_header_wrapper">
1108 {{ if srv->show_repo_description }}
1109 <dt>Description:</dt>
1110 <dd>{{ t->repo_dir->description }}</dd>
1112 {{ if srv->show_repo_owner }}
1114 <dd>{{ t->repo_dir->owner }}</dd>
1116 {{ if srv->show_repo_age }}
1117 <dt>Last Change:</dt>
1119 {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1122 {{ if srv->show_repo_cloneurl }}
1124 <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1127 {{ render gotweb_render_briefs(tp) }}
1128 {{ render gotweb_render_tags(tp) }}
1129 {{ render gotweb_render_branches(tp, refs) }}
1132 {{ define gotweb_render_blame(struct template *tp) }}
1134 const struct got_error *err;
1135 struct request *c = tp->tp_arg;
1136 struct transport *t = c->t;
1137 struct querystring *qs = t->qs;
1138 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1139 struct gotweb_url briefs_url, blob_url, raw_url;
1141 memset(&briefs_url, 0, sizeof(briefs_url));
1142 briefs_url.index_page = -1,
1143 briefs_url.page = -1,
1144 briefs_url.action = BRIEFS,
1145 briefs_url.path = qs->path,
1146 briefs_url.commit = qs->commit,
1147 briefs_url.folder = qs->folder,
1148 briefs_url.file = qs->file,
1150 memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1151 blob_url.action = BLOB;
1153 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1154 raw_url.action = BLOBRAW;
1156 <header class="subtitle">
1159 <div id="blame_content">
1160 <div class="page_header_wrapper">
1164 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1167 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1170 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1173 {{ " — " | unsafe }}
1174 <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1177 {{ " — " | unsafe }}
1178 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1187 err = got_output_file_blame(c, &blame_line);
1188 if (err && err->code != GOT_ERR_CANCELLED)
1189 log_warnx("%s: got_output_file_blame: %s", __func__,
1198 {{ define blame_line(struct template *tp, const char *line,
1199 struct blame_line *bline, int lprec, int lcur) }}
1201 struct request *c = tp->tp_arg;
1202 struct transport *t = c->t;
1203 struct repo_dir *repo_dir = t->repo_dir;
1204 char *committer, *s;
1205 struct gotweb_url url = {
1209 .path = repo_dir->name,
1210 .commit = bline->id_str,
1213 s = strchr(bline->committer, '<');
1214 committer = s ? s + 1 : bline->committer;
1216 s = strchr(committer, '@');
1220 <div class="blame_line">
1221 <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1222 <span class="blame_hash">
1223 <a href="{{ render gotweb_render_url(c, &url) }}">
1224 {{ printf "%.8s", bline->id_str }}
1228 <span class="blame_date">{{ bline->datebuf }}</span>
1230 <span class="blame_author">{{ printf "%.9s", committer }}</span>
1232 <span class="blame_code">{{ line }}</span>
1236 {{ define gotweb_render_patch(struct template *tp) }}
1238 struct request *c = tp->tp_arg;
1239 struct transport *t = c->t;
1240 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1242 char buf[BUFSIZ], datebuf[64];
1245 if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1246 strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1249 commit {{ rc->commit_id }} {{ "\n" }}
1250 from: {{ rc->author | unsafe }} {{ "\n" }}
1251 {{ if strcmp(rc->committer, rc->author) != 0 }}
1252 via: {{ rc->author | unsafe }} {{ "\n" }}
1254 date: {{ datebuf }} {{ "\n" }}
1256 {{ rc->commit_msg | unsafe }} {{ "\n" }}
1258 if (template_flush(tp) == -1)
1261 r = fread(buf, 1, sizeof(buf), t->fp);
1262 if (fcgi_write(c, buf, r) == -1 ||
1269 {{ define gotweb_render_rss(struct template *tp) }}
1271 struct request *c = tp->tp_arg;
1272 struct server *srv = c->srv;
1273 struct transport *t = c->t;
1274 struct repo_dir *repo_dir = t->repo_dir;
1275 struct repo_tag *rt;
1276 struct gotweb_url summary = {
1280 .path = repo_dir->name,
1283 <?xml version="1.0" encoding="UTF-8"?>
1284 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1286 <title>Tags of {{ repo_dir->name }}</title>
1289 {{ render gotweb_render_absolute_url(c, &summary) }}
1292 {{ if srv->show_repo_description }}
1293 <description>{{ repo_dir->description }}</description>
1295 {{ tailq-foreach rt &t->repo_tags entry }}
1296 {{ render rss_tag_item(tp, rt) }}
1302 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1304 struct request *c = tp->tp_arg;
1305 struct transport *t = c->t;
1306 struct repo_dir *repo_dir = t->repo_dir;
1310 char *tag_name = rt->tag_name;
1311 struct gotweb_url tag = {
1315 .path = repo_dir->name,
1316 .commit = rt->commit_id,
1319 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1322 if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1324 r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1329 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1332 {{ render gotweb_render_absolute_url(c, &tag) }}
1336 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1338 {{ render rss_author(tp, rt->tagger) }}
1339 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1346 {{ define rss_author(struct template *tp, char *author) }}
1350 /* what to do if the author name contains a paren? */
1351 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1354 t = strchr(author, '<');
1360 while (isspace((unsigned char)*--t))
1363 t = strchr(mail, '>');
1369 {{ mail }} {{" "}} ({{ author }})