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"
46 static int breadcumbs(struct template *);
47 static int datetime(struct template *, time_t, int);
48 static int gotweb_render_blob_line(struct template *, const char *, size_t);
49 static int gotweb_render_tree_item(struct template *, struct got_tree_entry *);
50 static int blame_line(struct template *, const char *, struct blame_line *,
53 static inline int gotweb_render_more(struct template *, int);
55 static inline int tree_listing(struct template *);
56 static inline int diff_line(struct template *, char *);
57 static inline int tag_item(struct template *, struct repo_tag *);
58 static inline int branch(struct template *, struct got_reflist_entry *);
59 static inline int rss_tag_item(struct template *, struct repo_tag *);
60 static inline int rss_author(struct template *, char *);
63 nextsep(char *s, char **t)
81 {{ define datetime(struct template *tp, time_t t, int fmt) }}
87 if (gmtime_r(&t, &tm) == NULL)
90 if (strftime(rfc3339, sizeof(rfc3339), "%FT%TZ", &tm) == 0)
93 if (fmt != TM_DIFF && asctime_r(&tm, datebuf) == NULL)
96 <time datetime="{{ rfc3339 }}">
97 {{ if fmt == TM_DIFF }}
98 {{ render gotweb_render_age(tp, t) }}
100 {{ datebuf }} {{ " UTC" }}
105 {{ define breadcumbs(struct template *tp) }}
107 struct request *c = tp->tp_arg;
108 struct querystring *qs = c->t->qs;
109 struct gotweb_url url;
110 const char *folder = qs->folder;
111 const char *action = "tree";
112 char *t, *s = NULL, *dir = NULL;
115 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;
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 = {
282 .path = repo_dir->name,
286 .path = repo_dir->name,
290 .path = repo_dir->name,
294 .path = repo_dir->name,
298 .path = repo_dir->name,
302 .path = repo_dir->name,
305 <div class="index_wrapper">
306 <div class="index_project">
307 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
309 {{ if srv->show_repo_description }}
310 <div class="index_project_description">
311 {{ repo_dir->description }}
314 {{ if srv->show_repo_owner }}
315 <div class="index_project_owner">
316 {{ repo_dir->owner }}
319 {{ if srv->show_repo_age }}
320 <div class="index_project_age">
321 {{ render datetime(tp, repo_dir->age, TM_DIFF) }}
324 <div class="navs_wrapper">
326 <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
328 <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
330 <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
332 <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
334 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
336 <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
343 {{ define gotweb_render_briefs(struct template *tp) }}
345 struct request *c = tp->tp_arg;
346 struct transport *t = c->t;
347 struct querystring *qs = c->t->qs;
348 struct repo_commit *rc;
349 struct repo_dir *repo_dir = t->repo_dir;
350 struct gotweb_url diff_url, patch_url, tree_url;
353 diff_url = (struct gotweb_url){
356 .path = repo_dir->name,
357 .headref = qs->headref,
359 patch_url = (struct gotweb_url){
362 .path = repo_dir->name,
363 .headref = qs->headref,
365 tree_url = (struct gotweb_url){
368 .path = repo_dir->name,
369 .headref = qs->headref,
372 <header class='subtitle'>
373 <h2>Commit Briefs</h2>
375 <div id="briefs_content">
376 {{ tailq-foreach rc &t->repo_commits entry }}
378 diff_url.commit = rc->commit_id;
379 patch_url.commit = rc->commit_id;
380 tree_url.commit = rc->commit_id;
382 tmp = strchr(rc->committer, '<');
386 body = strchr(rc->commit_msg, '\n');
389 while (*body == '\n')
394 <p class='brief_meta'>
395 <span class='briefs_age'>
396 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
399 <span class="briefs_author">
403 {{ if body && *body != '\0' }}
404 <details class="briefs_log">
406 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
409 {{ if rc->refs_str }}
410 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
413 <span class="briefs_toggle" aria-hidden="true">
421 <p class="briefs_log">
422 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
425 {{ if rc->refs_str }}
426 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
431 <div class="navs_wrapper">
433 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
435 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
437 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
442 {{ render gotweb_render_more(tp, BRIEFS) }}
446 {{ define gotweb_render_more(struct template *tp, int action) }}
448 struct request *c = tp->tp_arg;
449 struct transport *t = c->t;
450 struct querystring *qs = t->qs;
451 struct gotweb_url more = {
455 .commit = t->more_id,
456 .headref = qs->headref,
461 more.commit = t->tags_more_id;
464 <div id="np_wrapper">
466 <a href="{{ render gotweb_render_url(c, &more) }}">
474 {{ define gotweb_render_navs(struct template *tp) }}
476 struct request *c = tp->tp_arg;
477 struct gotweb_url prev, next;
478 int have_prev, have_next;
480 gotweb_index_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) }}">
500 {{ define gotweb_render_commits(struct template *tp) }}
502 struct request *c = tp->tp_arg;
503 struct transport *t = c->t;
504 struct repo_dir *repo_dir = t->repo_dir;
505 struct repo_commit *rc;
506 struct gotweb_url diff, patch, tree;
508 diff = (struct gotweb_url){
511 .path = repo_dir->name,
513 patch = (struct gotweb_url){
516 .path = repo_dir->name,
518 tree = (struct gotweb_url){
521 .path = repo_dir->name,
524 <header class="subtitle">
527 <div class="commits_content">
528 {{ tailq-foreach rc &t->repo_commits entry }}
530 diff.commit = rc->commit_id;
531 patch.commit = rc->commit_id;
532 tree.commit = rc->commit_id;
534 <div class="page_header_wrapper">
537 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
539 <dd>{{ rc->author }}</dd>
540 {{ if strcmp(rc->committer, rc->author) != 0 }}
542 <dd>{{ rc->committer }}</dd>
546 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
555 <div class="navs_wrapper">
557 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
559 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
561 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
566 {{ render gotweb_render_more(tp, COMMITS) }}
570 {{ define gotweb_render_blob(struct template *tp) }}
572 struct request *c = tp->tp_arg;
573 struct transport *t = c->t;
574 struct querystring *qs = t->qs;
575 struct got_blob_object *blob = t->blob;
576 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
577 struct gotweb_url briefs_url, blame_url, raw_url;
579 memset(&briefs_url, 0, sizeof(briefs_url));
580 briefs_url.index_page = -1,
581 briefs_url.action = BRIEFS,
582 briefs_url.path = qs->path,
583 briefs_url.commit = qs->commit,
584 briefs_url.folder = qs->folder,
585 briefs_url.file = qs->file,
587 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
588 blame_url.action = BLAME;
590 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
591 raw_url.action = BLOBRAW;
593 <header class="subtitle">
596 <div id="blob_content">
597 <div class="page_header_wrapper">
601 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
604 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
607 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
611 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
615 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
624 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
630 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
636 r = snprintf(lineno, sizeof(lineno), "%zu", no);
637 if (r < 0 || (size_t)r >= sizeof(lineno))
640 <div class="blob_line" id="line{{ lineno }}">
641 <a href="#line{{ lineno }}">{{ lineno }}{{" "}}</a>
642 <span class="blob_code">{{ line }}</span>
646 {{ define tree_listing(struct template *tp) }}
648 const struct got_error *error;
649 struct request *c = tp->tp_arg;
650 struct transport *t = c->t;
651 struct querystring *qs = c->t->qs;
652 struct gotweb_url url;
659 {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }}
663 error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c,
664 qs->folder, readme, qs->commit);
670 memset(&url, 0, sizeof(url));
673 url.path = t->qs->path;
675 url.folder = t->qs->folder;
676 url.commit = t->qs->commit;
680 <a href="{{ render gotweb_render_url(c, &url) }}">
687 error = got_object_blob_read_block(&len, t->blob);
694 buf = got_object_blob_get_read_buf(t->blob);
695 if (tp_write_htmlescape(tp, buf, len) == -1) {
708 {{ define gotweb_render_tree(struct template *tp) }}
710 struct request *c = tp->tp_arg;
711 struct transport *t = c->t;
712 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
714 <header class='subtitle'>
717 <div id="tree_content">
718 <div class="page_header_wrapper">
721 <dd><code class="commit-id">{{ rc->tree_id }}</code></dd>
724 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
727 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
731 {{ render tree_listing(tp) }}
735 {{ define gotweb_render_tree_item(struct template *tp,
736 struct got_tree_entry *te) }}
738 struct request *c = tp->tp_arg;
739 struct transport *t = c->t;
740 struct querystring *qs = t->qs;
741 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
742 const char *modestr = "";
747 struct gotweb_url url = {
749 .commit = rc->commit_id,
753 name = got_tree_entry_get_name(te);
754 mode = got_tree_entry_get_mode(te);
756 folder = qs->folder ? qs->folder : "";
758 if (asprintf(&dir, "%s/%s", folder, name) == -1)
769 if (got_object_tree_entry_is_submodule(te))
771 else if (S_ISLNK(mode))
773 else if (S_ISDIR(mode))
775 else if (mode & S_IXUSR)
778 <tr class="tree_wrapper">
779 {{ if S_ISDIR(mode) }}
780 <td class="tree_line" colspan=2>
781 <a href="{{ render gotweb_render_url(c, &url) }}">
782 {{ name }}{{ modestr }}
786 <td class="tree_line">
787 <a href="{{ render gotweb_render_url(c, &url) }}">
788 {{ name }}{{ modestr }}
791 <td class="tree_line_blank">
792 {! url.action = COMMITS; !}
793 <a href="{{ render gotweb_render_url(c, &url) }}">
797 {! url.action = BLAME; !}
798 <a href="{{ render gotweb_render_url(c, &url) }}">
810 {{ define gotweb_render_tags(struct template *tp) }}
812 struct request *c = tp->tp_arg;
813 struct transport *t = c->t;
814 struct querystring *qs = t->qs;
818 commit_found = qs->commit == NULL;
820 <header class='subtitle'>
823 <div id="tags_content">
824 {{ if t->tag_count == 0 }}
825 <div id="err_content">
826 This repository contains no tags
829 {{ tailq-foreach rt &t->repo_tags entry }}
830 {{ if commit_found || !strcmp(qs->commit, rt->commit_id) }}
831 {! commit_found = 1; !}
832 {{ render tag_item(tp, rt) }}
835 {{ render gotweb_render_more(tp, TAGS) }}
840 {{ define tag_item(struct template *tp, struct repo_tag *rt) }}
842 struct request *c = tp->tp_arg;
843 struct transport *t = c->t;
844 struct repo_dir *repo_dir = t->repo_dir;
845 char *tag_name = rt->tag_name;
846 char *msg = rt->tag_commit;
848 struct gotweb_url url = {
851 .path = repo_dir->name,
852 .commit = rt->commit_id,
855 if (strncmp(tag_name, "refs/tags/", 10) == 0)
859 nl = strchr(msg, '\n');
864 <div class="tag_age">
865 {{ render datetime(tp, rt->tagger_time, TM_DIFF) }}
867 <div class="tag_name">{{ tag_name }}</div>
868 <div class="tag_log">
869 <a href="{{ render gotweb_render_url(c, &url) }}">
873 <div class="navs_wrapper">
875 <a href="{{ render gotweb_render_url(c, &url) }}">tag</a>
877 {! url.action = BRIEFS; !}
878 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
880 {! url.action = COMMITS; !}
881 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
887 {{ define gotweb_render_tag(struct template *tp) }}
889 struct request *c = tp->tp_arg;
890 struct transport *t = c->t;
892 const char *tag_name;
894 rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
895 tag_name = rt->tag_name;
897 if (strncmp(tag_name, "refs/", 5) == 0)
900 <header class="subtitle">
903 <div id="tags_content">
904 <div class="page_header_wrapper">
908 <code class="commit-id">{{ rt->commit_id }}</code>
910 <span class="refs_str">({{ tag_name }})</span>
913 <dd>{{ rt->tagger }}</dd>
916 {{ render datetime(tp, rt->tagger_time, TM_LONG)}}
919 <dd class="commit-msg">{{ rt->commit_msg }}</dd>
922 <pre id="tag_commit">
929 {{ define gotweb_render_diff(struct template *tp) }}
931 struct request *c = tp->tp_arg;
932 struct transport *t = c->t;
933 struct querystring *qs = t->qs;
935 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
939 struct gotweb_url patch_url, tree_url = {
943 .commit = rc->commit_id,
946 memcpy(&patch_url, &tree_url, sizeof(patch_url));
947 patch_url.action = PATCH;
949 <header class="subtitle">
952 <div id="diff_content">
953 <div class="page_header_wrapper">
956 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
958 <dd>{{ rc->author }}</dd>
959 {{ if strcmp(rc->committer, rc->author) != 0 }}
961 <dd>{{ rc->committer }}</dd>
965 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
968 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
971 <a href="{{ render gotweb_render_url(c, &patch_url) }}">
975 <a href="{{ render gotweb_render_url(c, &tree_url) }}">
983 {{ while (linelen = getline(&line, &linesize, fp)) != -1 }}
984 {{ render diff_line(tp, line) }}
992 {{ define diff_line(struct template *tp, char *line )}}
994 const char *color = NULL;
997 if (!strncmp(line, "-", 1))
998 color = "diff_minus";
999 else if (!strncmp(line, "+", 1))
1000 color = "diff_plus";
1001 else if (!strncmp(line, "@@", 2))
1002 color = "diff_chunk_header";
1003 else if (!strncmp(line, "commit +", 8) ||
1004 !strncmp(line, "commit -", 8) ||
1005 !strncmp(line, "blob +", 6) ||
1006 !strncmp(line, "blob -", 6) ||
1007 !strncmp(line, "file +", 6) ||
1008 !strncmp(line, "file -", 6))
1009 color = "diff_meta";
1010 else if (!strncmp(line, "from:", 5) || !strncmp(line, "via:", 4))
1011 color = "diff_author";
1012 else if (!strncmp(line, "date:", 5))
1013 color = "diff_date";
1015 nl = strchr(line, '\n');
1019 <span class="diff_line {{ color }}">{{ line }}</span>{{"\n"}}
1022 {{ define gotweb_render_branches(struct template *tp,
1023 struct got_reflist_head *refs) }}
1025 struct got_reflist_entry *re;
1027 <header class='subtitle'>
1030 <div id="branches_content">
1031 {{ tailq-foreach re refs entry }}
1032 {{ if !got_ref_is_symbolic(re->ref) }}
1033 {{ render branch(tp, re) }}
1039 {{ define branch(struct template *tp, struct got_reflist_entry *re) }}
1041 const struct got_error *err;
1042 struct request *c = tp->tp_arg;
1043 struct querystring *qs = c->t->qs;
1044 const char *refname;
1046 struct gotweb_url url = {
1052 refname = got_ref_get_name(re->ref);
1054 err = got_get_repo_age(&age, c, refname);
1056 log_warnx("%s: %s", __func__, err->msg);
1060 if (strncmp(refname, "refs/heads/", 11) == 0)
1063 url.headref = refname;
1065 <section class="branches_wrapper">
1066 <div class="branches_age">
1067 {{ render datetime(tp, age, TM_DIFF) }}
1069 <div class="branch">
1070 <a href="{{ render gotweb_render_url(c, &url) }}">{{ refname }}</a>
1072 <div class="navs_wrapper">
1074 <a href="{{ render gotweb_render_url(c, &url) }}">summary</a>
1076 {! url.action = BRIEFS; !}
1077 <a href="{{ render gotweb_render_url(c, &url) }}">commit briefs</a>
1079 {! url.action = COMMITS; !}
1080 <a href="{{ render gotweb_render_url(c, &url) }}">commits</a>
1087 {{ define gotweb_render_summary(struct template *tp) }}
1089 struct request *c = tp->tp_arg;
1090 struct server *srv = c->srv;
1091 struct transport *t = c->t;
1092 struct got_reflist_head *refs = &t->refs;
1094 <dl id="summary_wrapper" class="page_header_wrapper">
1095 {{ if srv->show_repo_description }}
1096 <dt>Description:</dt>
1097 <dd>{{ t->repo_dir->description }}</dd>
1099 {{ if srv->show_repo_owner }}
1101 <dd>{{ t->repo_dir->owner }}</dd>
1103 {{ if srv->show_repo_age }}
1104 <dt>Last Change:</dt>
1106 {{ render datetime(tp, t->repo_dir->age, TM_DIFF) }}
1109 {{ if srv->show_repo_cloneurl }}
1111 <dd><pre class="clone-url">{{ t->repo_dir->url }}</pre></dd>
1114 {{ render gotweb_render_briefs(tp) }}
1115 {{ render gotweb_render_branches(tp, refs) }}
1116 {{ render gotweb_render_tags(tp) }}
1117 <header class='subtitle'>
1120 <div id="tree_content">
1121 {{ render tree_listing(tp) }}
1125 {{ define gotweb_render_blame(struct template *tp) }}
1127 const struct got_error *err;
1128 struct request *c = tp->tp_arg;
1129 struct transport *t = c->t;
1130 struct querystring *qs = t->qs;
1131 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1132 struct gotweb_url briefs_url, blob_url, raw_url;
1134 memset(&briefs_url, 0, sizeof(briefs_url));
1135 briefs_url.index_page = -1,
1136 briefs_url.action = BRIEFS,
1137 briefs_url.path = qs->path,
1138 briefs_url.commit = qs->commit,
1139 briefs_url.folder = qs->folder,
1140 briefs_url.file = qs->file,
1142 memcpy(&blob_url, &briefs_url, sizeof(blob_url));
1143 blob_url.action = BLOB;
1145 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
1146 raw_url.action = BLOBRAW;
1148 <header class="subtitle">
1151 <div id="blame_content">
1152 <div class="page_header_wrapper">
1156 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
1159 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
1162 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
1166 <a href="{{ render gotweb_render_url(c, &blob_url) }}">
1170 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
1179 err = got_output_file_blame(c, &blame_line);
1180 if (err && err->code != GOT_ERR_CANCELLED)
1181 log_warnx("%s: got_output_file_blame: %s", __func__,
1190 {{ define blame_line(struct template *tp, const char *line,
1191 struct blame_line *bline, int lprec, int lcur) }}
1193 struct request *c = tp->tp_arg;
1194 struct transport *t = c->t;
1195 struct repo_dir *repo_dir = t->repo_dir;
1196 char *committer, *s;
1197 struct gotweb_url url = {
1200 .path = repo_dir->name,
1201 .commit = bline->id_str,
1204 s = strchr(bline->committer, '<');
1205 committer = s ? s + 1 : bline->committer;
1207 s = strchr(committer, '@');
1211 <div class="blame_line">
1212 <span class="blame_number">{{ printf "%*d ", lprec, lcur }}</span>
1213 <span class="blame_hash">
1214 <a href="{{ render gotweb_render_url(c, &url) }}">
1215 {{ printf "%.8s", bline->id_str }}
1219 <span class="blame_date">{{ bline->datebuf }}</span>
1221 <span class="blame_author">{{ printf "%.9s", committer }}</span>
1223 <span class="blame_code">{{ line }}</span>
1227 {{ define gotweb_render_patch(struct template *tp) }}
1229 struct request *c = tp->tp_arg;
1230 struct transport *t = c->t;
1231 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
1233 char buf[BUFSIZ], datebuf[64];
1236 if (gmtime_r(&rc->committer_time, &tm) == NULL ||
1237 strftime(datebuf, sizeof(datebuf), "%a %b %d %T %Y UTC", &tm) == 0)
1240 commit {{ rc->commit_id }} {{ "\n" }}
1241 from: {{ rc->author | unsafe }} {{ "\n" }}
1242 {{ if strcmp(rc->committer, rc->author) != 0 }}
1243 via: {{ rc->committer | unsafe }} {{ "\n" }}
1245 date: {{ datebuf }} {{ "\n" }}
1247 {{ rc->commit_msg | unsafe }} {{ "\n" }}
1249 if (template_flush(tp) == -1)
1252 r = fread(buf, 1, sizeof(buf), t->fp);
1253 if (fcgi_write(c, buf, r) == -1 ||
1260 {{ define gotweb_render_rss(struct template *tp) }}
1262 struct request *c = tp->tp_arg;
1263 struct server *srv = c->srv;
1264 struct transport *t = c->t;
1265 struct repo_dir *repo_dir = t->repo_dir;
1266 struct repo_tag *rt;
1267 struct gotweb_url summary = {
1270 .path = repo_dir->name,
1273 <?xml version="1.0" encoding="UTF-8"?>
1274 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
1276 <title>Tags of {{ repo_dir->name }}</title>
1279 {{ render gotweb_render_absolute_url(c, &summary) }}
1282 {{ if srv->show_repo_description }}
1283 <description>{{ repo_dir->description }}</description>
1285 {{ tailq-foreach rt &t->repo_tags entry }}
1286 {{ render rss_tag_item(tp, rt) }}
1292 {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
1294 struct request *c = tp->tp_arg;
1295 struct transport *t = c->t;
1296 struct repo_dir *repo_dir = t->repo_dir;
1300 char *tag_name = rt->tag_name;
1301 struct gotweb_url tag = {
1304 .path = repo_dir->name,
1305 .commit = rt->commit_id,
1308 if (strncmp(tag_name, "refs/tags/", 10) == 0)
1311 if (gmtime_r(&rt->tagger_time, &tm) == NULL)
1313 r = strftime(rfc822, sizeof(rfc822), "%a, %d %b %Y %H:%M:%S GMT", &tm);
1318 <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
1321 {{ render gotweb_render_absolute_url(c, &tag) }}
1325 <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
1327 {{ render rss_author(tp, rt->tagger) }}
1328 <guid isPermaLink="false">{{ rt->commit_id }}</guid>
1335 {{ define rss_author(struct template *tp, char *author) }}
1339 /* what to do if the author name contains a paren? */
1340 if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
1343 t = strchr(author, '<');
1349 while (isspace((unsigned char)*--t))
1352 t = strchr(mail, '>');
1358 {{ mail }} {{" "}} ({{ author }})