+time_t read_agefile(char *path)
+{
+ time_t result;
+ size_t size;
+ char *buf;
+ static char buf2[64];
+
+ if (readfile(path, &buf, &size))
+ return -1;
+
+ if (parse_date(buf, buf2, sizeof(buf2)) > 0)
+ result = strtoul(buf2, NULL, 10);
+ else
+ result = 0;
+ free(buf);
+ return result;
+}
+
+static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
+{
+ char *path;
+ struct stat s;
+ struct cgit_repo *r = (struct cgit_repo *)repo;
+
+ if (repo->mtime != -1) {
+ *mtime = repo->mtime;
+ return 1;
+ }
+ path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
+ if (stat(path, &s) == 0) {
+ *mtime = read_agefile(path);
+ r->mtime = *mtime;
+ return 1;
+ }
+
+ path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
+ if (stat(path, &s) == 0) {
+ *mtime = s.st_mtime;
+ r->mtime = *mtime;
+ return 1;
+ }
+
+ path = fmt("%s/%s", repo->path, "packed-refs");
+ if (stat(path, &s) == 0) {
+ *mtime = s.st_mtime;
+ r->mtime = *mtime;
+ return 1;
+ }
+
+ *mtime = 0;
+ r->mtime = *mtime;
+ return (r->mtime != 0);
+}
+
+static void print_modtime(struct cgit_repo *repo)
+{
+ time_t t;
+ if (get_repo_modtime(repo, &t))
+ cgit_print_age(t, -1, NULL);
+}
+
+int is_match(struct cgit_repo *repo)
+{
+ if (!ctx.qry.search)
+ return 1;
+ if (repo->url && strcasestr(repo->url, ctx.qry.search))
+ return 1;
+ if (repo->name && strcasestr(repo->name, ctx.qry.search))
+ return 1;
+ if (repo->desc && strcasestr(repo->desc, ctx.qry.search))
+ return 1;
+ if (repo->owner && strcasestr(repo->owner, ctx.qry.search))
+ return 1;
+ return 0;
+}
+
+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;
+}
+
+void print_sort_header(const char *title, const char *sort)
+{
+ htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort);
+ if (ctx.qry.search) {
+ html("&q=");
+ html_url_arg(ctx.qry.search);
+ }
+ htmlf("'>%s</a></th>", title);
+}
+
+void print_header(int columns)
+{
+ html("<tr class='nohover'>");
+ print_sort_header("Name", "name");
+ print_sort_header("Description", "desc");
+ print_sort_header("Owner", "owner");
+ print_sort_header("Idle", "idle");
+ if (ctx.cfg.enable_index_links)
+ html("<th class='left'>Links</th>");
+ html("</tr>\n");
+}
+
+
+void print_pager(int items, int pagelen, char *search)