author | Benjamin Close <Benjamin.Close@clearchain.com> | 2008-11-25 14:25:35 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-11-29 12:25:54 (UTC) |
commit | d71c0c725d7b5ddfc5b788d328a5fc7a27739662 (patch) (side-by-side diff) | |
tree | c7b0e71793470987c05a278dc5ed011a4903f524 | |
parent | 7b5cee65fd9cf31e4f19ce4ff613778cb95512a9 (diff) | |
download | cgit-d71c0c725d7b5ddfc5b788d328a5fc7a27739662.zip cgit-d71c0c725d7b5ddfc5b788d328a5fc7a27739662.tar.gz cgit-d71c0c725d7b5ddfc5b788d328a5fc7a27739662.tar.bz2 |
Add support for sorting by Age in the repolist
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | ui-repolist.c | 39 |
3 files changed, 39 insertions, 3 deletions
@@ -151,12 +151,14 @@ static void querystring_cb(const char *name, const char *value) } else if (!strcmp(name, "path")) { ctx.qry.path = trim_end(value, '/'); } else if (!strcmp(name, "name")) { ctx.qry.name = xstrdup(value); } else if (!strcmp(name, "mimetype")) { ctx.qry.mimetype = xstrdup(value); + } else if (!strcmp(name, "s")){ + ctx.qry.sort = xstrdup(value); } } static void prepare_context(struct cgit_context *ctx) { memset(ctx, 0, sizeof(ctx)); @@ -118,12 +118,13 @@ struct cgit_query { char *path; char *name; char *mimetype; char *url; int ofs; int nohead; + char *sort; }; struct cgit_config { char *agefile; char *cache_root; char *clone_prefix; diff --git a/ui-repolist.c b/ui-repolist.c index c23232c..312a7ee 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -72,13 +72,13 @@ int is_in_url(struct cgit_repo *repo) void print_header(int columns) { html("<tr class='nohover'>" "<th class='left'>Name</th>" "<th class='left'>Description</th>" "<th class='left'>Owner</th>" - "<th class='left'>Idle</th>"); + "<th class='left'><a href=\"?s=1\">Idle</a></th>"); if (ctx.cfg.enable_index_links) html("<th class='left'>Links</th>"); html("</tr>\n"); } @@ -89,12 +89,41 @@ void print_pager(int items, int pagelen, char *search) 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>"); } +static int cgit_reposort_modtime(const void *a, const void *b) +{ + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; + char *path; + struct stat s; + time_t t1, t2; + path = fmt("%s/%s", r1->path, ctx.cfg.agefile); + if (stat(path, &s) == 0) { + t1 = read_agefile(path); + } else { + path = fmt("%s/refs/heads/%s", r1->path, r1->defbranch); + if (stat(path, &s) != 0) + return 0; + t1 =s.st_mtime; + } + + path = fmt("%s/%s", r2->path, ctx.cfg.agefile); + if (stat(path, &s) == 0) { + t2 = read_agefile(path); + } else { + path = fmt("%s/refs/heads/%s", r2->path, r2->defbranch); + if (stat(path, &s) != 0) + return 0; + t2 =s.st_mtime; + } + return t2-t1; +} + void cgit_print_repolist() { int i, columns = 4, hits = 0, header = 0; char *last_group = NULL; if (ctx.cfg.enable_index_links) @@ -105,28 +134,32 @@ void cgit_print_repolist() cgit_print_docstart(&ctx); cgit_print_pageheader(&ctx); if (ctx.cfg.index_header) html_include(ctx.cfg.index_header); + if(ctx.qry.sort) + qsort(cgit_repolist.repos,cgit_repolist.count,sizeof(struct cgit_repo),cgit_reposort_modtime); + html("<table summary='repository list' class='list nowrap'>"); for (i=0; i<cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) continue; hits++; if (hits <= ctx.qry.ofs) continue; if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) continue; if (!header++) print_header(columns); - if ((last_group == NULL && ctx.repo->group != NULL) || + if (!ctx.qry.sort && + ((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))) { + strcmp(ctx.repo->group, last_group)))) { htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", columns); html_txt(ctx.repo->group); html("</td></tr>"); last_group = ctx.repo->group; } |