Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 1 | /* ui-repolist.c: functions for generating the repolist page |
| 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 | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-repolist.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 11 | #include "html.h" |
Lars Hjemli | a4d1ca1 | 2008-03-24 16:50:57 +0100 | [diff] [blame] | 12 | #include "ui-shared.h" |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 13 | |
Christian Hesse | ccba7eb | 2019-01-02 17:25:01 +0100 | [diff] [blame] | 14 | static time_t read_agefile(const char *path) |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 15 | { |
Lars Hjemli | e16f178 | 2009-08-18 17:17:41 +0200 | [diff] [blame] | 16 | time_t result; |
| 17 | size_t size; |
Christian Hesse | 6edc84b | 2016-01-13 00:45:03 +0100 | [diff] [blame] | 18 | char *buf = NULL; |
Christian Hesse | 17838ec | 2014-12-19 00:28:34 -0700 | [diff] [blame] | 19 | struct strbuf date_buf = STRBUF_INIT; |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 20 | |
Christian Hesse | 7ef1a47 | 2015-10-09 14:55:47 +0200 | [diff] [blame] | 21 | if (readfile(path, &buf, &size)) { |
| 22 | free(buf); |
Christian Hesse | 583aa5d | 2019-11-22 11:09:50 +0100 | [diff] [blame^] | 23 | return 0; |
Christian Hesse | 7ef1a47 | 2015-10-09 14:55:47 +0200 | [diff] [blame] | 24 | } |
Lars Hjemli | e16f178 | 2009-08-18 17:17:41 +0200 | [diff] [blame] | 25 | |
Christian Hesse | 17838ec | 2014-12-19 00:28:34 -0700 | [diff] [blame] | 26 | if (parse_date(buf, &date_buf) == 0) |
| 27 | result = strtoul(date_buf.buf, NULL, 10); |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 28 | else |
Lars Hjemli | e16f178 | 2009-08-18 17:17:41 +0200 | [diff] [blame] | 29 | result = 0; |
| 30 | free(buf); |
Christian Hesse | 17838ec | 2014-12-19 00:28:34 -0700 | [diff] [blame] | 31 | strbuf_release(&date_buf); |
Lars Hjemli | e16f178 | 2009-08-18 17:17:41 +0200 | [diff] [blame] | 32 | return result; |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Lars Hjemli | cbac02c | 2008-11-29 13:33:02 +0100 | [diff] [blame] | 35 | static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 36 | { |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 37 | struct strbuf path = STRBUF_INIT; |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 38 | struct stat s; |
Lars Hjemli | 8813170 | 2008-11-29 16:46:37 +0100 | [diff] [blame] | 39 | struct cgit_repo *r = (struct cgit_repo *)repo; |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 40 | |
Lars Hjemli | 8813170 | 2008-11-29 16:46:37 +0100 | [diff] [blame] | 41 | if (repo->mtime != -1) { |
| 42 | *mtime = repo->mtime; |
| 43 | return 1; |
| 44 | } |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 45 | strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile); |
| 46 | if (stat(path.buf, &s) == 0) { |
| 47 | *mtime = read_agefile(path.buf); |
Ferry Huberts | e52a522 | 2012-10-09 13:09:58 +0200 | [diff] [blame] | 48 | if (*mtime) { |
| 49 | r->mtime = *mtime; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 50 | goto end; |
Ferry Huberts | e52a522 | 2012-10-09 13:09:58 +0200 | [diff] [blame] | 51 | } |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 52 | } |
| 53 | |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 54 | strbuf_reset(&path); |
| 55 | strbuf_addf(&path, "%s/refs/heads/%s", repo->path, |
| 56 | repo->defbranch ? repo->defbranch : "master"); |
| 57 | if (stat(path.buf, &s) == 0) { |
Lars Hjemli | cbac02c | 2008-11-29 13:33:02 +0100 | [diff] [blame] | 58 | *mtime = s.st_mtime; |
Ferry Huberts | 21e0e0b | 2011-05-13 23:09:34 +0200 | [diff] [blame] | 59 | r->mtime = *mtime; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 60 | goto end; |
Ferry Huberts | 21e0e0b | 2011-05-13 23:09:34 +0200 | [diff] [blame] | 61 | } |
Lars Hjemli | 8813170 | 2008-11-29 16:46:37 +0100 | [diff] [blame] | 62 | |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 63 | strbuf_reset(&path); |
| 64 | strbuf_addf(&path, "%s/%s", repo->path, "packed-refs"); |
| 65 | if (stat(path.buf, &s) == 0) { |
Ferry Huberts | 21e0e0b | 2011-05-13 23:09:34 +0200 | [diff] [blame] | 66 | *mtime = s.st_mtime; |
| 67 | r->mtime = *mtime; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 68 | goto end; |
Ferry Huberts | 21e0e0b | 2011-05-13 23:09:34 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | *mtime = 0; |
Lars Hjemli | 8813170 | 2008-11-29 16:46:37 +0100 | [diff] [blame] | 72 | r->mtime = *mtime; |
John Keeping | fb3655d | 2013-04-06 10:28:57 +0100 | [diff] [blame] | 73 | end: |
| 74 | strbuf_release(&path); |
Lars Hjemli | 8813170 | 2008-11-29 16:46:37 +0100 | [diff] [blame] | 75 | return (r->mtime != 0); |
Lars Hjemli | cbac02c | 2008-11-29 13:33:02 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static void print_modtime(struct cgit_repo *repo) |
| 79 | { |
| 80 | time_t t; |
| 81 | if (get_repo_modtime(repo, &t)) |
John Keeping | f2a901d | 2016-01-19 19:33:05 +0000 | [diff] [blame] | 82 | cgit_print_age(t, 0, -1); |
Lars Hjemli | 57f6a8b | 2007-05-22 23:25:25 +0200 | [diff] [blame] | 83 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 84 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 85 | static int is_match(struct cgit_repo *repo) |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 86 | { |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 87 | if (!ctx.qry.search) |
| 88 | return 1; |
Lars Hjemli | 28d781f | 2008-04-13 12:42:27 +0200 | [diff] [blame] | 89 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 90 | return 1; |
Lars Hjemli | 28d781f | 2008-04-13 12:42:27 +0200 | [diff] [blame] | 91 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 92 | return 1; |
Lars Hjemli | 28d781f | 2008-04-13 12:42:27 +0200 | [diff] [blame] | 93 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 94 | return 1; |
Lars Hjemli | 28d781f | 2008-04-13 12:42:27 +0200 | [diff] [blame] | 95 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 96 | return 1; |
| 97 | return 0; |
| 98 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 99 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 100 | static int is_in_url(struct cgit_repo *repo) |
Lars Hjemli | dd80ef5 | 2008-09-14 20:18:10 +0200 | [diff] [blame] | 101 | { |
| 102 | if (!ctx.qry.url) |
| 103 | return 1; |
Christian Hesse | 79c985e | 2014-05-29 17:35:46 +0200 | [diff] [blame] | 104 | if (repo->url && starts_with(repo->url, ctx.qry.url)) |
Lars Hjemli | dd80ef5 | 2008-09-14 20:18:10 +0200 | [diff] [blame] | 105 | return 1; |
| 106 | return 0; |
| 107 | } |
| 108 | |
Peter Colberg | a4014d0 | 2015-12-08 12:53:08 -0500 | [diff] [blame] | 109 | static int is_visible(struct cgit_repo *repo) |
| 110 | { |
| 111 | if (repo->hide || repo->ignore) |
| 112 | return 0; |
| 113 | if (!(is_match(repo) && is_in_url(repo))) |
| 114 | return 0; |
| 115 | return 1; |
| 116 | } |
| 117 | |
Peter Colberg | 9abe4a2 | 2015-12-08 12:53:09 -0500 | [diff] [blame] | 118 | static int any_repos_visible(void) |
| 119 | { |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < cgit_repolist.count; i++) { |
| 123 | if (is_visible(&cgit_repolist.repos[i])) |
| 124 | return 1; |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 129 | static void print_sort_header(const char *title, const char *sort) |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 130 | { |
Christian Hesse | 51338f7 | 2015-10-09 14:55:48 +0200 | [diff] [blame] | 131 | char *currenturl = cgit_currenturl(); |
John Keeping | 1de6591 | 2014-01-12 19:45:17 +0000 | [diff] [blame] | 132 | html("<th class='left'><a href='"); |
Christian Hesse | 51338f7 | 2015-10-09 14:55:48 +0200 | [diff] [blame] | 133 | html_attr(currenturl); |
John Keeping | 1de6591 | 2014-01-12 19:45:17 +0000 | [diff] [blame] | 134 | htmlf("?s=%s", sort); |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 135 | if (ctx.qry.search) { |
William Bell | c366bd6 | 2012-10-09 20:45:58 +0200 | [diff] [blame] | 136 | html("&q="); |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 137 | html_url_arg(ctx.qry.search); |
| 138 | } |
| 139 | htmlf("'>%s</a></th>", title); |
Christian Hesse | 51338f7 | 2015-10-09 14:55:48 +0200 | [diff] [blame] | 140 | free(currenturl); |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 141 | } |
| 142 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 143 | static void print_header(void) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 144 | { |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 145 | html("<tr class='nohover'>"); |
| 146 | print_sort_header("Name", "name"); |
| 147 | print_sort_header("Description", "desc"); |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 148 | if (ctx.cfg.enable_index_owner) |
| 149 | print_sort_header("Owner", "owner"); |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 150 | print_sort_header("Idle", "idle"); |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 151 | if (ctx.cfg.enable_index_links) |
Lars Hjemli | 931fc6d | 2008-04-13 10:57:11 +0200 | [diff] [blame] | 152 | html("<th class='left'>Links</th>"); |
Lars Hjemli | 0d05bca | 2007-06-19 00:56:40 +0200 | [diff] [blame] | 153 | html("</tr>\n"); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 154 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 155 | |
Lars Hjemli | c6078b8 | 2008-05-03 10:54:39 +0200 | [diff] [blame] | 156 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 157 | static void print_pager(int items, int pagelen, char *search, char *sort) |
Lars Hjemli | c6078b8 | 2008-05-03 10:54:39 +0200 | [diff] [blame] | 158 | { |
Jamie Couture | 4675b91 | 2012-10-08 12:49:34 -0400 | [diff] [blame] | 159 | int i, ofs; |
| 160 | char *class = NULL; |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 161 | html("<ul class='pager'>"); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 162 | for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) { |
Jamie Couture | 4675b91 | 2012-10-08 12:49:34 -0400 | [diff] [blame] | 163 | class = (ctx.qry.ofs == ofs) ? "current" : NULL; |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 164 | html("<li>"); |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 165 | cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1), |
Jason A. Donenfeld | 2e4a41e | 2015-03-03 17:23:40 +0100 | [diff] [blame] | 166 | class, search, sort, ofs, 0); |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 167 | html("</li>"); |
Jamie Couture | 4675b91 | 2012-10-08 12:49:34 -0400 | [diff] [blame] | 168 | } |
Lukas Fleischer | b60e6bf | 2013-03-07 08:56:22 +0100 | [diff] [blame] | 169 | html("</ul>"); |
Lars Hjemli | c6078b8 | 2008-05-03 10:54:39 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 172 | static int cmp(const char *s1, const char *s2) |
| 173 | { |
Jason A. Donenfeld | 184c565 | 2012-07-12 19:13:39 +0200 | [diff] [blame] | 174 | if (s1 && s2) { |
| 175 | if (ctx.cfg.case_sensitive_sort) |
| 176 | return strcmp(s1, s2); |
| 177 | else |
| 178 | return strcasecmp(s1, s2); |
| 179 | } |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 180 | if (s1 && !s2) |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 181 | return -1; |
Lars Hjemli | 54272e6 | 2008-11-29 14:27:35 +0100 | [diff] [blame] | 182 | if (s2 && !s1) |
| 183 | return 1; |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int sort_name(const void *a, const void *b) |
| 188 | { |
| 189 | const struct cgit_repo *r1 = a; |
| 190 | const struct cgit_repo *r2 = b; |
| 191 | |
| 192 | return cmp(r1->name, r2->name); |
| 193 | } |
| 194 | |
| 195 | static int sort_desc(const void *a, const void *b) |
| 196 | { |
| 197 | const struct cgit_repo *r1 = a; |
| 198 | const struct cgit_repo *r2 = b; |
| 199 | |
| 200 | return cmp(r1->desc, r2->desc); |
| 201 | } |
| 202 | |
| 203 | static int sort_owner(const void *a, const void *b) |
| 204 | { |
| 205 | const struct cgit_repo *r1 = a; |
| 206 | const struct cgit_repo *r2 = b; |
| 207 | |
| 208 | return cmp(r1->owner, r2->owner); |
| 209 | } |
| 210 | |
| 211 | static int sort_idle(const void *a, const void *b) |
Benjamin Close | d71c0c7 | 2008-11-25 06:25:35 -0800 | [diff] [blame] | 212 | { |
| 213 | const struct cgit_repo *r1 = a; |
| 214 | const struct cgit_repo *r2 = b; |
Benjamin Close | d71c0c7 | 2008-11-25 06:25:35 -0800 | [diff] [blame] | 215 | time_t t1, t2; |
Benjamin Close | d71c0c7 | 2008-11-25 06:25:35 -0800 | [diff] [blame] | 216 | |
Lars Hjemli | cbac02c | 2008-11-29 13:33:02 +0100 | [diff] [blame] | 217 | t1 = t2 = 0; |
| 218 | get_repo_modtime(r1, &t1); |
| 219 | get_repo_modtime(r2, &t2); |
| 220 | return t2 - t1; |
Benjamin Close | d71c0c7 | 2008-11-25 06:25:35 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Jason A. Donenfeld | 87c4748 | 2017-03-30 13:19:50 +0200 | [diff] [blame] | 223 | static int sort_section(const void *a, const void *b) |
| 224 | { |
| 225 | const struct cgit_repo *r1 = a; |
| 226 | const struct cgit_repo *r2 = b; |
| 227 | int result; |
Jason A. Donenfeld | 87c4748 | 2017-03-30 13:19:50 +0200 | [diff] [blame] | 228 | |
| 229 | result = cmp(r1->section, r2->section); |
| 230 | if (!result) { |
| 231 | if (!strcmp(ctx.cfg.repository_sort, "age")) |
| 232 | result = sort_idle(r1, r2); |
| 233 | if (!result) |
| 234 | result = cmp(r1->name, r2->name); |
| 235 | } |
| 236 | return result; |
| 237 | } |
| 238 | |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 239 | struct sortcolumn { |
| 240 | const char *name; |
| 241 | int (*fn)(const void *a, const void *b); |
| 242 | }; |
| 243 | |
John Keeping | ad74669 | 2015-03-08 16:32:21 +0000 | [diff] [blame] | 244 | static const struct sortcolumn sortcolumn[] = { |
Lars Hjemli | 63816ec | 2009-08-23 23:09:31 +0200 | [diff] [blame] | 245 | {"section", sort_section}, |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 246 | {"name", sort_name}, |
| 247 | {"desc", sort_desc}, |
| 248 | {"owner", sort_owner}, |
| 249 | {"idle", sort_idle}, |
| 250 | {NULL, NULL} |
| 251 | }; |
| 252 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 253 | static int sort_repolist(char *field) |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 254 | { |
John Keeping | ad74669 | 2015-03-08 16:32:21 +0000 | [diff] [blame] | 255 | const struct sortcolumn *column; |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 256 | |
| 257 | for (column = &sortcolumn[0]; column->name; column++) { |
| 258 | if (strcmp(field, column->name)) |
| 259 | continue; |
| 260 | qsort(cgit_repolist.repos, cgit_repolist.count, |
| 261 | sizeof(struct cgit_repo), column->fn); |
| 262 | return 1; |
| 263 | } |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 268 | void cgit_print_repolist(void) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 269 | { |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 270 | int i, columns = 3, hits = 0, header = 0; |
Lars Hjemli | e7af002 | 2009-08-23 22:58:39 +0200 | [diff] [blame] | 271 | char *last_section = NULL; |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 272 | char *section; |
Christian Hesse | c177379 | 2016-10-07 15:08:53 +0200 | [diff] [blame] | 273 | char *repourl; |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 274 | int sorted = 0; |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 275 | |
Peter Colberg | 9abe4a2 | 2015-12-08 12:53:09 -0500 | [diff] [blame] | 276 | if (!any_repos_visible()) { |
| 277 | cgit_print_error_page(404, "Not found", "No repositories found"); |
| 278 | return; |
| 279 | } |
| 280 | |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 281 | if (ctx.cfg.enable_index_links) |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 282 | ++columns; |
| 283 | if (ctx.cfg.enable_index_owner) |
| 284 | ++columns; |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 285 | |
| 286 | ctx.page.title = ctx.cfg.root_title; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 287 | cgit_print_http_headers(); |
| 288 | cgit_print_docstart(); |
| 289 | cgit_print_pageheader(); |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 290 | |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 291 | if (ctx.qry.sort) |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 292 | sorted = sort_repolist(ctx.qry.sort); |
Tobias Bieniek | 7a4e7c8 | 2012-10-09 20:53:29 +0200 | [diff] [blame] | 293 | else if (ctx.cfg.section_sort) |
Lars Hjemli | 63816ec | 2009-08-23 23:09:31 +0200 | [diff] [blame] | 294 | sort_repolist("section"); |
Benjamin Close | d71c0c7 | 2008-11-25 06:25:35 -0800 | [diff] [blame] | 295 | |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 296 | html("<table summary='repository list' class='list nowrap'>"); |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 297 | for (i = 0; i < cgit_repolist.count; i++) { |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 298 | ctx.repo = &cgit_repolist.repos[i]; |
Peter Colberg | a4014d0 | 2015-12-08 12:53:08 -0500 | [diff] [blame] | 299 | if (!is_visible(ctx.repo)) |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 300 | continue; |
Lars Hjemli | c6078b8 | 2008-05-03 10:54:39 +0200 | [diff] [blame] | 301 | hits++; |
| 302 | if (hits <= ctx.qry.ofs) |
| 303 | continue; |
| 304 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) |
| 305 | continue; |
Lars Hjemli | 536b054 | 2008-04-13 11:57:10 +0200 | [diff] [blame] | 306 | if (!header++) |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 307 | print_header(); |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 308 | section = ctx.repo->section; |
| 309 | if (section && !strcmp(section, "")) |
| 310 | section = NULL; |
Lars Hjemli | f250c1c | 2008-11-29 14:08:51 +0100 | [diff] [blame] | 311 | if (!sorted && |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 312 | ((last_section == NULL && section != NULL) || |
| 313 | (last_section != NULL && section == NULL) || |
| 314 | (last_section != NULL && section != NULL && |
| 315 | strcmp(section, last_section)))) { |
Christian Hesse | 81509a2 | 2016-07-06 22:42:36 +0200 | [diff] [blame] | 316 | htmlf("<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", |
Lars Hjemli | 0d05bca | 2007-06-19 00:56:40 +0200 | [diff] [blame] | 317 | columns); |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 318 | html_txt(section); |
Lars Hjemli | 5877c49 | 2007-05-18 22:48:22 +0200 | [diff] [blame] | 319 | html("</td></tr>"); |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 320 | last_section = section; |
Lars Hjemli | 5877c49 | 2007-05-18 22:48:22 +0200 | [diff] [blame] | 321 | } |
Lars Hjemli | 0b8b6a3 | 2007-05-21 00:14:28 +0200 | [diff] [blame] | 322 | htmlf("<tr><td class='%s'>", |
Lars Hjemli | e01229c | 2009-08-24 07:42:03 +0200 | [diff] [blame] | 323 | !sorted && section ? "sublevel-repo" : "toplevel-repo"); |
Lars Hjemli | 49ecbbd | 2008-10-05 17:16:36 +0200 | [diff] [blame] | 324 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 325 | html("</td><td>"); |
Christian Hesse | c177379 | 2016-10-07 15:08:53 +0200 | [diff] [blame] | 326 | repourl = cgit_repourl(ctx.repo->url); |
| 327 | html_link_open(repourl, NULL, NULL); |
| 328 | free(repourl); |
Jeff Smith | 7078725 | 2017-10-01 23:39:05 -0500 | [diff] [blame] | 329 | if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0) |
| 330 | html("..."); |
Lars Hjemli | e9a7042 | 2008-04-14 22:23:48 +0200 | [diff] [blame] | 331 | html_link_close(); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 332 | html("</td><td>"); |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 333 | if (ctx.cfg.enable_index_owner) { |
Chris Burroughs | 96ceb9a | 2014-08-04 09:23:08 -0400 | [diff] [blame] | 334 | if (ctx.repo->owner_filter) { |
| 335 | cgit_open_filter(ctx.repo->owner_filter); |
| 336 | html_txt(ctx.repo->owner); |
| 337 | cgit_close_filter(ctx.repo->owner_filter); |
| 338 | } else { |
Christian Hesse | 7fea585 | 2016-10-10 20:17:51 +0200 | [diff] [blame] | 339 | char *currenturl = cgit_currenturl(); |
Chris Burroughs | 96ceb9a | 2014-08-04 09:23:08 -0400 | [diff] [blame] | 340 | html("<a href='"); |
Christian Hesse | 7fea585 | 2016-10-10 20:17:51 +0200 | [diff] [blame] | 341 | html_attr(currenturl); |
Jason A. Donenfeld | e14eee9 | 2015-03-03 16:53:11 +0100 | [diff] [blame] | 342 | html("?q="); |
Chris Burroughs | 96ceb9a | 2014-08-04 09:23:08 -0400 | [diff] [blame] | 343 | html_url_arg(ctx.repo->owner); |
| 344 | html("'>"); |
| 345 | html_txt(ctx.repo->owner); |
| 346 | html("</a>"); |
Christian Hesse | 7fea585 | 2016-10-10 20:17:51 +0200 | [diff] [blame] | 347 | free(currenturl); |
Chris Burroughs | 96ceb9a | 2014-08-04 09:23:08 -0400 | [diff] [blame] | 348 | } |
Florian Pritz | b1e172a | 2013-02-01 10:59:13 +0100 | [diff] [blame] | 349 | html("</td><td>"); |
| 350 | } |
Lars Hjemli | d1f3bbe | 2008-02-16 13:56:09 +0100 | [diff] [blame] | 351 | print_modtime(ctx.repo); |
Lars Hjemli | 0d05bca | 2007-06-19 00:56:40 +0200 | [diff] [blame] | 352 | html("</td>"); |
Lars Hjemli | b228d4f | 2008-02-16 13:07:13 +0100 | [diff] [blame] | 353 | if (ctx.cfg.enable_index_links) { |
Lars Hjemli | 0d05bca | 2007-06-19 00:56:40 +0200 | [diff] [blame] | 354 | html("<td>"); |
Lars Hjemli | 49ecbbd | 2008-10-05 17:16:36 +0200 | [diff] [blame] | 355 | cgit_summary_link("summary", NULL, "button", NULL); |
Lars Hjemli | 5114031 | 2007-11-03 10:42:37 +0100 | [diff] [blame] | 356 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
John Keeping | 30304d8 | 2015-08-12 15:55:28 +0100 | [diff] [blame] | 357 | 0, NULL, NULL, ctx.qry.showmsg, 0); |
Lars Hjemli | 0d05bca | 2007-06-19 00:56:40 +0200 | [diff] [blame] | 358 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); |
| 359 | html("</td>"); |
| 360 | } |
| 361 | html("</tr>\n"); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 362 | } |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 363 | html("</table>"); |
Peter Colberg | 9abe4a2 | 2015-12-08 12:53:09 -0500 | [diff] [blame] | 364 | if (hits > ctx.cfg.max_repo_count) |
Tobias Grimm | 7530d94 | 2011-07-31 02:44:05 +0200 | [diff] [blame] | 365 | print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); |
Lars Hjemli | 74620f1 | 2006-12-11 16:48:03 +0100 | [diff] [blame] | 366 | cgit_print_docend(); |
| 367 | } |
Lars Hjemli | c6431a7 | 2008-04-29 01:06:30 +0200 | [diff] [blame] | 368 | |
John Keeping | e3d3fff | 2015-03-08 16:32:16 +0000 | [diff] [blame] | 369 | void cgit_print_site_readme(void) |
Lars Hjemli | c6431a7 | 2008-04-29 01:06:30 +0200 | [diff] [blame] | 370 | { |
John Keeping | 51d9176 | 2015-08-14 12:47:12 +0100 | [diff] [blame] | 371 | cgit_print_layout_start(); |
Lars Hjemli | 537c05f | 2009-08-09 13:27:21 +0200 | [diff] [blame] | 372 | if (!ctx.cfg.root_readme) |
John Keeping | 51d9176 | 2015-08-14 12:47:12 +0100 | [diff] [blame] | 373 | goto done; |
Jason A. Donenfeld | 800380d | 2014-01-13 03:56:50 +0100 | [diff] [blame] | 374 | cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); |
Lars Hjemli | 537c05f | 2009-08-09 13:27:21 +0200 | [diff] [blame] | 375 | html_include(ctx.cfg.root_readme); |
Jason A. Donenfeld | 800380d | 2014-01-13 03:56:50 +0100 | [diff] [blame] | 376 | cgit_close_filter(ctx.cfg.about_filter); |
John Keeping | 51d9176 | 2015-08-14 12:47:12 +0100 | [diff] [blame] | 377 | done: |
| 378 | cgit_print_layout_end(); |
Lars Hjemli | c6431a7 | 2008-04-29 01:06:30 +0200 | [diff] [blame] | 379 | } |