summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-10-25 18:33:04 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-27 08:53:19 (UTC)
commitef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc (patch) (unidiff)
tree5c9d40e556a5787e9338bc506dec37360f54d8f5
parent502d71072a813e6fadb2e59fb47c2782b542674a (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c18
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,193 +1,211 @@
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
11static int header; 11static int header;
12 12
13static 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
13static void cgit_print_branch(struct refinfo *ref) 30static 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);
29 html("</td><td>"); 46 html("</td><td>");
30 html_txt(info->author); 47 html_txt(info->author);
31 html("</td><td>"); 48 html("</td><td>");
32 cgit_commit_link(info->subject, NULL, NULL, name, NULL); 49 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
33 html("</td></tr>\n"); 50 html("</td></tr>\n");
34 cgit_free_commitinfo(info); 51 cgit_free_commitinfo(info);
35 } else { 52 } else {
36 html("<tr><td>"); 53 html("<tr><td>");
37 html_txt(name); 54 html_txt(name);
38 html("</td><td colspan='3'>"); 55 html("</td><td colspan='3'>");
39 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); 56 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
40 html("</td></tr>\n"); 57 html("</td></tr>\n");
41 } 58 }
42} 59}
43 60
44static void print_tag_header() 61static void print_tag_header()
45{ 62{
46 html("<tr class='nohover'><th class='left'>Tag</th>" 63 html("<tr class='nohover'><th class='left'>Tag</th>"
47 "<th class='left'>Age</th>" 64 "<th class='left'>Age</th>"
48 "<th class='left'>Author</th>" 65 "<th class='left'>Author</th>"
49 "<th class='left'>Reference</th></tr>\n"); 66 "<th class='left'>Reference</th></tr>\n");
50 header = 1; 67 header = 1;
51} 68}
52 69
53static int print_tag(struct refinfo *ref) 70static int print_tag(struct refinfo *ref)
54{ 71{
55 struct tag *tag; 72 struct tag *tag;
56 struct taginfo *info; 73 struct taginfo *info;
57 char *url, *name = (char *)ref->refname; 74 char *url, *name = (char *)ref->refname;
58 75
59 if (ref->object->type == OBJ_TAG) { 76 if (ref->object->type == OBJ_TAG) {
60 tag = lookup_tag(ref->object->sha1); 77 tag = lookup_tag(ref->object->sha1);
61 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 78 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
62 return 2; 79 return 2;
63 html("<tr><td>"); 80 html("<tr><td>");
64 url = cgit_pageurl(cgit_query_repo, "tag", 81 url = cgit_pageurl(cgit_query_repo, "tag",
65 fmt("id=%s", name)); 82 fmt("id=%s", name));
66 html_link_open(url, NULL, NULL); 83 html_link_open(url, NULL, NULL);
67 html_txt(name); 84 html_txt(name);
68 html_link_close(); 85 html_link_close();
69 html("</td><td>"); 86 html("</td><td>");
70 if (info->tagger_date > 0) 87 if (info->tagger_date > 0)
71 cgit_print_age(info->tagger_date, -1, NULL); 88 cgit_print_age(info->tagger_date, -1, NULL);
72 html("</td><td>"); 89 html("</td><td>");
73 if (info->tagger) 90 if (info->tagger)
74 html(info->tagger); 91 html(info->tagger);
75 html("</td><td>"); 92 html("</td><td>");
76 cgit_object_link(tag->tagged); 93 cgit_object_link(tag->tagged);
77 html("</td></tr>\n"); 94 html("</td></tr>\n");
78 } else { 95 } else {
79 if (!header) 96 if (!header)
80 print_tag_header(); 97 print_tag_header();
81 html("<tr><td>"); 98 html("<tr><td>");
82 html_txt(name); 99 html_txt(name);
83 html("</td><td colspan='2'/><td>"); 100 html("</td><td colspan='2'/><td>");
84 cgit_object_link(ref->object); 101 cgit_object_link(ref->object);
85 html("</td></tr>\n"); 102 html("</td></tr>\n");
86 } 103 }
87 return 0; 104 return 0;
88} 105}
89 106
90static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, 107static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
91 int flags, void *cb_data) 108 int flags, void *cb_data)
92{ 109{
93 struct tag *tag; 110 struct tag *tag;
94 struct taginfo *info; 111 struct taginfo *info;
95 struct object *obj; 112 struct object *obj;
96 char buf[256], *url; 113 char buf[256], *url;
97 unsigned char fileid[20]; 114 unsigned char fileid[20];
98 115
99 if (prefixcmp(refname, "refs/archives")) 116 if (prefixcmp(refname, "refs/archives"))
100 return 0; 117 return 0;
101 strncpy(buf, refname+14, sizeof(buf)); 118 strncpy(buf, refname+14, sizeof(buf));
102 obj = parse_object(sha1); 119 obj = parse_object(sha1);
103 if (!obj) 120 if (!obj)
104 return 1; 121 return 1;
105 if (obj->type == OBJ_TAG) { 122 if (obj->type == OBJ_TAG) {
106 tag = lookup_tag(sha1); 123 tag = lookup_tag(sha1);
107 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 124 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
108 return 0; 125 return 0;
109 hashcpy(fileid, tag->tagged->sha1); 126 hashcpy(fileid, tag->tagged->sha1);
110 } else if (obj->type != OBJ_BLOB) { 127 } else if (obj->type != OBJ_BLOB) {
111 return 0; 128 return 0;
112 } else { 129 } else {
113 hashcpy(fileid, sha1); 130 hashcpy(fileid, sha1);
114 } 131 }
115 if (!header) { 132 if (!header) {
116 html("<table id='downloads'>"); 133 html("<table id='downloads'>");
117 html("<tr><th>Downloads</th></tr>"); 134 html("<tr><th>Downloads</th></tr>");
118 header = 1; 135 header = 1;
119 } 136 }
120 html("<tr><td>"); 137 html("<tr><td>");
121 url = cgit_pageurl(cgit_query_repo, "blob", 138 url = cgit_pageurl(cgit_query_repo, "blob",
122 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 139 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
123 buf)); 140 buf));
124 html_link_open(url, NULL, NULL); 141 html_link_open(url, NULL, NULL);
125 html_txt(buf); 142 html_txt(buf);
126 html_link_close(); 143 html_link_close();
127 html("</td></tr>"); 144 html("</td></tr>");
128 return 0; 145 return 0;
129} 146}
130 147
131static void cgit_print_branches() 148static void cgit_print_branches()
132{ 149{
133 struct reflist list; 150 struct reflist list;
134 int i; 151 int i;
135 152
136 html("<tr class='nohover'><th class='left'>Branch</th>" 153 html("<tr class='nohover'><th class='left'>Branch</th>"
137 "<th class='left'>Idle</th>" 154 "<th class='left'>Idle</th>"
138 "<th class='left'>Author</th>" 155 "<th class='left'>Author</th>"
139 "<th class='left'>Head commit</th></tr>\n"); 156 "<th class='left'>Head commit</th></tr>\n");
140 157
141 list.refs = NULL; 158 list.refs = NULL;
142 list.alloc = list.count = 0; 159 list.alloc = list.count = 0;
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
148static void cgit_print_tags() 165static 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
164static void cgit_print_archives() 182static 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
172void cgit_print_summary() 190void cgit_print_summary()
173{ 191{
174 html("<div id='summary'>"); 192 html("<div id='summary'>");
175 cgit_print_archives(); 193 cgit_print_archives();
176 html("<h2>"); 194 html("<h2>");
177 html_txt(cgit_repo->name); 195 html_txt(cgit_repo->name);
178 html(" - "); 196 html(" - ");
179 html_txt(cgit_repo->desc); 197 html_txt(cgit_repo->desc);
180 html("</h2>"); 198 html("</h2>");
181 if (cgit_repo->readme) 199 if (cgit_repo->readme)
182 html_include(cgit_repo->readme); 200 html_include(cgit_repo->readme);
183 html("</div>"); 201 html("</div>");
184 if (cgit_summary_log > 0) 202 if (cgit_summary_log > 0)
185 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); 203 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
186 html("<table class='list nowrap'>"); 204 html("<table class='list nowrap'>");
187 if (cgit_summary_log > 0) 205 if (cgit_summary_log > 0)
188 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 206 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
189 cgit_print_branches(); 207 cgit_print_branches();
190 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 208 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
191 cgit_print_tags(); 209 cgit_print_tags();
192 html("</table>"); 210 html("</table>");
193} 211}