Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 1 | /* ui-shared.c: common web output functions |
| 2 | * |
Lukas Fleischer | f7f26f8 | 2014-01-08 15:10:49 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-shared.h" |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 11 | #include "cmd.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 12 | #include "html.h" |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 13 | |
John Keeping | 0f23d46 | 2015-03-08 16:32:22 +0000 | [diff] [blame] | 14 | static const char cgit_doctype[] = |
Juuso Lapinlampi | 8d05b39 | 2016-05-11 18:04:14 +0000 | [diff] [blame] | 15 | "<!DOCTYPE html>\n"; |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 16 | |
| 17 | static char *http_date(time_t t) |
| 18 | { |
Lars Hjemli | 6fb7d09 | 2007-05-15 00:22:03 +0200 | [diff] [blame] | 19 | static char day[][4] = |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
Lars Hjemli | 6fb7d09 | 2007-05-15 00:22:03 +0200 | [diff] [blame] | 21 | static char month[][4] = |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
Danijel TaĊĦov | e34a3b5 | 2009-11-02 22:10:04 +0100 | [diff] [blame] | 23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 24 | struct tm *tm = gmtime(&t); |
| 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 26 | tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year, |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 28 | } |
| 29 | |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 30 | void cgit_print_error(const char *fmt, ...) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 31 | { |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 32 | va_list ap; |
| 33 | va_start(ap, fmt); |
| 34 | cgit_vprint_error(fmt, ap); |
| 35 | va_end(ap); |
| 36 | } |
| 37 | |
| 38 | void cgit_vprint_error(const char *fmt, va_list ap) |
| 39 | { |
| 40 | va_list cp; |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 41 | html("<div class='error'>"); |
John Keeping | ed5bd30 | 2013-04-06 11:23:52 +0100 | [diff] [blame] | 42 | va_copy(cp, ap); |
| 43 | html_vtxtf(fmt, cp); |
| 44 | va_end(cp); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 45 | html("</div>\n"); |
| 46 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 47 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 48 | const char *cgit_httpscheme(void) |
Diego Ongaro | 87a89ae | 2009-06-10 18:09:55 -0500 | [diff] [blame] | 49 | { |
Lars Hjemli | 60a2627 | 2009-08-10 08:21:09 +0200 | [diff] [blame] | 50 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
Diego Ongaro | 87a89ae | 2009-06-10 18:09:55 -0500 | [diff] [blame] | 51 | return "https://"; |
| 52 | else |
| 53 | return "http://"; |
| 54 | } |
| 55 | |
Christian Hesse | f77e2a8 | 2015-10-09 13:15:50 +0200 | [diff] [blame] | 56 | char *cgit_hosturl(void) |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 57 | { |
Lars Hjemli | 60a2627 | 2009-08-10 08:21:09 +0200 | [diff] [blame] | 58 | if (ctx.env.http_host) |
Christian Hesse | f77e2a8 | 2015-10-09 13:15:50 +0200 | [diff] [blame] | 59 | return xstrdup(ctx.env.http_host); |
Lars Hjemli | 60a2627 | 2009-08-10 08:21:09 +0200 | [diff] [blame] | 60 | if (!ctx.env.server_name) |
| 61 | return NULL; |
| 62 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) |
Christian Hesse | f77e2a8 | 2015-10-09 13:15:50 +0200 | [diff] [blame] | 63 | return xstrdup(ctx.env.server_name); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 64 | return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Christian Hesse | c5c0eb8 | 2015-10-09 13:15:47 +0200 | [diff] [blame] | 67 | char *cgit_currenturl(void) |
Jason A. Donenfeld | 6bcda2f | 2015-03-03 17:18:42 +0100 | [diff] [blame] | 68 | { |
| 69 | if (!ctx.qry.url) |
Christian Hesse | c5c0eb8 | 2015-10-09 13:15:47 +0200 | [diff] [blame] | 70 | return xstrdup(cgit_rooturl()); |
Jason A. Donenfeld | 8eef458 | 2015-03-08 12:34:07 +0100 | [diff] [blame] | 71 | const char *root = cgit_rooturl(); |
| 72 | size_t len = strlen(root); |
| 73 | if (len && root[len - 1] == '/') |
| 74 | return fmtalloc("%s%s", root, ctx.qry.url); |
| 75 | return fmtalloc("%s/%s", root, ctx.qry.url); |
Jason A. Donenfeld | 6bcda2f | 2015-03-03 17:18:42 +0100 | [diff] [blame] | 76 | } |
| 77 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 78 | const char *cgit_rooturl(void) |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 79 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 80 | if (ctx.cfg.virtual_root) |
John Keeping | b1f17f1 | 2013-04-01 19:03:34 +0100 | [diff] [blame] | 81 | return ctx.cfg.virtual_root; |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 82 | else |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 83 | return ctx.cfg.script_name; |
Lars Hjemli | 66cacd0 | 2007-02-17 13:46:18 +0100 | [diff] [blame] | 84 | } |
| 85 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 86 | const char *cgit_loginurl(void) |
Jason A. Donenfeld | a431326 | 2014-01-16 23:21:54 +0100 | [diff] [blame] | 87 | { |
John Keeping | 94e5f21 | 2015-03-08 16:32:24 +0000 | [diff] [blame] | 88 | static const char *login_url; |
Jason A. Donenfeld | a431326 | 2014-01-16 23:21:54 +0100 | [diff] [blame] | 89 | if (!login_url) |
| 90 | login_url = fmtalloc("%s?p=login", cgit_rooturl()); |
| 91 | return login_url; |
| 92 | } |
| 93 | |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 94 | char *cgit_repourl(const char *reponame) |
| 95 | { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 96 | if (ctx.cfg.virtual_root) |
| 97 | return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame); |
| 98 | else |
| 99 | return fmtalloc("?r=%s", reponame); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 102 | char *cgit_fileurl(const char *reponame, const char *pagename, |
| 103 | const char *filename, const char *query) |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 104 | { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 105 | struct strbuf sb = STRBUF_INIT; |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 106 | char *delim; |
| 107 | |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 108 | if (ctx.cfg.virtual_root) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 109 | strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame, |
| 110 | pagename, (filename ? filename:"")); |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 111 | delim = "?"; |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 112 | } else { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 113 | strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename, |
| 114 | (filename ? filename : "")); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 115 | delim = "&"; |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 116 | } |
Lars Hjemli | 68cf9b4 | 2007-11-03 11:15:56 +0100 | [diff] [blame] | 117 | if (query) |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 118 | strbuf_addf(&sb, "%s%s", delim, query); |
| 119 | return strbuf_detach(&sb, NULL); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 122 | char *cgit_pageurl(const char *reponame, const char *pagename, |
| 123 | const char *query) |
| 124 | { |
John Keeping | d34b967 | 2015-03-08 16:32:25 +0000 | [diff] [blame] | 125 | return cgit_fileurl(reponame, pagename, NULL, query); |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 128 | const char *cgit_repobasename(const char *reponame) |
| 129 | { |
| 130 | /* I assume we don't need to store more than one repo basename */ |
| 131 | static char rvbuf[1024]; |
| 132 | int p; |
| 133 | const char *rv; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 134 | strncpy(rvbuf, reponame, sizeof(rvbuf)); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 135 | if (rvbuf[sizeof(rvbuf)-1]) |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 136 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
| 137 | p = strlen(rvbuf)-1; |
| 138 | /* strip trailing slashes */ |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 139 | while (p && rvbuf[p] == '/') rvbuf[p--] = 0; |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 140 | /* strip trailing .git */ |
Christian Hesse | 79c985e | 2014-05-29 17:35:46 +0200 | [diff] [blame] | 141 | if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) { |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 142 | p -= 3; rvbuf[p--] = 0; |
| 143 | } |
| 144 | /* strip more trailing slashes if any */ |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 145 | while ( p && rvbuf[p] == '/') rvbuf[p--] = 0; |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 146 | /* find last slash in the remaining string */ |
| 147 | rv = strrchr(rvbuf,'/'); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 148 | if (rv) |
Michael Krelin | 1cb8bed | 2007-07-21 15:24:07 +0200 | [diff] [blame] | 149 | return ++rv; |
| 150 | return rvbuf; |
| 151 | } |
Michael Krelin | 0df096f | 2007-07-21 13:13:40 +0200 | [diff] [blame] | 152 | |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 153 | static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 154 | { |
| 155 | char *delim = "?"; |
| 156 | |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 157 | if (always_root || page) |
Jason A. Donenfeld | db4b735 | 2015-03-03 17:13:52 +0100 | [diff] [blame] | 158 | html_attr(cgit_rooturl()); |
Christian Hesse | 3e244a0 | 2015-10-09 13:15:48 +0200 | [diff] [blame] | 159 | else { |
| 160 | char *currenturl = cgit_currenturl(); |
| 161 | html_attr(currenturl); |
| 162 | free(currenturl); |
| 163 | } |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 164 | |
| 165 | if (page) { |
| 166 | htmlf("?p=%s", page); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 167 | delim = "&"; |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 168 | } |
| 169 | if (search) { |
| 170 | html(delim); |
| 171 | html("q="); |
| 172 | html_attr(search); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 173 | delim = "&"; |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 174 | } |
Tobias Grimm | 7530d94 | 2011-07-31 02:44:05 +0200 | [diff] [blame] | 175 | if (sort) { |
| 176 | html(delim); |
| 177 | html("s="); |
| 178 | html_attr(sort); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 179 | delim = "&"; |
Tobias Grimm | 7530d94 | 2011-07-31 02:44:05 +0200 | [diff] [blame] | 180 | } |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 181 | if (ofs) { |
| 182 | html(delim); |
| 183 | htmlf("ofs=%d", ofs); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 187 | static void site_link(const char *page, const char *name, const char *title, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 188 | const char *class, const char *search, const char *sort, int ofs, int always_root) |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 189 | { |
| 190 | html("<a"); |
| 191 | if (title) { |
| 192 | html(" title='"); |
| 193 | html_attr(title); |
| 194 | html("'"); |
| 195 | } |
| 196 | if (class) { |
| 197 | html(" class='"); |
| 198 | html_attr(class); |
| 199 | html("'"); |
| 200 | } |
| 201 | html(" href='"); |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 202 | site_url(page, search, sort, ofs, always_root); |
Lars Hjemli | 71adba1 | 2008-04-29 01:09:41 +0200 | [diff] [blame] | 203 | html("'>"); |
| 204 | html_txt(name); |
| 205 | html("</a>"); |
| 206 | } |
| 207 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 208 | void cgit_index_link(const char *name, const char *title, const char *class, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 209 | const char *pattern, const char *sort, int ofs, int always_root) |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 210 | { |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 211 | site_link(NULL, name, title, class, pattern, sort, ofs, always_root); |
Lars Hjemli | 141f1c3 | 2008-05-03 10:37:02 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 214 | static char *repolink(const char *title, const char *class, const char *page, |
| 215 | const char *head, const char *path) |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 216 | { |
| 217 | char *delim = "?"; |
| 218 | |
| 219 | html("<a"); |
| 220 | if (title) { |
| 221 | html(" title='"); |
| 222 | html_attr(title); |
| 223 | html("'"); |
| 224 | } |
| 225 | if (class) { |
| 226 | html(" class='"); |
| 227 | html_attr(class); |
| 228 | html("'"); |
| 229 | } |
| 230 | html(" href='"); |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 231 | if (ctx.cfg.virtual_root) { |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 232 | html_url_path(ctx.cfg.virtual_root); |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 233 | html_url_path(ctx.repo->url); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 234 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 235 | html("/"); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 236 | if (page) { |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 237 | html_url_path(page); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 238 | html("/"); |
| 239 | if (path) |
Lars Hjemli | 44b208a | 2008-10-05 16:54:44 +0200 | [diff] [blame] | 240 | html_url_path(path); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 241 | } |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 242 | } else { |
John Keeping | a45030f | 2014-01-12 19:45:16 +0000 | [diff] [blame] | 243 | html_url_path(ctx.cfg.script_name); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 244 | html("?url="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 245 | html_url_arg(ctx.repo->url); |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 246 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 247 | html("/"); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 248 | if (page) { |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 249 | html_url_arg(page); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 250 | html("/"); |
| 251 | if (path) |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 252 | html_url_arg(path); |
Lars Hjemli | b8be028 | 2007-06-18 00:18:42 +0200 | [diff] [blame] | 253 | } |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 254 | delim = "&"; |
| 255 | } |
Eric Wong | 590ba45 | 2016-07-06 07:08:01 +0000 | [diff] [blame] | 256 | if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) { |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 257 | html(delim); |
| 258 | html("h="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 259 | html_url_arg(head); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 260 | delim = "&"; |
| 261 | } |
| 262 | return fmt("%s", delim); |
| 263 | } |
| 264 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 265 | static void reporevlink(const char *page, const char *name, const char *title, |
| 266 | const char *class, const char *head, const char *rev, |
| 267 | const char *path) |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 268 | { |
| 269 | char *delim; |
| 270 | |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 271 | delim = repolink(title, class, page, head, path); |
Florian Pritz | 8d94607 | 2010-02-01 17:55:37 +0100 | [diff] [blame] | 272 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 273 | html(delim); |
| 274 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 275 | html_url_arg(rev); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 276 | } |
| 277 | html("'>"); |
| 278 | html_txt(name); |
| 279 | html("</a>"); |
| 280 | } |
Lars Hjemli | 148fb96 | 2006-12-16 00:33:28 +0100 | [diff] [blame] | 281 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 282 | void cgit_summary_link(const char *name, const char *title, const char *class, |
| 283 | const char *head) |
Lars Hjemli | e9d3bd5 | 2008-10-05 16:55:50 +0200 | [diff] [blame] | 284 | { |
| 285 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
| 286 | } |
| 287 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 288 | void cgit_tag_link(const char *name, const char *title, const char *class, |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 289 | const char *tag) |
Lars Hjemli | cf61ad4 | 2008-10-05 21:18:45 +0200 | [diff] [blame] | 290 | { |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 291 | reporevlink("tag", name, title, class, tag, NULL, NULL); |
Lars Hjemli | cf61ad4 | 2008-10-05 21:18:45 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 294 | void cgit_tree_link(const char *name, const char *title, const char *class, |
| 295 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 296 | { |
| 297 | reporevlink("tree", name, title, class, head, rev, path); |
| 298 | } |
| 299 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 300 | void cgit_plain_link(const char *name, const char *title, const char *class, |
| 301 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 65b7b87 | 2008-08-06 11:07:13 +0200 | [diff] [blame] | 302 | { |
| 303 | reporevlink("plain", name, title, class, head, rev, path); |
| 304 | } |
| 305 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 306 | void cgit_log_link(const char *name, const char *title, const char *class, |
| 307 | const char *head, const char *rev, const char *path, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 308 | int ofs, const char *grep, const char *pattern, int showmsg, |
| 309 | int follow) |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 310 | { |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 311 | char *delim; |
| 312 | |
| 313 | delim = repolink(title, class, "log", head, path); |
Eric Wong | 21418ec | 2012-01-04 09:01:51 +0000 | [diff] [blame] | 314 | if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 315 | html(delim); |
| 316 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 317 | html_url_arg(rev); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 318 | delim = "&"; |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 319 | } |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 320 | if (grep && pattern) { |
| 321 | html(delim); |
| 322 | html("qt="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 323 | html_url_arg(grep); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 324 | delim = "&"; |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 325 | html(delim); |
| 326 | html("q="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 327 | html_url_arg(pattern); |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 328 | } |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 329 | if (ofs > 0) { |
| 330 | html(delim); |
| 331 | html("ofs="); |
| 332 | htmlf("%d", ofs); |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 333 | delim = "&"; |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 334 | } |
| 335 | if (showmsg) { |
| 336 | html(delim); |
| 337 | html("showmsg=1"); |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 338 | delim = "&"; |
| 339 | } |
| 340 | if (follow) { |
| 341 | html(delim); |
| 342 | html("follow=1"); |
Lars Hjemli | 103940f | 2007-06-29 20:27:41 +0200 | [diff] [blame] | 343 | } |
| 344 | html("'>"); |
| 345 | html_txt(name); |
| 346 | html("</a>"); |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 349 | void cgit_commit_link(char *name, const char *title, const char *class, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 350 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 351 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 352 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
| 353 | name[ctx.cfg.max_msg_len] = '\0'; |
| 354 | name[ctx.cfg.max_msg_len - 1] = '.'; |
| 355 | name[ctx.cfg.max_msg_len - 2] = '.'; |
| 356 | name[ctx.cfg.max_msg_len - 3] = '.'; |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 357 | } |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 358 | |
| 359 | char *delim; |
| 360 | |
Johan Herland | 685872b | 2010-06-10 01:09:35 +0200 | [diff] [blame] | 361 | delim = repolink(title, class, "commit", head, path); |
Eric Wong | 21418ec | 2012-01-04 09:01:51 +0000 | [diff] [blame] | 362 | if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 363 | html(delim); |
| 364 | html("id="); |
| 365 | html_url_arg(rev); |
| 366 | delim = "&"; |
| 367 | } |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 368 | if (ctx.qry.difftype) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 369 | html(delim); |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 370 | htmlf("dt=%d", ctx.qry.difftype); |
Johan Herland | d20313e | 2010-06-10 20:15:51 +0200 | [diff] [blame] | 371 | delim = "&"; |
| 372 | } |
| 373 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
| 374 | html(delim); |
| 375 | html("context="); |
| 376 | htmlf("%d", ctx.qry.context); |
| 377 | delim = "&"; |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 378 | } |
Johan Herland | 72ef913 | 2010-06-24 17:53:20 +0200 | [diff] [blame] | 379 | if (ctx.qry.ignorews) { |
| 380 | html(delim); |
| 381 | html("ignorews=1"); |
| 382 | delim = "&"; |
| 383 | } |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 384 | if (ctx.qry.follow) { |
| 385 | html(delim); |
| 386 | html("follow=1"); |
| 387 | } |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 388 | html("'>"); |
Christian Franke | fe1bb0e | 2012-10-28 18:36:08 +0100 | [diff] [blame] | 389 | if (name[0] != '\0') |
| 390 | html_txt(name); |
| 391 | else |
| 392 | html_txt("(no commit message)"); |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 393 | html("</a>"); |
Lars Hjemli | 42a7eb9 | 2007-06-17 14:53:02 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 396 | void cgit_refs_link(const char *name, const char *title, const char *class, |
| 397 | const char *head, const char *rev, const char *path) |
Lars Hjemli | ac1f493 | 2007-10-27 10:47:44 +0200 | [diff] [blame] | 398 | { |
| 399 | reporevlink("refs", name, title, class, head, rev, path); |
| 400 | } |
| 401 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 402 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
| 403 | const char *head, const char *rev, |
| 404 | const char *archivename) |
Lars Hjemli | eb45342 | 2007-07-23 00:11:15 +0200 | [diff] [blame] | 405 | { |
| 406 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
| 407 | } |
| 408 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 409 | void cgit_diff_link(const char *name, const char *title, const char *class, |
| 410 | const char *head, const char *new_rev, const char *old_rev, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 411 | const char *path) |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 412 | { |
| 413 | char *delim; |
| 414 | |
| 415 | delim = repolink(title, class, "diff", head, path); |
Florian Pritz | 8d94607 | 2010-02-01 17:55:37 +0100 | [diff] [blame] | 416 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 417 | html(delim); |
| 418 | html("id="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 419 | html_url_arg(new_rev); |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 420 | delim = "&"; |
| 421 | } |
| 422 | if (old_rev) { |
| 423 | html(delim); |
| 424 | html("id2="); |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 425 | html_url_arg(old_rev); |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 426 | delim = "&"; |
| 427 | } |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 428 | if (ctx.qry.difftype) { |
Ragnar Ouchterlony | c358aa3 | 2009-09-14 20:19:02 +0200 | [diff] [blame] | 429 | html(delim); |
John Keeping | 1830271 | 2014-10-05 10:59:04 +0100 | [diff] [blame] | 430 | htmlf("dt=%d", ctx.qry.difftype); |
Johan Herland | d20313e | 2010-06-10 20:15:51 +0200 | [diff] [blame] | 431 | delim = "&"; |
| 432 | } |
| 433 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
| 434 | html(delim); |
| 435 | html("context="); |
| 436 | htmlf("%d", ctx.qry.context); |
| 437 | delim = "&"; |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 438 | } |
Johan Herland | 72ef913 | 2010-06-24 17:53:20 +0200 | [diff] [blame] | 439 | if (ctx.qry.ignorews) { |
| 440 | html(delim); |
| 441 | html("ignorews=1"); |
| 442 | delim = "&"; |
| 443 | } |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 444 | if (ctx.qry.follow) { |
| 445 | html(delim); |
| 446 | html("follow=1"); |
| 447 | } |
Lars Hjemli | 4a0be58 | 2007-06-17 18:12:03 +0200 | [diff] [blame] | 448 | html("'>"); |
| 449 | html_txt(name); |
| 450 | html("</a>"); |
| 451 | } |
| 452 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 453 | void cgit_patch_link(const char *name, const char *title, const char *class, |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 454 | const char *head, const char *rev, const char *path) |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 455 | { |
Johan Herland | eac1b67 | 2010-06-10 01:09:33 +0200 | [diff] [blame] | 456 | reporevlink("patch", name, title, class, head, rev, path); |
Lars Hjemli | 620bb3e | 2007-12-10 21:47:29 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 459 | void cgit_stats_link(const char *name, const char *title, const char *class, |
| 460 | const char *head, const char *path) |
Lars Hjemli | eaf2d25 | 2008-12-07 13:34:16 +0100 | [diff] [blame] | 461 | { |
| 462 | reporevlink("stats", name, title, class, head, NULL, path); |
| 463 | } |
| 464 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 465 | static void cgit_self_link(char *name, const char *title, const char *class) |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 466 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 467 | if (!strcmp(ctx.qry.page, "repolist")) |
| 468 | cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort, |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 469 | ctx.qry.ofs, 1); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 470 | else if (!strcmp(ctx.qry.page, "summary")) |
| 471 | cgit_summary_link(name, title, class, ctx.qry.head); |
| 472 | else if (!strcmp(ctx.qry.page, "tag")) |
John Keeping | c422b9b | 2015-01-15 22:18:14 +0000 | [diff] [blame] | 473 | cgit_tag_link(name, title, class, ctx.qry.has_sha1 ? |
| 474 | ctx.qry.sha1 : ctx.qry.head); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 475 | else if (!strcmp(ctx.qry.page, "tree")) |
| 476 | cgit_tree_link(name, title, class, ctx.qry.head, |
| 477 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 478 | ctx.qry.path); |
| 479 | else if (!strcmp(ctx.qry.page, "plain")) |
| 480 | cgit_plain_link(name, title, class, ctx.qry.head, |
| 481 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 482 | ctx.qry.path); |
| 483 | else if (!strcmp(ctx.qry.page, "log")) |
| 484 | cgit_log_link(name, title, class, ctx.qry.head, |
| 485 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 486 | ctx.qry.path, ctx.qry.ofs, |
| 487 | ctx.qry.grep, ctx.qry.search, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 488 | ctx.qry.showmsg, ctx.qry.follow); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 489 | else if (!strcmp(ctx.qry.page, "commit")) |
| 490 | cgit_commit_link(name, title, class, ctx.qry.head, |
| 491 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 492 | ctx.qry.path); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 493 | else if (!strcmp(ctx.qry.page, "patch")) |
| 494 | cgit_patch_link(name, title, class, ctx.qry.head, |
| 495 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 496 | ctx.qry.path); |
| 497 | else if (!strcmp(ctx.qry.page, "refs")) |
| 498 | cgit_refs_link(name, title, class, ctx.qry.head, |
| 499 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 500 | ctx.qry.path); |
| 501 | else if (!strcmp(ctx.qry.page, "snapshot")) |
| 502 | cgit_snapshot_link(name, title, class, ctx.qry.head, |
| 503 | ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, |
| 504 | ctx.qry.path); |
| 505 | else if (!strcmp(ctx.qry.page, "diff")) |
| 506 | cgit_diff_link(name, title, class, ctx.qry.head, |
| 507 | ctx.qry.sha1, ctx.qry.sha2, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 508 | ctx.qry.path); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 509 | else if (!strcmp(ctx.qry.page, "stats")) |
| 510 | cgit_stats_link(name, title, class, ctx.qry.head, |
| 511 | ctx.qry.path); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 512 | else { |
| 513 | /* Don't known how to make link for this page */ |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 514 | repolink(title, class, ctx.qry.page, ctx.qry.head, ctx.qry.path); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 515 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 516 | html_txt(ctx.qry.page); |
John Keeping | 6d8a789 | 2013-03-06 20:51:54 +0000 | [diff] [blame] | 517 | html("' -->"); |
| 518 | html_txt(name); |
| 519 | html("</a>"); |
| 520 | } |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 523 | void cgit_object_link(struct object *obj) |
| 524 | { |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 525 | char *page, *shortrev, *fullrev, *name; |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 526 | |
Christian Hesse | 559ab5e | 2016-01-05 07:38:53 +0100 | [diff] [blame] | 527 | fullrev = oid_to_hex(&obj->oid); |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 528 | shortrev = xstrdup(fullrev); |
| 529 | shortrev[10] = '\0'; |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 530 | if (obj->type == OBJ_COMMIT) { |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 531 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 532 | ctx.qry.head, fullrev, NULL); |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 533 | return; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 534 | } else if (obj->type == OBJ_TREE) |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 535 | page = "tree"; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 536 | else if (obj->type == OBJ_TAG) |
Lars Hjemli | fc5880f | 2007-10-28 15:40:47 +0100 | [diff] [blame] | 537 | page = "tag"; |
Lars Hjemli | 8b5fc6d | 2008-10-05 21:12:08 +0200 | [diff] [blame] | 538 | else |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 539 | page = "blob"; |
Lars Hjemli | c57aceb | 2008-12-01 21:58:59 +0100 | [diff] [blame] | 540 | name = fmt("%s %s...", typename(obj->type), shortrev); |
| 541 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
Lars Hjemli | 4e9107a | 2007-07-22 23:42:55 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 544 | static struct string_list_item *lookup_path(struct string_list *list, |
| 545 | const char *path) |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 546 | { |
| 547 | struct string_list_item *item; |
| 548 | |
| 549 | while (path && path[0]) { |
| 550 | if ((item = string_list_lookup(list, path))) |
| 551 | return item; |
| 552 | if (!(path = strchr(path, '/'))) |
| 553 | break; |
| 554 | path++; |
| 555 | } |
| 556 | return NULL; |
| 557 | } |
| 558 | |
| 559 | void cgit_submodule_link(const char *class, char *path, const char *rev) |
| 560 | { |
| 561 | struct string_list *list; |
| 562 | struct string_list_item *item; |
| 563 | char tail, *dir; |
| 564 | size_t len; |
| 565 | |
Jason A. Donenfeld | 40e1d9b | 2013-03-20 20:43:13 +0100 | [diff] [blame] | 566 | len = 0; |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 567 | tail = 0; |
| 568 | list = &ctx.repo->submodules; |
| 569 | item = lookup_path(list, path); |
| 570 | if (!item) { |
| 571 | len = strlen(path); |
| 572 | tail = path[len - 1]; |
| 573 | if (tail == '/') { |
| 574 | path[len - 1] = 0; |
| 575 | item = lookup_path(list, path); |
| 576 | } |
| 577 | } |
Lukas Fleischer | db021a1 | 2015-03-05 20:41:45 +0100 | [diff] [blame] | 578 | if (item || ctx.repo->module_link) { |
| 579 | html("<a "); |
| 580 | if (class) |
| 581 | htmlf("class='%s' ", class); |
| 582 | html("href='"); |
| 583 | if (item) { |
| 584 | html_attrf(item->util, rev); |
| 585 | } else { |
| 586 | dir = strrchr(path, '/'); |
| 587 | if (dir) |
| 588 | dir++; |
| 589 | else |
| 590 | dir = path; |
| 591 | html_attrf(ctx.repo->module_link, dir, rev); |
| 592 | } |
| 593 | html("'>"); |
| 594 | html_txt(path); |
| 595 | html("</a>"); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 596 | } else { |
Lukas Fleischer | db021a1 | 2015-03-05 20:41:45 +0100 | [diff] [blame] | 597 | html("<span"); |
| 598 | if (class) |
| 599 | htmlf(" class='%s'", class); |
| 600 | html(">"); |
| 601 | html_txt(path); |
| 602 | html("</span>"); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 603 | } |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 604 | html_txtf(" @ %.7s", rev); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 605 | if (item && tail) |
| 606 | path[len - 1] = tail; |
| 607 | } |
| 608 | |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 609 | const struct date_mode *cgit_date_mode(enum date_mode_type type) |
John Keeping | 360af46 | 2016-01-19 19:33:03 +0000 | [diff] [blame] | 610 | { |
| 611 | static struct date_mode mode; |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 612 | mode.type = type; |
John Keeping | 360af46 | 2016-01-19 19:33:03 +0000 | [diff] [blame] | 613 | mode.local = ctx.cfg.local_time; |
| 614 | return &mode; |
| 615 | } |
| 616 | |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 617 | static void print_rel_date(time_t t, int tz, double value, |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 618 | const char *class, const char *suffix) |
| 619 | { |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 620 | htmlf("<span class='%s' title='", class); |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 621 | html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601))); |
John Keeping | caed6cb | 2014-12-20 13:59:39 +0000 | [diff] [blame] | 622 | htmlf("'>%.0f %s</span>", value, suffix); |
| 623 | } |
| 624 | |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 625 | void cgit_print_age(time_t t, int tz, time_t max_relative) |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 626 | { |
| 627 | time_t now, secs; |
| 628 | |
Lars Hjemli | fc4c4ba | 2007-12-02 22:11:35 +0100 | [diff] [blame] | 629 | if (!t) |
| 630 | return; |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 631 | time(&now); |
| 632 | secs = now - t; |
Jason A. Donenfeld | bb3cc0d | 2014-01-17 15:41:41 +0100 | [diff] [blame] | 633 | if (secs < 0) |
| 634 | secs = 0; |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 635 | |
| 636 | if (secs > max_relative && max_relative >= 0) { |
John Keeping | a360666 | 2015-08-13 12:24:34 +0100 | [diff] [blame] | 637 | html("<span title='"); |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 638 | html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601))); |
John Keeping | a360666 | 2015-08-13 12:24:34 +0100 | [diff] [blame] | 639 | html("'>"); |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 640 | html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT))); |
John Keeping | a360666 | 2015-08-13 12:24:34 +0100 | [diff] [blame] | 641 | html("</span>"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 642 | return; |
| 643 | } |
| 644 | |
| 645 | if (secs < TM_HOUR * 2) { |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 646 | print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min."); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | if (secs < TM_DAY * 2) { |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 650 | print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 651 | return; |
| 652 | } |
| 653 | if (secs < TM_WEEK * 2) { |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 654 | print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | if (secs < TM_MONTH * 2) { |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 658 | print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 659 | return; |
| 660 | } |
| 661 | if (secs < TM_YEAR * 2) { |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 662 | print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 663 | return; |
| 664 | } |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 665 | print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years"); |
Lars Hjemli | 5db3917 | 2007-05-22 23:08:46 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 668 | void cgit_print_http_headers(void) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 669 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 670 | if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1")) |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 671 | return; |
| 672 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 673 | if (ctx.page.status) |
| 674 | htmlf("Status: %d %s\n", ctx.page.status, ctx.page.statusmsg); |
| 675 | if (ctx.page.mimetype && ctx.page.charset) |
| 676 | htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype, |
| 677 | ctx.page.charset); |
| 678 | else if (ctx.page.mimetype) |
| 679 | htmlf("Content-Type: %s\n", ctx.page.mimetype); |
| 680 | if (ctx.page.size) |
| 681 | htmlf("Content-Length: %zd\n", ctx.page.size); |
Jason A. Donenfeld | 513b386 | 2016-01-14 14:28:37 +0100 | [diff] [blame] | 682 | if (ctx.page.filename) { |
| 683 | html("Content-Disposition: inline; filename=\""); |
| 684 | html_header_arg_in_quotes(ctx.page.filename); |
| 685 | html("\"\n"); |
| 686 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 687 | if (!ctx.env.authenticated) |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 688 | html("Cache-Control: no-cache, no-store\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 689 | htmlf("Last-Modified: %s\n", http_date(ctx.page.modified)); |
| 690 | htmlf("Expires: %s\n", http_date(ctx.page.expires)); |
| 691 | if (ctx.page.etag) |
| 692 | htmlf("ETag: \"%s\"\n", ctx.page.etag); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 693 | html("\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 694 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
Lars Hjemli | 3ff58dd | 2009-02-19 23:24:15 +0100 | [diff] [blame] | 695 | exit(0); |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 696 | } |
| 697 | |
Jason A. Donenfeld | d703480 | 2015-08-12 14:50:09 +0200 | [diff] [blame] | 698 | void cgit_redirect(const char *url, bool permanent) |
| 699 | { |
| 700 | htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found"); |
Jason A. Donenfeld | 4291453 | 2016-01-14 14:13:39 +0100 | [diff] [blame] | 701 | html("Location: "); |
| 702 | html_url_path(url); |
| 703 | html("\n\n"); |
Jason A. Donenfeld | d703480 | 2015-08-12 14:50:09 +0200 | [diff] [blame] | 704 | } |
| 705 | |
John Keeping | 3c53ebf | 2014-08-01 22:14:19 +0100 | [diff] [blame] | 706 | static void print_rel_vcs_link(const char *url) |
| 707 | { |
| 708 | html("<link rel='vcs-git' href='"); |
| 709 | html_attr(url); |
| 710 | html("' title='"); |
| 711 | html_attr(ctx.repo->name); |
| 712 | html(" Git repository'/>\n"); |
| 713 | } |
| 714 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 715 | void cgit_print_docstart(void) |
Lars Hjemli | f3c1a18 | 2008-03-24 00:51:19 +0100 | [diff] [blame] | 716 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 717 | if (ctx.cfg.embedded) { |
| 718 | if (ctx.cfg.header) |
| 719 | html_include(ctx.cfg.header); |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 720 | return; |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 721 | } |
Lars Hjemli | 0cbb508 | 2009-01-22 23:33:56 +0100 | [diff] [blame] | 722 | |
Christian Hesse | 6edfc16 | 2015-10-09 13:15:51 +0200 | [diff] [blame] | 723 | char *host = cgit_hosturl(); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 724 | html(cgit_doctype); |
Juuso Lapinlampi | 8d05b39 | 2016-05-11 18:04:14 +0000 | [diff] [blame] | 725 | html("<html lang='en'>\n"); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 726 | html("<head>\n"); |
| 727 | html("<title>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 728 | html_txt(ctx.page.title); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 729 | html("</title>\n"); |
Lars Hjemli | f692503 | 2007-06-18 09:42:10 +0200 | [diff] [blame] | 730 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 731 | if (ctx.cfg.robots && *ctx.cfg.robots) |
| 732 | htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 733 | html("<link rel='stylesheet' type='text/css' href='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 734 | html_attr(ctx.cfg.css); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 735 | html("'/>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 736 | if (ctx.cfg.favicon) { |
Lars Hjemli | 502865a | 2008-07-19 20:40:30 +0200 | [diff] [blame] | 737 | html("<link rel='shortcut icon' href='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 738 | html_attr(ctx.cfg.favicon); |
Lars Hjemli | 502865a | 2008-07-19 20:40:30 +0200 | [diff] [blame] | 739 | html("'/>\n"); |
| 740 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 741 | if (host && ctx.repo && ctx.qry.head) { |
Christian Hesse | 37fce99 | 2015-10-09 13:15:46 +0200 | [diff] [blame] | 742 | char *fileurl; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 743 | struct strbuf sb = STRBUF_INIT; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 744 | strbuf_addf(&sb, "h=%s", ctx.qry.head); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 745 | |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 746 | html("<link rel='alternate' title='Atom feed' href='"); |
| 747 | html(cgit_httpscheme()); |
Christian Hesse | 6edfc16 | 2015-10-09 13:15:51 +0200 | [diff] [blame] | 748 | html_attr(host); |
Christian Hesse | 37fce99 | 2015-10-09 13:15:46 +0200 | [diff] [blame] | 749 | fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath, |
| 750 | sb.buf); |
| 751 | html_attr(fileurl); |
Mark Lodato | b5a3a20 | 2009-03-15 00:11:54 -0400 | [diff] [blame] | 752 | html("' type='application/atom+xml'/>\n"); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 753 | strbuf_release(&sb); |
Christian Hesse | 37fce99 | 2015-10-09 13:15:46 +0200 | [diff] [blame] | 754 | free(fileurl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 755 | } |
John Keeping | 3c53ebf | 2014-08-01 22:14:19 +0100 | [diff] [blame] | 756 | if (ctx.repo) |
| 757 | cgit_add_clone_urls(print_rel_vcs_link); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 758 | if (ctx.cfg.head_include) |
| 759 | html_include(ctx.cfg.head_include); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 760 | html("</head>\n"); |
| 761 | html("<body>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 762 | if (ctx.cfg.header) |
| 763 | html_include(ctx.cfg.header); |
Christian Hesse | 6edfc16 | 2015-10-09 13:15:51 +0200 | [diff] [blame] | 764 | free(host); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 765 | } |
| 766 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 767 | void cgit_print_docend(void) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 768 | { |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 769 | html("</div> <!-- class=content -->\n"); |
| 770 | if (ctx.cfg.embedded) { |
| 771 | html("</div> <!-- id=cgit -->\n"); |
| 772 | if (ctx.cfg.footer) |
| 773 | html_include(ctx.cfg.footer); |
| 774 | return; |
| 775 | } |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 776 | if (ctx.cfg.footer) |
| 777 | html_include(ctx.cfg.footer); |
| 778 | else { |
Jason A. Donenfeld | d88ec84 | 2016-02-24 18:01:42 +0100 | [diff] [blame] | 779 | htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", |
Lars Hjemli | b9aabf0 | 2008-10-05 19:09:58 +0200 | [diff] [blame] | 780 | cgit_version); |
John Keeping | 9c15f3c | 2016-02-08 15:05:54 +0000 | [diff] [blame] | 781 | html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 782 | html("</div>\n"); |
| 783 | } |
Lars Hjemli | 80550bb | 2009-08-11 10:12:35 +0200 | [diff] [blame] | 784 | html("</div> <!-- id=cgit -->\n"); |
Lars Hjemli | de5e928 | 2008-06-26 13:53:30 +0200 | [diff] [blame] | 785 | html("</body>\n</html>\n"); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 786 | } |
| 787 | |
John Keeping | aec1204 | 2015-08-14 12:47:01 +0100 | [diff] [blame] | 788 | void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) |
| 789 | { |
| 790 | va_list ap; |
John Keeping | c5975ae | 2015-08-14 12:47:22 +0100 | [diff] [blame] | 791 | ctx.page.expires = ctx.cfg.cache_dynamic_ttl; |
John Keeping | aec1204 | 2015-08-14 12:47:01 +0100 | [diff] [blame] | 792 | ctx.page.status = code; |
| 793 | ctx.page.statusmsg = msg; |
Juuso Lapinlampi | 80f12b3 | 2016-05-11 17:50:09 +0000 | [diff] [blame] | 794 | cgit_print_layout_start(); |
John Keeping | aec1204 | 2015-08-14 12:47:01 +0100 | [diff] [blame] | 795 | va_start(ap, fmt); |
| 796 | cgit_vprint_error(fmt, ap); |
| 797 | va_end(ap); |
Juuso Lapinlampi | 80f12b3 | 2016-05-11 17:50:09 +0000 | [diff] [blame] | 798 | cgit_print_layout_end(); |
John Keeping | aec1204 | 2015-08-14 12:47:01 +0100 | [diff] [blame] | 799 | } |
| 800 | |
John Keeping | 7649879 | 2015-08-14 12:47:11 +0100 | [diff] [blame] | 801 | void cgit_print_layout_start(void) |
| 802 | { |
| 803 | cgit_print_http_headers(); |
| 804 | cgit_print_docstart(); |
| 805 | cgit_print_pageheader(); |
| 806 | } |
| 807 | |
| 808 | void cgit_print_layout_end(void) |
| 809 | { |
| 810 | cgit_print_docend(); |
| 811 | } |
| 812 | |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 813 | static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) |
| 814 | { |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 815 | struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); |
| 816 | int i; |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 817 | |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 818 | for (i = 0; url_list[i]; i++) { |
| 819 | strbuf_rtrim(url_list[i]); |
| 820 | if (url_list[i]->len == 0) |
| 821 | continue; |
| 822 | if (suffix && *suffix) |
| 823 | strbuf_addf(url_list[i], "/%s", suffix); |
| 824 | fn(url_list[i]->buf); |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 825 | } |
| 826 | |
Lukas Fleischer | 1a9e566 | 2015-02-05 10:11:42 +0100 | [diff] [blame] | 827 | strbuf_list_free(url_list); |
John Keeping | bbfa006 | 2014-08-01 22:14:17 +0100 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | void cgit_add_clone_urls(void (*fn)(const char *)) |
| 831 | { |
| 832 | if (ctx.repo->clone_url) |
| 833 | add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL); |
| 834 | else if (ctx.cfg.clone_prefix) |
| 835 | add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); |
| 836 | } |
| 837 | |
Christian Hesse | de83de2 | 2015-07-28 10:42:01 +0200 | [diff] [blame] | 838 | static int print_branch_option(const char *refname, const struct object_id *oid, |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 839 | int flags, void *cb_data) |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 840 | { |
| 841 | char *name = (char *)refname; |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 842 | html_option(name, name, ctx.qry.head); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 843 | return 0; |
| 844 | } |
| 845 | |
Johan Herland | c3f23d4 | 2010-06-10 01:09:24 +0200 | [diff] [blame] | 846 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
| 847 | const char *page) |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 848 | { |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 849 | if (!ctx.cfg.virtual_root) { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 850 | struct strbuf url = STRBUF_INIT; |
| 851 | |
| 852 | strbuf_addf(&url, "%s/%s", ctx.qry.repo, page); |
Johan Herland | c8e3295 | 2010-06-10 01:09:27 +0200 | [diff] [blame] | 853 | if (ctx.qry.vpath) |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 854 | strbuf_addf(&url, "/%s", ctx.qry.vpath); |
| 855 | html_hidden("url", url.buf); |
| 856 | strbuf_release(&url); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Lars Hjemli | 25c8432 | 2008-07-27 12:32:08 +0200 | [diff] [blame] | 859 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
| 860 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 861 | html_hidden("h", ctx.qry.head); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 862 | |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 863 | if (ctx.qry.sha1) |
| 864 | html_hidden("id", ctx.qry.sha1); |
| 865 | if (ctx.qry.sha2) |
| 866 | html_hidden("id2", ctx.qry.sha2); |
Lars Hjemli | 0274b57 | 2008-11-29 18:39:41 +0100 | [diff] [blame] | 867 | if (ctx.qry.showmsg) |
| 868 | html_hidden("showmsg", "1"); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 869 | |
| 870 | if (incl_search) { |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 871 | if (ctx.qry.grep) |
| 872 | html_hidden("qt", ctx.qry.grep); |
| 873 | if (ctx.qry.search) |
| 874 | html_hidden("q", ctx.qry.search); |
Lars Hjemli | 0c8e184 | 2007-10-30 10:47:38 +0100 | [diff] [blame] | 875 | } |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 876 | } |
| 877 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 878 | static const char *hc(const char *page) |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 879 | { |
Lukas Fleischer | da1b897 | 2015-12-13 01:27:13 +0100 | [diff] [blame] | 880 | if (!ctx.qry.page) |
| 881 | return NULL; |
| 882 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 883 | return strcmp(ctx.qry.page, page) ? NULL : "active"; |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 884 | } |
| 885 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 886 | static void cgit_print_path_crumbs(char *path) |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 887 | { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 888 | char *old_path = ctx.qry.path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 889 | char *p = path, *q, *end = path + strlen(path); |
| 890 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 891 | ctx.qry.path = NULL; |
| 892 | cgit_self_link("root", NULL, NULL); |
| 893 | ctx.qry.path = p = path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 894 | while (p < end) { |
| 895 | if (!(q = strchr(p, '/'))) |
| 896 | q = end; |
| 897 | *q = '\0'; |
| 898 | html_txt("/"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 899 | cgit_self_link(p, NULL, NULL); |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 900 | if (q < end) |
| 901 | *q = '/'; |
| 902 | p = q + 1; |
| 903 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 904 | ctx.qry.path = old_path; |
Johan Herland | 24fd7e5 | 2010-06-10 01:09:29 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 907 | static void print_header(void) |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 908 | { |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 909 | char *logo = NULL, *logo_link = NULL; |
| 910 | |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 911 | html("<table id='header'>\n"); |
| 912 | html("<tr>\n"); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 913 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 914 | if (ctx.repo && ctx.repo->logo && *ctx.repo->logo) |
| 915 | logo = ctx.repo->logo; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 916 | else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 917 | logo = ctx.cfg.logo; |
| 918 | if (ctx.repo && ctx.repo->logo_link && *ctx.repo->logo_link) |
| 919 | logo_link = ctx.repo->logo_link; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 920 | else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 921 | logo_link = ctx.cfg.logo_link; |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 922 | if (logo && *logo) { |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 923 | html("<td class='logo' rowspan='2'><a href='"); |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 924 | if (logo_link && *logo_link) |
| 925 | html_attr(logo_link); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 926 | else |
| 927 | html_attr(cgit_rooturl()); |
| 928 | html("'><img src='"); |
Bernhard Reutner-Fischer | 808c685 | 2010-12-23 12:47:54 +0100 | [diff] [blame] | 929 | html_attr(logo); |
Matthew Metnetsky | 6421dc3 | 2009-06-29 21:27:51 -0400 | [diff] [blame] | 930 | html("' alt='cgit logo'/></a></td>\n"); |
| 931 | } |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 932 | |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 933 | html("<td class='main'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 934 | if (ctx.repo) { |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 935 | cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); |
Lars Hjemli | 17890d0 | 2008-05-03 12:44:20 +0200 | [diff] [blame] | 936 | html(" : "); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 937 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
| 938 | if (ctx.env.authenticated) { |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 939 | html("</td><td class='form'>"); |
Jason A. Donenfeld | c34e288 | 2016-05-12 21:29:40 +0200 | [diff] [blame] | 940 | html("<form method='get'>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 941 | cgit_add_hidden_formfields(0, 1, ctx.qry.page); |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 942 | html("<select name='h' onchange='this.form.submit();'>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 943 | for_each_branch_ref(print_branch_option, ctx.qry.head); |
Christian Hesse | d1ddce9 | 2015-03-18 18:08:48 +0100 | [diff] [blame] | 944 | if (ctx.repo->enable_remote_branches) |
| 945 | for_each_remote_ref(print_branch_option, ctx.qry.head); |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 946 | html("</select> "); |
Juuso Lapinlampi | 9afda36 | 2016-05-11 18:04:18 +0000 | [diff] [blame] | 947 | html("<input type='submit' value='switch'/>"); |
Jason A. Donenfeld | d6e9200 | 2014-01-14 21:49:31 +0100 | [diff] [blame] | 948 | html("</form>"); |
| 949 | } |
Lars Hjemli | 7c0d2d9 | 2008-04-12 19:59:41 +0200 | [diff] [blame] | 950 | } else |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 951 | html_txt(ctx.cfg.root_title); |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 952 | html("</td></tr>\n"); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 953 | |
Lars Hjemli | 2d6ee03 | 2008-07-27 12:22:16 +0200 | [diff] [blame] | 954 | html("<tr><td class='sub'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 955 | if (ctx.repo) { |
| 956 | html_txt(ctx.repo->desc); |
Lars Hjemli | 2d6ee03 | 2008-07-27 12:22:16 +0200 | [diff] [blame] | 957 | html("</td><td class='sub right'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 958 | html_txt(ctx.repo->owner); |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 959 | } else { |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 960 | if (ctx.cfg.root_desc) |
| 961 | html_txt(ctx.cfg.root_desc); |
| 962 | else if (ctx.cfg.index_info) |
| 963 | html_include(ctx.cfg.index_info); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 964 | } |
Lars Hjemli | 3cfcb08 | 2008-04-15 00:00:11 +0200 | [diff] [blame] | 965 | html("</td></tr></table>\n"); |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 966 | } |
| 967 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 968 | void cgit_print_pageheader(void) |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 969 | { |
Lars Hjemli | ef0c6aa | 2009-07-25 12:19:31 +0200 | [diff] [blame] | 970 | html("<div id='cgit'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 971 | if (!ctx.env.authenticated || !ctx.cfg.noheader) |
| 972 | print_header(); |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 973 | |
| 974 | html("<table class='tabs'><tr><td>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 975 | if (ctx.env.authenticated && ctx.repo) { |
Jason A. Donenfeld | 3cbbb8e | 2014-01-17 13:53:37 +0100 | [diff] [blame] | 976 | if (ctx.repo->readme.nr) |
| 977 | reporevlink("about", "about", NULL, |
| 978 | hc("about"), ctx.qry.head, NULL, |
| 979 | NULL); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 980 | cgit_summary_link("summary", NULL, hc("summary"), |
| 981 | ctx.qry.head); |
| 982 | cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head, |
| 983 | ctx.qry.sha1, NULL); |
| 984 | cgit_log_link("log", NULL, hc("log"), ctx.qry.head, |
| 985 | NULL, ctx.qry.vpath, 0, NULL, NULL, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 986 | ctx.qry.showmsg, ctx.qry.follow); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 987 | cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, |
| 988 | ctx.qry.sha1, ctx.qry.vpath); |
| 989 | cgit_commit_link("commit", NULL, hc("commit"), |
John Keeping | eeddb5b | 2014-10-05 10:59:02 +0100 | [diff] [blame] | 990 | ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 991 | cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head, |
John Keeping | 03f537f | 2014-10-05 10:59:03 +0100 | [diff] [blame] | 992 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 993 | if (ctx.repo->max_stats) |
| 994 | cgit_stats_link("stats", NULL, hc("stats"), |
| 995 | ctx.qry.head, ctx.qry.vpath); |
Jason A. Donenfeld | 5f2664f | 2016-02-22 16:04:15 +0100 | [diff] [blame] | 996 | if (ctx.repo->homepage) { |
| 997 | html("<a href='"); |
| 998 | html_attr(ctx.repo->homepage); |
Jason A. Donenfeld | c424b5c | 2016-02-23 15:35:32 +0100 | [diff] [blame] | 999 | html("'>homepage</a>"); |
Jason A. Donenfeld | 5f2664f | 2016-02-22 16:04:15 +0100 | [diff] [blame] | 1000 | } |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 1001 | html("</td><td class='form'>"); |
| 1002 | html("<form class='right' method='get' action='"); |
Christian Hesse | 37fce99 | 2015-10-09 13:15:46 +0200 | [diff] [blame] | 1003 | if (ctx.cfg.virtual_root) { |
| 1004 | char *fileurl = cgit_fileurl(ctx.qry.repo, "log", |
| 1005 | ctx.qry.vpath, NULL); |
| 1006 | html_url_path(fileurl); |
| 1007 | free(fileurl); |
| 1008 | } |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 1009 | html("'>\n"); |
Lars Hjemli | c3c925f | 2008-12-07 15:52:35 +0100 | [diff] [blame] | 1010 | cgit_add_hidden_formfields(1, 0, "log"); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 1011 | html("<select name='qt'>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1012 | html_option("grep", "log msg", ctx.qry.grep); |
| 1013 | html_option("author", "author", ctx.qry.grep); |
| 1014 | html_option("committer", "committer", ctx.qry.grep); |
| 1015 | html_option("range", "range", ctx.qry.grep); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 1016 | html("</select>\n"); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 1017 | html("<input class='txt' type='text' size='10' name='q' value='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1018 | html_attr(ctx.qry.search); |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 1019 | html("'/>\n"); |
| 1020 | html("<input type='submit' value='search'/>\n"); |
| 1021 | html("</form>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1022 | } else if (ctx.env.authenticated) { |
Christian Hesse | 3e244a0 | 2015-10-09 13:15:48 +0200 | [diff] [blame] | 1023 | char *currenturl = cgit_currenturl(); |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 1024 | site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1025 | if (ctx.cfg.root_readme) |
| 1026 | site_link("about", "about", NULL, hc("about"), |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 1027 | NULL, NULL, 0, 1); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 1028 | html("</td><td class='form'>"); |
| 1029 | html("<form method='get' action='"); |
Christian Hesse | 3e244a0 | 2015-10-09 13:15:48 +0200 | [diff] [blame] | 1030 | html_attr(currenturl); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 1031 | html("'>\n"); |
| 1032 | html("<input type='text' name='q' size='10' value='"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1033 | html_attr(ctx.qry.search); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 1034 | html("'/>\n"); |
| 1035 | html("<input type='submit' value='search'/>\n"); |
| 1036 | html("</form>"); |
Christian Hesse | 3e244a0 | 2015-10-09 13:15:48 +0200 | [diff] [blame] | 1037 | free(currenturl); |
Lars Hjemli | e39d738 | 2006-12-28 02:01:49 +0100 | [diff] [blame] | 1038 | } |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 1039 | html("</td></tr></table>\n"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1040 | if (ctx.env.authenticated && ctx.qry.vpath) { |
Johan Herland | c93ef96 | 2010-06-10 01:09:28 +0200 | [diff] [blame] | 1041 | html("<div class='path'>"); |
| 1042 | html("path: "); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 1043 | cgit_print_path_crumbs(ctx.qry.vpath); |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 1044 | if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) { |
| 1045 | html(" ("); |
| 1046 | ctx.qry.follow = !ctx.qry.follow; |
| 1047 | cgit_self_link(ctx.qry.follow ? "follow" : "unfollow", |
| 1048 | NULL, NULL); |
| 1049 | ctx.qry.follow = !ctx.qry.follow; |
| 1050 | html(")"); |
| 1051 | } |
Johan Herland | c93ef96 | 2010-06-10 01:09:28 +0200 | [diff] [blame] | 1052 | html("</div>"); |
| 1053 | } |
Lars Hjemli | f135569 | 2008-04-12 15:53:31 +0200 | [diff] [blame] | 1054 | html("<div class='content'>"); |
Lars Hjemli | 5a106eb | 2006-12-11 16:38:30 +0100 | [diff] [blame] | 1055 | } |
Lars Hjemli | ab2ab95 | 2007-02-08 13:53:13 +0100 | [diff] [blame] | 1056 | |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 1057 | void cgit_print_filemode(unsigned short mode) |
| 1058 | { |
| 1059 | if (S_ISDIR(mode)) |
| 1060 | html("d"); |
| 1061 | else if (S_ISLNK(mode)) |
| 1062 | html("l"); |
| 1063 | else if (S_ISGITLINK(mode)) |
| 1064 | html("m"); |
| 1065 | else |
| 1066 | html("-"); |
| 1067 | html_fileperm(mode >> 6); |
| 1068 | html_fileperm(mode >> 3); |
| 1069 | html_fileperm(mode); |
| 1070 | } |
| 1071 | |
Lukas Fleischer | 9984e7a | 2016-05-24 18:15:18 +0200 | [diff] [blame] | 1072 | void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, |
| 1073 | const char *ref) |
| 1074 | { |
| 1075 | unsigned char sha1[20]; |
| 1076 | |
| 1077 | /* |
| 1078 | * Prettify snapshot names by stripping leading "v" or "V" if the tag |
| 1079 | * name starts with {v,V}[0-9] and the prettify mapping is injective, |
| 1080 | * i.e. each stripped tag can be inverted without ambiguities. |
| 1081 | */ |
| 1082 | if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && |
| 1083 | (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && |
| 1084 | ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + |
| 1085 | (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + |
| 1086 | (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) |
| 1087 | ref++; |
| 1088 | |
| 1089 | strbuf_addf(filename, "%s-%s", base, ref); |
| 1090 | } |
| 1091 | |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1092 | void cgit_print_snapshot_links(const char *repo, const char *head, |
| 1093 | const char *hex, int snapshots) |
| 1094 | { |
| 1095 | const struct cgit_snapshot_format* f; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1096 | struct strbuf filename = STRBUF_INIT; |
| 1097 | size_t prefixlen; |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1098 | |
Lukas Fleischer | 9984e7a | 2016-05-24 18:15:18 +0200 | [diff] [blame] | 1099 | cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo), hex); |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1100 | prefixlen = filename.len; |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1101 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
| 1102 | if (!(snapshots & f->bit)) |
| 1103 | continue; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1104 | strbuf_setlen(&filename, prefixlen); |
| 1105 | strbuf_addstr(&filename, f->suffix); |
| 1106 | cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, |
| 1107 | filename.buf); |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1108 | html("<br/>"); |
| 1109 | } |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 1110 | strbuf_release(&filename); |
Lars Hjemli | f34478c | 2008-03-24 16:00:27 +0100 | [diff] [blame] | 1111 | } |