author | Lars Hjemli <hjemli@gmail.com> | 2007-10-25 18:33:04 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:53:19 (UTC) |
commit | ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc (patch) (unidiff) | |
tree | 5c9d40e556a5787e9338bc506dec37360f54d8f5 | |
parent | 502d71072a813e6fadb2e59fb47c2782b542674a (diff) | |
download | cgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.zip cgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.tar.gz cgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.tar.bz2 |
Sort tags by age
This adds a function to compare timestamps and then uses it as callback
for qsort() before printing out tags.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-summary.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ui-summary.c b/ui-summary.c index c684628..43582da 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,28 +1,45 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cmp_tag_age(void *a, void *b) | ||
14 | { | ||
15 | struct refinfo *r1 = *(struct refinfo **)a; | ||
16 | struct refinfo *r2 = *(struct refinfo **)b; | ||
17 | |||
18 | if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0) | ||
19 | return r2->tag->tagger_date - r1->tag->tagger_date; | ||
20 | |||
21 | if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0) | ||
22 | return 0; | ||
23 | |||
24 | if (r1 == 0) | ||
25 | return +1; | ||
26 | |||
27 | return -1; | ||
28 | } | ||
29 | |||
13 | static void cgit_print_branch(struct refinfo *ref) | 30 | static void cgit_print_branch(struct refinfo *ref) |
14 | { | 31 | { |
15 | struct commit *commit; | 32 | struct commit *commit; |
16 | struct commitinfo *info; | 33 | struct commitinfo *info; |
17 | char *name = (char *)ref->refname; | 34 | char *name = (char *)ref->refname; |
18 | 35 | ||
19 | commit = lookup_commit(ref->object->sha1); | 36 | commit = lookup_commit(ref->object->sha1); |
20 | // object is not really parsed at this point, because of some fallout | 37 | // object is not really parsed at this point, because of some fallout |
21 | // from previous calls to git functions in cgit_print_log() | 38 | // from previous calls to git functions in cgit_print_log() |
22 | commit->object.parsed = 0; | 39 | commit->object.parsed = 0; |
23 | if (commit && !parse_commit(commit)){ | 40 | if (commit && !parse_commit(commit)){ |
24 | info = cgit_parse_commit(commit); | 41 | info = cgit_parse_commit(commit); |
25 | html("<tr><td>"); | 42 | html("<tr><td>"); |
26 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 43 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
27 | html("</td><td>"); | 44 | html("</td><td>"); |
28 | cgit_print_age(commit->date, -1, NULL); | 45 | cgit_print_age(commit->date, -1, NULL); |
@@ -143,32 +160,33 @@ static void cgit_print_branches() | |||
143 | for_each_branch_ref(cgit_refs_cb, &list); | 160 | for_each_branch_ref(cgit_refs_cb, &list); |
144 | for(i=0; i<list.count; i++) | 161 | for(i=0; i<list.count; i++) |
145 | cgit_print_branch(list.refs[i]); | 162 | cgit_print_branch(list.refs[i]); |
146 | } | 163 | } |
147 | 164 | ||
148 | static void cgit_print_tags() | 165 | static void cgit_print_tags() |
149 | { | 166 | { |
150 | struct reflist list; | 167 | struct reflist list; |
151 | int i; | 168 | int i; |
152 | 169 | ||
153 | header = 0; | 170 | header = 0; |
154 | list.refs = NULL; | 171 | list.refs = NULL; |
155 | list.alloc = list.count = 0; | 172 | list.alloc = list.count = 0; |
156 | for_each_tag_ref(cgit_refs_cb, &list); | 173 | for_each_tag_ref(cgit_refs_cb, &list); |
157 | if (list.count == 0) | 174 | if (list.count == 0) |
158 | return; | 175 | return; |
176 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | ||
159 | print_tag_header(); | 177 | print_tag_header(); |
160 | for(i=0; i<list.count; i++) | 178 | for(i=0; i<list.count; i++) |
161 | print_tag(list.refs[i]); | 179 | print_tag(list.refs[i]); |
162 | } | 180 | } |
163 | 181 | ||
164 | static void cgit_print_archives() | 182 | static void cgit_print_archives() |
165 | { | 183 | { |
166 | header = 0; | 184 | header = 0; |
167 | for_each_ref(cgit_print_archive_cb, NULL); | 185 | for_each_ref(cgit_print_archive_cb, NULL); |
168 | if (header) | 186 | if (header) |
169 | html("</table>"); | 187 | html("</table>"); |
170 | } | 188 | } |
171 | 189 | ||
172 | void cgit_print_summary() | 190 | void cgit_print_summary() |
173 | { | 191 | { |
174 | html("<div id='summary'>"); | 192 | html("<div id='summary'>"); |