+static int cgit_reposort_modtime(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+ time_t t1, t2;
+
+ t1 = t2 = 0;
+ get_repo_modtime(r1, &t1);
+ get_repo_modtime(r2, &t2);
+ 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)
+ columns++;
+
+ ctx.page.title = ctx.cfg.root_title;
+ cgit_print_http_headers(&ctx);
+ 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'>");