2006-12-11 15:48:03 +00:00
|
|
|
/* ui-repolist.c: functions for generating the repolist page
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Lars Hjemli
|
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
2007-05-22 21:25:25 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2008-02-23 21:45:33 +00:00
|
|
|
#include "cgit.h"
|
|
|
|
#include "html.h"
|
2008-03-24 15:50:57 +00:00
|
|
|
#include "ui-shared.h"
|
2007-05-22 21:25:25 +00:00
|
|
|
|
|
|
|
time_t read_agefile(char *path)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
static char buf[64], buf2[64];
|
|
|
|
|
|
|
|
if (!(f = fopen(path, "r")))
|
|
|
|
return -1;
|
2008-11-14 08:29:22 +00:00
|
|
|
if (fgets(buf, sizeof(buf), f) == NULL)
|
|
|
|
return -1;
|
2007-05-22 21:25:25 +00:00
|
|
|
fclose(f);
|
|
|
|
if (parse_date(buf, buf2, sizeof(buf2)))
|
|
|
|
return strtoul(buf2, NULL, 10);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-16 12:56:09 +00:00
|
|
|
static void print_modtime(struct cgit_repo *repo)
|
2007-05-22 21:25:25 +00:00
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
struct stat s;
|
|
|
|
|
2008-02-16 12:07:13 +00:00
|
|
|
path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
|
2007-05-22 21:25:25 +00:00
|
|
|
if (stat(path, &s) == 0) {
|
|
|
|
cgit_print_age(read_agefile(path), -1, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
|
|
|
|
if (stat(path, &s) != 0)
|
|
|
|
return;
|
|
|
|
cgit_print_age(s.st_mtime, -1, NULL);
|
|
|
|
}
|
2006-12-11 15:48:03 +00:00
|
|
|
|
2008-04-13 09:57:10 +00:00
|
|
|
int is_match(struct cgit_repo *repo)
|
2006-12-11 15:48:03 +00:00
|
|
|
{
|
2008-04-13 09:57:10 +00:00
|
|
|
if (!ctx.qry.search)
|
|
|
|
return 1;
|
2008-04-13 10:42:27 +00:00
|
|
|
if (repo->url && strcasestr(repo->url, ctx.qry.search))
|
2008-04-13 09:57:10 +00:00
|
|
|
return 1;
|
2008-04-13 10:42:27 +00:00
|
|
|
if (repo->name && strcasestr(repo->name, ctx.qry.search))
|
2008-04-13 09:57:10 +00:00
|
|
|
return 1;
|
2008-04-13 10:42:27 +00:00
|
|
|
if (repo->desc && strcasestr(repo->desc, ctx.qry.search))
|
2008-04-13 09:57:10 +00:00
|
|
|
return 1;
|
2008-04-13 10:42:27 +00:00
|
|
|
if (repo->owner && strcasestr(repo->owner, ctx.qry.search))
|
2008-04-13 09:57:10 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-12-11 15:48:03 +00:00
|
|
|
|
2008-09-14 18:18:10 +00:00
|
|
|
int is_in_url(struct cgit_repo *repo)
|
|
|
|
{
|
|
|
|
if (!ctx.qry.url)
|
|
|
|
return 1;
|
|
|
|
if (repo->url && !prefixcmp(repo->url, ctx.qry.url))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-13 09:57:10 +00:00
|
|
|
void print_header(int columns)
|
|
|
|
{
|
2007-01-27 23:39:26 +00:00
|
|
|
html("<tr class='nohover'>"
|
2006-12-22 00:44:32 +00:00
|
|
|
"<th class='left'>Name</th>"
|
|
|
|
"<th class='left'>Description</th>"
|
2007-05-16 00:12:06 +00:00
|
|
|
"<th class='left'>Owner</th>"
|
2007-06-18 22:56:40 +00:00
|
|
|
"<th class='left'>Idle</th>");
|
2008-02-16 12:07:13 +00:00
|
|
|
if (ctx.cfg.enable_index_links)
|
2008-04-13 08:57:11 +00:00
|
|
|
html("<th class='left'>Links</th>");
|
2007-06-18 22:56:40 +00:00
|
|
|
html("</tr>\n");
|
2008-04-13 09:57:10 +00:00
|
|
|
}
|
2006-12-11 15:48:03 +00:00
|
|
|
|
2008-05-03 08:54:39 +00:00
|
|
|
|
|
|
|
void print_pager(int items, int pagelen, char *search)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
html("<div class='pager'>");
|
|
|
|
for(i = 0; i * pagelen < items; i++)
|
|
|
|
cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL,
|
|
|
|
search, i * pagelen);
|
|
|
|
html("</div>");
|
|
|
|
}
|
|
|
|
|
2008-04-13 09:57:10 +00:00
|
|
|
void cgit_print_repolist()
|
|
|
|
{
|
|
|
|
int i, columns = 4, hits = 0, header = 0;
|
|
|
|
char *last_group = NULL;
|
|
|
|
|
|
|
|
if (ctx.cfg.enable_index_links)
|
|
|
|
columns++;
|
|
|
|
|
|
|
|
ctx.page.title = ctx.cfg.root_title;
|
|
|
|
cgit_print_http_headers(&ctx);
|
|
|
|
cgit_print_docstart(&ctx);
|
|
|
|
cgit_print_pageheader(&ctx);
|
|
|
|
|
2008-04-28 22:35:49 +00:00
|
|
|
if (ctx.cfg.index_header)
|
|
|
|
html_include(ctx.cfg.index_header);
|
|
|
|
|
2008-04-13 09:57:10 +00:00
|
|
|
html("<table summary='repository list' class='list nowrap'>");
|
2007-02-03 14:02:55 +00:00
|
|
|
for (i=0; i<cgit_repolist.count; i++) {
|
2008-02-16 12:56:09 +00:00
|
|
|
ctx.repo = &cgit_repolist.repos[i];
|
2008-09-14 18:18:10 +00:00
|
|
|
if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
|
2008-04-13 09:57:10 +00:00
|
|
|
continue;
|
2008-05-03 08:54:39 +00:00
|
|
|
hits++;
|
|
|
|
if (hits <= ctx.qry.ofs)
|
|
|
|
continue;
|
|
|
|
if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
|
|
|
|
continue;
|
2008-04-13 09:57:10 +00:00
|
|
|
if (!header++)
|
|
|
|
print_header(columns);
|
2008-02-16 12:56:09 +00:00
|
|
|
if ((last_group == NULL && ctx.repo->group != NULL) ||
|
|
|
|
(last_group != NULL && ctx.repo->group == NULL) ||
|
|
|
|
(last_group != NULL && ctx.repo->group != NULL &&
|
|
|
|
strcmp(ctx.repo->group, last_group))) {
|
2007-06-18 22:56:40 +00:00
|
|
|
htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
|
|
|
|
columns);
|
2008-02-16 12:56:09 +00:00
|
|
|
html_txt(ctx.repo->group);
|
2007-05-18 20:48:22 +00:00
|
|
|
html("</td></tr>");
|
2008-02-16 12:56:09 +00:00
|
|
|
last_group = ctx.repo->group;
|
2007-05-18 20:48:22 +00:00
|
|
|
}
|
2007-05-20 22:14:28 +00:00
|
|
|
htmlf("<tr><td class='%s'>",
|
2008-02-16 12:56:09 +00:00
|
|
|
ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
|
2008-10-05 15:16:36 +00:00
|
|
|
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
|
2006-12-11 15:48:03 +00:00
|
|
|
html("</td><td>");
|
2008-04-14 20:23:48 +00:00
|
|
|
html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
|
2008-02-16 12:56:09 +00:00
|
|
|
html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
|
2008-04-14 20:23:48 +00:00
|
|
|
html_link_close();
|
2006-12-11 15:48:03 +00:00
|
|
|
html("</td><td>");
|
2008-02-16 12:56:09 +00:00
|
|
|
html_txt(ctx.repo->owner);
|
2007-05-16 00:12:06 +00:00
|
|
|
html("</td><td>");
|
2008-02-16 12:56:09 +00:00
|
|
|
print_modtime(ctx.repo);
|
2007-06-18 22:56:40 +00:00
|
|
|
html("</td>");
|
2008-02-16 12:07:13 +00:00
|
|
|
if (ctx.cfg.enable_index_links) {
|
2007-06-18 22:56:40 +00:00
|
|
|
html("<td>");
|
2008-10-05 15:16:36 +00:00
|
|
|
cgit_summary_link("summary", NULL, "button", NULL);
|
2007-11-03 09:42:37 +00:00
|
|
|
cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
|
|
|
|
0, NULL, NULL);
|
2007-06-18 22:56:40 +00:00
|
|
|
cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
|
|
|
|
html("</td>");
|
|
|
|
}
|
|
|
|
html("</tr>\n");
|
2006-12-11 15:48:03 +00:00
|
|
|
}
|
|
|
|
html("</table>");
|
2008-04-13 09:57:10 +00:00
|
|
|
if (!hits)
|
|
|
|
cgit_print_error("No repositories found");
|
2008-05-03 08:54:39 +00:00
|
|
|
else if (hits > ctx.cfg.max_repo_count)
|
|
|
|
print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
|
2006-12-11 15:48:03 +00:00
|
|
|
cgit_print_docend();
|
|
|
|
}
|
2008-04-28 23:06:30 +00:00
|
|
|
|
|
|
|
void cgit_print_site_readme()
|
|
|
|
{
|
|
|
|
if (ctx.cfg.root_readme)
|
|
|
|
html_include(ctx.cfg.root_readme);
|
|
|
|
}
|