+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;
+}
+