2006-12-11 16:48:03 +01: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 23:25:25 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
2008-02-23 22:45:33 +01:00
|
|
|
#include "cgit.h"
|
|
|
|
#include "html.h"
|
2008-03-24 16:50:57 +01:00
|
|
|
#include "ui-shared.h"
|
2007-05-22 23:25:25 +02: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 09:29:22 +01:00
|
|
|
if (fgets(buf, sizeof(buf), f) == NULL)
|
|
|
|
return -1;
|
2007-05-22 23:25:25 +02:00
|
|
|
fclose(f);
|
|
|
|
if (parse_date(buf, buf2, sizeof(buf2)))
|
|
|
|
return strtoul(buf2, NULL, 10);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-16 13:56:09 +01:00
|
|
|
static void print_modtime(struct cgit_repo *repo)
|
2007-05-22 23:25:25 +02:00
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
struct stat s;
|
|
|
|
|
2008-02-16 13:07:13 +01:00
|
|
|
path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
|
2007-05-22 23:25:25 +02: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 16:48:03 +01:00
|
|
|
|
2008-04-13 11:57:10 +02:00
|
|
|
int is_match(struct cgit_repo *repo)
|
2006-12-11 16:48:03 +01:00
|
|
|
{
|
2008-04-13 11:57:10 +02:00
|
|
|
if (!ctx.qry.search)
|
|
|
|
return 1;
|
2008-04-13 12:42:27 +02:00
|
|
|
if (repo->url && strcasestr(repo->url, ctx.qry.search))
|
2008-04-13 11:57:10 +02:00
|
|
|
return 1;
|
2008-04-13 12:42:27 +02:00
|
|
|
if (repo->name && strcasestr(repo->name, ctx.qry.search))
|
2008-04-13 11:57:10 +02:00
|
|
|
return 1;
|
2008-04-13 12:42:27 +02:00
|
|
|
if (repo->desc && strcasestr(repo->desc, ctx.qry.search))
|
2008-04-13 11:57:10 +02:00
|
|
|
return 1;
|
2008-04-13 12:42:27 +02:00
|
|
|
if (repo->owner && strcasestr(repo->owner, ctx.qry.search))
|
2008-04-13 11:57:10 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-12-11 16:48:03 +01:00
|
|
|
|
2008-09-14 20:18:10 +02: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 11:57:10 +02:00
|
|
|
void print_header(int columns)
|
|
|
|
{
|
2007-01-28 00:39:26 +01:00
|
|
|
html("<tr class='nohover'>"
|
2006-12-22 01:44:32 +01:00
|
|
|
"<th class='left'>Name</th>"
|
|
|
|
"<th class='left'>Description</th>"
|
2007-05-16 02:12:06 +02:00
|
|
|
"<th class='left'>Owner</th>"
|
2007-06-19 00:56:40 +02:00
|
|
|
"<th class='left'>Idle</th>");
|
2008-02-16 13:07:13 +01:00
|
|
|
if (ctx.cfg.enable_index_links)
|
2008-04-13 10:57:11 +02:00
|
|
|
html("<th class='left'>Links</th>");
|
2007-06-19 00:56:40 +02:00
|
|
|
html("</tr>\n");
|
2008-04-13 11:57:10 +02:00
|
|
|
}
|
2006-12-11 16:48:03 +01:00
|
|
|
|
2008-05-03 10:54:39 +02: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 11:57:10 +02: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-29 00:35:49 +02:00
|
|
|
if (ctx.cfg.index_header)
|
|
|
|
html_include(ctx.cfg.index_header);
|
|
|
|
|
2008-04-13 11:57:10 +02:00
|
|
|
html("<table summary='repository list' class='list nowrap'>");
|
2007-02-03 15:02:55 +01:00
|
|
|
for (i=0; i<cgit_repolist.count; i++) {
|
2008-02-16 13:56:09 +01:00
|
|
|
ctx.repo = &cgit_repolist.repos[i];
|
2008-09-14 20:18:10 +02:00
|
|
|
if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
|
2008-04-13 11:57:10 +02:00
|
|
|
continue;
|
2008-05-03 10:54:39 +02:00
|
|
|
hits++;
|
|
|
|
if (hits <= ctx.qry.ofs)
|
|
|
|
continue;
|
|
|
|
if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
|
|
|
|
continue;
|
2008-04-13 11:57:10 +02:00
|
|
|
if (!header++)
|
|
|
|
print_header(columns);
|
2008-02-16 13:56:09 +01: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-19 00:56:40 +02:00
|
|
|
htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
|
|
|
|
columns);
|
2008-02-16 13:56:09 +01:00
|
|
|
html_txt(ctx.repo->group);
|
2007-05-18 22:48:22 +02:00
|
|
|
html("</td></tr>");
|
2008-02-16 13:56:09 +01:00
|
|
|
last_group = ctx.repo->group;
|
2007-05-18 22:48:22 +02:00
|
|
|
}
|
2007-05-21 00:14:28 +02:00
|
|
|
htmlf("<tr><td class='%s'>",
|
2008-02-16 13:56:09 +01:00
|
|
|
ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
|
2008-10-05 17:16:36 +02:00
|
|
|
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
|
2006-12-11 16:48:03 +01:00
|
|
|
html("</td><td>");
|
2008-04-14 22:23:48 +02:00
|
|
|
html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
|
2008-02-16 13:56:09 +01:00
|
|
|
html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
|
2008-04-14 22:23:48 +02:00
|
|
|
html_link_close();
|
2006-12-11 16:48:03 +01:00
|
|
|
html("</td><td>");
|
2008-02-16 13:56:09 +01:00
|
|
|
html_txt(ctx.repo->owner);
|
2007-05-16 02:12:06 +02:00
|
|
|
html("</td><td>");
|
2008-02-16 13:56:09 +01:00
|
|
|
print_modtime(ctx.repo);
|
2007-06-19 00:56:40 +02:00
|
|
|
html("</td>");
|
2008-02-16 13:07:13 +01:00
|
|
|
if (ctx.cfg.enable_index_links) {
|
2007-06-19 00:56:40 +02:00
|
|
|
html("<td>");
|
2008-10-05 17:16:36 +02:00
|
|
|
cgit_summary_link("summary", NULL, "button", NULL);
|
2007-11-03 10:42:37 +01:00
|
|
|
cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
|
|
|
|
0, NULL, NULL);
|
2007-06-19 00:56:40 +02:00
|
|
|
cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
|
|
|
|
html("</td>");
|
|
|
|
}
|
|
|
|
html("</tr>\n");
|
2006-12-11 16:48:03 +01:00
|
|
|
}
|
|
|
|
html("</table>");
|
2008-04-13 11:57:10 +02:00
|
|
|
if (!hits)
|
|
|
|
cgit_print_error("No repositories found");
|
2008-05-03 10:54:39 +02:00
|
|
|
else if (hits > ctx.cfg.max_repo_count)
|
|
|
|
print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
|
2006-12-11 16:48:03 +01:00
|
|
|
cgit_print_docend();
|
|
|
|
}
|
2008-04-29 01:06:30 +02:00
|
|
|
|
|
|
|
void cgit_print_site_readme()
|
|
|
|
{
|
|
|
|
if (ctx.cfg.root_readme)
|
|
|
|
html_include(ctx.cfg.root_readme);
|
|
|
|
}
|