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 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));
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;
174 u_path.action = SUMMARY;
179 <meta charset="utf-8" />
180 <title>{{ srv->site_name }}</title>
181 <meta name="viewport" content="initial-scale=1.0" />
182 <meta name="msapplication-TileColor" content="#da532c" />
183 <meta name="theme-color" content="#ffffff"/>
184 <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
185 <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
186 <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
187 <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
188 <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
189 <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
194 <a href="{{ srv->logo_url }}" target="_blank">
195 <img src="{{ prfx }}{{ srv->logo }}" />
201 <a href="?index_page={{ printf "%d", qs->index_page }}">
205 {! u_path.path = qs->path; !}
207 <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
211 {{ if qs->action == SUMMARY || qs->action == DIFF ||
212 qs->action == TAG || qs->action == TAGS }}
213 {{ " / " }}{{ gotweb_action_name(qs->action) }}
214 {{ else if qs->action != INDEX}}
215 {{ render breadcumbs(tp) }}
220 {{ render body(tp) }}
222 <footer id="site_owner_wrapper">
224 {{ if srv->show_site_owner }}
225 {{ srv->site_owner }}
233 {{ define gotweb_render_error(struct template *tp) }}
235 struct request *c = tp->tp_arg;
236 struct transport *t = c->t;
238 <div id="err_content">
242 See daemon logs for details
247 {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
249 struct request *c = tp->tp_arg;
250 struct server *srv = c->srv;
252 <div id="index_header">
253 <div class="index_project">
256 {{ if srv->show_repo_description }}
257 <div class="index_project_description">
261 {{ if srv->show_repo_owner }}
262 <div class="index_project_owner">
266 {{ if srv->show_repo_age }}
267 <div class="index_project_age">
274 {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
276 struct request *c = tp->tp_arg;
277 struct server *srv = c->srv;
278 struct gotweb_url summary = {
281 .path = repo_dir->name,
285 .path = repo_dir->name,
289 .path = repo_dir->name,
293 .path = repo_dir->name,
297 .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){
355 .path = repo_dir->name,
356 .headref = qs->headref,
358 patch_url = (struct gotweb_url){
361 .path = repo_dir->name,
362 .headref = qs->headref,
364 tree_url = (struct gotweb_url){
367 .path = repo_dir->name,
368 .headref = qs->headref,
371 <header class='subtitle'>
372 <h2>Commit Briefs</h2>
374 <div id="briefs_content">
375 {{ tailq-foreach rc &t->repo_commits entry }}
377 diff_url.commit = rc->commit_id;
378 patch_url.commit = rc->commit_id;
379 tree_url.commit = rc->commit_id;
381 tmp = strchr(rc->committer, '<');
385 body = strchr(rc->commit_msg, '\n');
388 while (*body == '\n')
393 <p class='brief_meta'>
394 <span class='briefs_age'>
395 {{ render datetime(tp, rc->committer_time, TM_DIFF) }}
398 <span class="briefs_author">
402 {{ if body && *body != '\0' }}
403 <details class="briefs_log">
405 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
408 {{ if rc->refs_str }}
409 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
412 <span class="briefs_toggle" aria-hidden="true">
420 <p class="briefs_log">
421 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
424 {{ if rc->refs_str }}
425 {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
430 <div class="navs_wrapper">
432 <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
434 <a href="{{ render gotweb_render_url(tp->tp_arg, &patch_url) }}">patch</a>
436 <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
441 {{ render gotweb_render_more(tp, BRIEFS) }}
445 {{ define gotweb_render_more(struct template *tp, int action) }}
447 struct request *c = tp->tp_arg;
448 struct transport *t = c->t;
449 struct querystring *qs = t->qs;
450 struct gotweb_url more = {
454 .commit = t->more_id,
455 .headref = qs->headref,
460 more.commit = t->tags_more_id;
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 gotweb_url prev, next;
477 int have_prev, have_next;
479 gotweb_index_navs(c, &prev, &have_prev, &next, &have_next);
481 <div id="np_wrapper">
484 <a href="{{ render gotweb_render_url(c, &prev) }}">
491 <a href="{{ render gotweb_render_url(c, &next) }}">
499 {{ define gotweb_render_commits(struct template *tp) }}
501 struct request *c = tp->tp_arg;
502 struct transport *t = c->t;
503 struct repo_dir *repo_dir = t->repo_dir;
504 struct repo_commit *rc;
505 struct gotweb_url diff, patch, tree;
507 diff = (struct gotweb_url){
510 .path = repo_dir->name,
512 patch = (struct gotweb_url){
515 .path = repo_dir->name,
517 tree = (struct gotweb_url){
520 .path = repo_dir->name,
523 <header class="subtitle">
526 <div class="commits_content">
527 {{ tailq-foreach rc &t->repo_commits entry }}
529 diff.commit = rc->commit_id;
530 patch.commit = rc->commit_id;
531 tree.commit = rc->commit_id;
533 <div class="page_header_wrapper">
536 <dd><code class="commit-id">{{ rc->commit_id }}</code></dd>
538 <dd>{{ rc->author }}</dd>
539 {{ if strcmp(rc->committer, rc->author) != 0 }}
541 <dd>{{ rc->committer }}</dd>
545 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
554 <div class="navs_wrapper">
556 <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
558 <a href="{{ render gotweb_render_url(c, &patch) }}">patch</a>
560 <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
565 {{ render gotweb_render_more(tp, COMMITS) }}
569 {{ define gotweb_render_blob(struct template *tp) }}
571 struct request *c = tp->tp_arg;
572 struct transport *t = c->t;
573 struct querystring *qs = t->qs;
574 struct got_blob_object *blob = t->blob;
575 struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits);
576 struct gotweb_url briefs_url, blame_url, raw_url;
578 memset(&briefs_url, 0, sizeof(briefs_url));
579 briefs_url.index_page = -1,
580 briefs_url.action = BRIEFS,
581 briefs_url.path = qs->path,
582 briefs_url.commit = qs->commit,
583 briefs_url.folder = qs->folder,
584 briefs_url.file = qs->file,
586 memcpy(&blame_url, &briefs_url, sizeof(blame_url));
587 blame_url.action = BLAME;
589 memcpy(&raw_url, &briefs_url, sizeof(raw_url));
590 raw_url.action = BLOBRAW;
592 <header class="subtitle">
595 <div id="blob_content">
596 <div class="page_header_wrapper">
600 {{ render datetime(tp, rc->committer_time, TM_LONG) }}
603 <dd class="commit-msg">{{ rc->commit_msg }}</dd>
606 <a href="{{ render gotweb_render_url(c, &briefs_url) }}">
610 <a href="{{ render gotweb_render_url(c, &blame_url) }}">
614 <a href="{{ render gotweb_render_url(c, &raw_url) }}">
623 {{ render got_output_blob_by_lines(tp, blob, gotweb_render_blob_line) }}
629 {{ define gotweb_render_blob_line(struct template *tp, const char *line,
635 r = snprintf(lineno, sizeof(lineno), "%zu", no);
636 if (r < 0 || (size_t)r >= sizeof(lineno))
639 <div class="blob_line" id="line{{ lineno }}">
640 <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 }})