-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
@@ -156,2 +156,4 @@ static void querystring_cb(const char *name, const char *value) | |||
156 | ctx.qry.mimetype = xstrdup(value); | 156 | ctx.qry.mimetype = xstrdup(value); |
157 | } else if (!strcmp(name, "s")){ | ||
158 | ctx.qry.sort = xstrdup(value); | ||
157 | } | 159 | } |
@@ -123,2 +123,3 @@ struct cgit_query { | |||
123 | int nohead; | 123 | int nohead; |
124 | char *sort; | ||
124 | }; | 125 | }; |
diff --git a/ui-repolist.c b/ui-repolist.c index c23232c..312a7ee 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -77,3 +77,3 @@ void print_header(int columns) | |||
77 | "<th class='left'>Owner</th>" | 77 | "<th class='left'>Owner</th>" |
78 | "<th class='left'>Idle</th>"); | 78 | "<th class='left'><a href=\"?s=1\">Idle</a></th>"); |
79 | if (ctx.cfg.enable_index_links) | 79 | if (ctx.cfg.enable_index_links) |
@@ -94,2 +94,31 @@ void print_pager(int items, int pagelen, char *search) | |||
94 | 94 | ||
95 | static int cgit_reposort_modtime(const void *a, const void *b) | ||
96 | { | ||
97 | const struct cgit_repo *r1 = a; | ||
98 | const struct cgit_repo *r2 = b; | ||
99 | char *path; | ||
100 | struct stat s; | ||
101 | time_t t1, t2; | ||
102 | path = fmt("%s/%s", r1->path, ctx.cfg.agefile); | ||
103 | if (stat(path, &s) == 0) { | ||
104 | t1 = read_agefile(path); | ||
105 | } else { | ||
106 | path = fmt("%s/refs/heads/%s", r1->path, r1->defbranch); | ||
107 | if (stat(path, &s) != 0) | ||
108 | return 0; | ||
109 | t1 =s.st_mtime; | ||
110 | } | ||
111 | |||
112 | path = fmt("%s/%s", r2->path, ctx.cfg.agefile); | ||
113 | if (stat(path, &s) == 0) { | ||
114 | t2 = read_agefile(path); | ||
115 | } else { | ||
116 | path = fmt("%s/refs/heads/%s", r2->path, r2->defbranch); | ||
117 | if (stat(path, &s) != 0) | ||
118 | return 0; | ||
119 | t2 =s.st_mtime; | ||
120 | } | ||
121 | return t2-t1; | ||
122 | } | ||
123 | |||
95 | void cgit_print_repolist() | 124 | void cgit_print_repolist() |
@@ -110,2 +139,5 @@ void cgit_print_repolist() | |||
110 | 139 | ||
140 | if(ctx.qry.sort) | ||
141 | qsort(cgit_repolist.repos,cgit_repolist.count,sizeof(struct cgit_repo),cgit_reposort_modtime); | ||
142 | |||
111 | html("<table summary='repository list' class='list nowrap'>"); | 143 | html("<table summary='repository list' class='list nowrap'>"); |
@@ -122,6 +154,7 @@ void cgit_print_repolist() | |||
122 | print_header(columns); | 154 | print_header(columns); |
123 | if ((last_group == NULL && ctx.repo->group != NULL) || | 155 | if (!ctx.qry.sort && |
156 | ((last_group == NULL && ctx.repo->group != NULL) || | ||
124 | (last_group != NULL && ctx.repo->group == NULL) || | 157 | (last_group != NULL && ctx.repo->group == NULL) || |
125 | (last_group != NULL && ctx.repo->group != NULL && | 158 | (last_group != NULL && ctx.repo->group != NULL && |
126 | strcmp(ctx.repo->group, last_group))) { | 159 | strcmp(ctx.repo->group, last_group)))) { |
127 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 160 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |