Diff options
Diffstat (limited to '')
-rw-r--r--source/ui-repolist.c72
1 file changed, 22 insertions, 50 deletions
diff --git a/source/ui-repolist.c b/source/ui-repolist.c
index 6df70e4..4e4f61b 100644
--- a/source/ui-repolist.c
+++ b/source/ui-repolist.c
@@ -27,11 +27,10 @@ struct sort_column {
static time_t read_agefile(const char *path)
{
time_t result;
- size_t size;
char *buf = NULL;
struct strbuf date = STRBUF_INIT;
- if (cgit_read_first_line(path, &buf, &size)) {
+ if (cgit_read_first_line(path, &buf)) {
free(buf);
return 0;
}
@@ -77,7 +76,7 @@ static const char *tip_branch(const struct cgit_repo *repo, struct strbuf *head)
return branch ? branch : "master";
}
-static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
+static time_t get_repo_modtime(const struct cgit_repo *repo)
{
struct strbuf path = STRBUF_INIT;
struct strbuf head = STRBUF_INIT;
@@ -87,39 +86,30 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
// is kept in the repository itself so one page stats it only once.
struct cgit_repo *writable = (struct cgit_repo *)repo;
- if (repo->mtime != -1) {
- *mtime = repo->mtime;
- return 1;
- }
+ if (repo->mtime != -1)
+ return repo->mtime;
// A repository configured without a path has nothing on disk to date.
if (!repo->path) {
- *mtime = 0;
writable->mtime = 0;
return 0;
}
strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile);
- if (stat(path.buf, &st) == 0) {
- *mtime = read_agefile(path.buf);
- if (*mtime) {
- writable->mtime = *mtime;
- goto end;
- }
- }
+ writable->mtime = read_agefile(path.buf);
+ if (repo->mtime)
+ goto end;
branch = tip_branch(repo, &head);
strbuf_reset(&path);
strbuf_addf(&path, "%s/refs/heads/%s", repo->path, branch);
if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
+ writable->mtime = st.st_mtime;
goto end;
}
strbuf_reset(&path);
strbuf_addf(&path, "%s/packed-refs", repo->path);
if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
+ writable->mtime = st.st_mtime;
goto end;
}
@@ -127,26 +117,12 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
// every ref update.
strbuf_reset(&path);
strbuf_addf(&path, "%s/reftable/tables.list", repo->path);
- if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
- goto end;
- }
-
- *mtime = 0;
- writable->mtime = *mtime;
+ if (stat(path.buf, &st) == 0)
+ writable->mtime = st.st_mtime;
end:
strbuf_release(&path);
strbuf_release(&head);
- return (writable->mtime != 0);
-}
-
-static void print_modtime(struct cgit_repo *repo)
-{
- time_t mtime;
-
- if (get_repo_modtime(repo, &mtime))
- cgit_print_age(mtime, 0, -1);
+ return repo->mtime;
}
static int matches_search(struct cgit_repo *repo)
@@ -247,11 +223,13 @@ static void print_repo_row(const char *currenturl, int sublevel)
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
html("</td><td class='col-desc'>");
repourl = cgit_repourl(ctx.repo->url);
- html_link_open(repourl, NULL, NULL);
+ html("<a href='");
+ html_attr(repourl);
+ html("'>");
free(repourl);
if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0)
html("...");
- html_link_close();
+ html("</a>");
html("</td>");
if (ctx.cfg.enable_index_owner) {
html("<td class='col-owner'>");
@@ -269,7 +247,7 @@ static void print_repo_row(const char *currenturl, int sublevel)
html("</td>");
}
html("<td class='col-idle'>");
- print_modtime(ctx.repo);
+ cgit_print_age(get_repo_modtime(ctx.repo), 0, -1);
html("</td>");
if (ctx.cfg.enable_index_links) {
html("<td class='col-links'>");
@@ -340,11 +318,8 @@ static int cmp_idle(const void *a, const void *b)
{
const struct cgit_repo *r1 = a;
const struct cgit_repo *r2 = b;
- time_t t1, t2;
+ time_t t1 = get_repo_modtime(r1), t2 = get_repo_modtime(r2);
- t1 = t2 = 0;
- get_repo_modtime(r1, &t1);
- get_repo_modtime(r2, &t2);
// Only the sign is returned, because a 64-bit difference truncated
// into an int could come back with the wrong sign and leave the
// ordering inconsistent.
@@ -377,11 +352,10 @@ static int cmp_section(const void *a, const void *b)
*/
static void resolve_modtimes(void)
{
- time_t t;
int i;
for (i = 0; i < cgit_repolist.count; i++)
- get_repo_modtime(&cgit_repolist.repos[i], &t);
+ get_repo_modtime(&cgit_repolist.repos[i]);
}
static const struct sort_column sort_columns[] = {
@@ -402,7 +376,7 @@ static int sort_repolist(const char *field)
continue;
if (column->cmp == cmp_idle || column->cmp == cmp_section)
resolve_modtimes();
- cgit_qsort(cgit_repolist.repos, cgit_repolist.count, sizeof(struct cgit_repo), column->cmp);
+ QSORT(cgit_repolist.repos, cgit_repolist.count, column->cmp);
return 1;
}
return 0;
@@ -429,9 +403,7 @@ void cgit_print_repolist(void)
++columns;
ctx.page.title = ctx.cfg.root_title;
- cgit_print_http_headers();
- cgit_print_docstart();
- cgit_print_pageheader();
+ cgit_print_layout_start();
if (ctx.qry.sort)
column_sorted = sort_repolist(ctx.qry.sort);
@@ -473,7 +445,7 @@ void cgit_print_repolist(void)
if (hits > ctx.cfg.max_repo_count)
print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
free(currenturl);
- cgit_print_docend();
+ cgit_print_layout_end();
}
void cgit_print_site_readme(void)