author | Lars Hjemli <hjemli@gmail.com> | 2007-10-25 08:40:16 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:53:27 (UTC) |
commit | fe211c7eef6c7d3e39486d6a7484d3b4debff88f (patch) (unidiff) | |
tree | 1b77d4b541cd5848ae1ad8d48e17e7d0f1a8b017 /ui-summary.c | |
parent | ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc (diff) | |
download | cgit-fe211c7eef6c7d3e39486d6a7484d3b4debff88f.zip cgit-fe211c7eef6c7d3e39486d6a7484d3b4debff88f.tar.gz cgit-fe211c7eef6c7d3e39486d6a7484d3b4debff88f.tar.bz2 |
Add support for config param summary-tags
This parameter can be used to specify max number of tags to show on
the summary page. If not specified, all tags are printed.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-summary.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ui-summary.c b/ui-summary.c index 43582da..3d5eda8 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,211 +1,215 @@ | |||
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) | 13 | static int cmp_tag_age(void *a, void *b) |
14 | { | 14 | { |
15 | struct refinfo *r1 = *(struct refinfo **)a; | 15 | struct refinfo *r1 = *(struct refinfo **)a; |
16 | struct refinfo *r2 = *(struct refinfo **)b; | 16 | struct refinfo *r2 = *(struct refinfo **)b; |
17 | 17 | ||
18 | if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0) | 18 | if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0) |
19 | return r2->tag->tagger_date - r1->tag->tagger_date; | 19 | return r2->tag->tagger_date - r1->tag->tagger_date; |
20 | 20 | ||
21 | if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0) | 21 | if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0) |
22 | return 0; | 22 | return 0; |
23 | 23 | ||
24 | if (r1 == 0) | 24 | if (r1 == 0) |
25 | return +1; | 25 | return +1; |
26 | 26 | ||
27 | return -1; | 27 | return -1; |
28 | } | 28 | } |
29 | 29 | ||
30 | static void cgit_print_branch(struct refinfo *ref) | 30 | static void cgit_print_branch(struct refinfo *ref) |
31 | { | 31 | { |
32 | struct commit *commit; | 32 | struct commit *commit; |
33 | struct commitinfo *info; | 33 | struct commitinfo *info; |
34 | char *name = (char *)ref->refname; | 34 | char *name = (char *)ref->refname; |
35 | 35 | ||
36 | commit = lookup_commit(ref->object->sha1); | 36 | commit = lookup_commit(ref->object->sha1); |
37 | // 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 |
38 | // from previous calls to git functions in cgit_print_log() | 38 | // from previous calls to git functions in cgit_print_log() |
39 | commit->object.parsed = 0; | 39 | commit->object.parsed = 0; |
40 | if (commit && !parse_commit(commit)){ | 40 | if (commit && !parse_commit(commit)){ |
41 | info = cgit_parse_commit(commit); | 41 | info = cgit_parse_commit(commit); |
42 | html("<tr><td>"); | 42 | html("<tr><td>"); |
43 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 43 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
44 | html("</td><td>"); | 44 | html("</td><td>"); |
45 | cgit_print_age(commit->date, -1, NULL); | 45 | cgit_print_age(commit->date, -1, NULL); |
46 | html("</td><td>"); | 46 | html("</td><td>"); |
47 | html_txt(info->author); | 47 | html_txt(info->author); |
48 | html("</td><td>"); | 48 | html("</td><td>"); |
49 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 49 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); |
50 | html("</td></tr>\n"); | 50 | html("</td></tr>\n"); |
51 | cgit_free_commitinfo(info); | 51 | cgit_free_commitinfo(info); |
52 | } else { | 52 | } else { |
53 | html("<tr><td>"); | 53 | html("<tr><td>"); |
54 | html_txt(name); | 54 | html_txt(name); |
55 | html("</td><td colspan='3'>"); | 55 | html("</td><td colspan='3'>"); |
56 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); | 56 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); |
57 | html("</td></tr>\n"); | 57 | html("</td></tr>\n"); |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | static void print_tag_header() | 61 | static void print_tag_header() |
62 | { | 62 | { |
63 | html("<tr class='nohover'><th class='left'>Tag</th>" | 63 | html("<tr class='nohover'><th class='left'>Tag</th>" |
64 | "<th class='left'>Age</th>" | 64 | "<th class='left'>Age</th>" |
65 | "<th class='left'>Author</th>" | 65 | "<th class='left'>Author</th>" |
66 | "<th class='left'>Reference</th></tr>\n"); | 66 | "<th class='left'>Reference</th></tr>\n"); |
67 | header = 1; | 67 | header = 1; |
68 | } | 68 | } |
69 | 69 | ||
70 | static int print_tag(struct refinfo *ref) | 70 | static int print_tag(struct refinfo *ref) |
71 | { | 71 | { |
72 | struct tag *tag; | 72 | struct tag *tag; |
73 | struct taginfo *info; | 73 | struct taginfo *info; |
74 | char *url, *name = (char *)ref->refname; | 74 | char *url, *name = (char *)ref->refname; |
75 | 75 | ||
76 | if (ref->object->type == OBJ_TAG) { | 76 | if (ref->object->type == OBJ_TAG) { |
77 | tag = lookup_tag(ref->object->sha1); | 77 | tag = lookup_tag(ref->object->sha1); |
78 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 78 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
79 | return 2; | 79 | return 2; |
80 | html("<tr><td>"); | 80 | html("<tr><td>"); |
81 | url = cgit_pageurl(cgit_query_repo, "tag", | 81 | url = cgit_pageurl(cgit_query_repo, "tag", |
82 | fmt("id=%s", name)); | 82 | fmt("id=%s", name)); |
83 | html_link_open(url, NULL, NULL); | 83 | html_link_open(url, NULL, NULL); |
84 | html_txt(name); | 84 | html_txt(name); |
85 | html_link_close(); | 85 | html_link_close(); |
86 | html("</td><td>"); | 86 | html("</td><td>"); |
87 | if (info->tagger_date > 0) | 87 | if (info->tagger_date > 0) |
88 | cgit_print_age(info->tagger_date, -1, NULL); | 88 | cgit_print_age(info->tagger_date, -1, NULL); |
89 | html("</td><td>"); | 89 | html("</td><td>"); |
90 | if (info->tagger) | 90 | if (info->tagger) |
91 | html(info->tagger); | 91 | html(info->tagger); |
92 | html("</td><td>"); | 92 | html("</td><td>"); |
93 | cgit_object_link(tag->tagged); | 93 | cgit_object_link(tag->tagged); |
94 | html("</td></tr>\n"); | 94 | html("</td></tr>\n"); |
95 | } else { | 95 | } else { |
96 | if (!header) | 96 | if (!header) |
97 | print_tag_header(); | 97 | print_tag_header(); |
98 | html("<tr><td>"); | 98 | html("<tr><td>"); |
99 | html_txt(name); | 99 | html_txt(name); |
100 | html("</td><td colspan='2'/><td>"); | 100 | html("</td><td colspan='2'/><td>"); |
101 | cgit_object_link(ref->object); | 101 | cgit_object_link(ref->object); |
102 | html("</td></tr>\n"); | 102 | html("</td></tr>\n"); |
103 | } | 103 | } |
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | 106 | ||
107 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 107 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
108 | int flags, void *cb_data) | 108 | int flags, void *cb_data) |
109 | { | 109 | { |
110 | struct tag *tag; | 110 | struct tag *tag; |
111 | struct taginfo *info; | 111 | struct taginfo *info; |
112 | struct object *obj; | 112 | struct object *obj; |
113 | char buf[256], *url; | 113 | char buf[256], *url; |
114 | unsigned char fileid[20]; | 114 | unsigned char fileid[20]; |
115 | 115 | ||
116 | if (prefixcmp(refname, "refs/archives")) | 116 | if (prefixcmp(refname, "refs/archives")) |
117 | return 0; | 117 | return 0; |
118 | strncpy(buf, refname+14, sizeof(buf)); | 118 | strncpy(buf, refname+14, sizeof(buf)); |
119 | obj = parse_object(sha1); | 119 | obj = parse_object(sha1); |
120 | if (!obj) | 120 | if (!obj) |
121 | return 1; | 121 | return 1; |
122 | if (obj->type == OBJ_TAG) { | 122 | if (obj->type == OBJ_TAG) { |
123 | tag = lookup_tag(sha1); | 123 | tag = lookup_tag(sha1); |
124 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 124 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
125 | return 0; | 125 | return 0; |
126 | hashcpy(fileid, tag->tagged->sha1); | 126 | hashcpy(fileid, tag->tagged->sha1); |
127 | } else if (obj->type != OBJ_BLOB) { | 127 | } else if (obj->type != OBJ_BLOB) { |
128 | return 0; | 128 | return 0; |
129 | } else { | 129 | } else { |
130 | hashcpy(fileid, sha1); | 130 | hashcpy(fileid, sha1); |
131 | } | 131 | } |
132 | if (!header) { | 132 | if (!header) { |
133 | html("<table id='downloads'>"); | 133 | html("<table id='downloads'>"); |
134 | html("<tr><th>Downloads</th></tr>"); | 134 | html("<tr><th>Downloads</th></tr>"); |
135 | header = 1; | 135 | header = 1; |
136 | } | 136 | } |
137 | html("<tr><td>"); | 137 | html("<tr><td>"); |
138 | url = cgit_pageurl(cgit_query_repo, "blob", | 138 | url = cgit_pageurl(cgit_query_repo, "blob", |
139 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 139 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
140 | buf)); | 140 | buf)); |
141 | html_link_open(url, NULL, NULL); | 141 | html_link_open(url, NULL, NULL); |
142 | html_txt(buf); | 142 | html_txt(buf); |
143 | html_link_close(); | 143 | html_link_close(); |
144 | html("</td></tr>"); | 144 | html("</td></tr>"); |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | 147 | ||
148 | static void cgit_print_branches() | 148 | static void cgit_print_branches() |
149 | { | 149 | { |
150 | struct reflist list; | 150 | struct reflist list; |
151 | int i; | 151 | int i; |
152 | 152 | ||
153 | html("<tr class='nohover'><th class='left'>Branch</th>" | 153 | html("<tr class='nohover'><th class='left'>Branch</th>" |
154 | "<th class='left'>Idle</th>" | 154 | "<th class='left'>Idle</th>" |
155 | "<th class='left'>Author</th>" | 155 | "<th class='left'>Author</th>" |
156 | "<th class='left'>Head commit</th></tr>\n"); | 156 | "<th class='left'>Head commit</th></tr>\n"); |
157 | 157 | ||
158 | list.refs = NULL; | 158 | list.refs = NULL; |
159 | list.alloc = list.count = 0; | 159 | list.alloc = list.count = 0; |
160 | for_each_branch_ref(cgit_refs_cb, &list); | 160 | for_each_branch_ref(cgit_refs_cb, &list); |
161 | for(i=0; i<list.count; i++) | 161 | for(i=0; i<list.count; i++) |
162 | cgit_print_branch(list.refs[i]); | 162 | cgit_print_branch(list.refs[i]); |
163 | } | 163 | } |
164 | 164 | ||
165 | static void cgit_print_tags() | 165 | static void cgit_print_tags(int maxcount) |
166 | { | 166 | { |
167 | struct reflist list; | 167 | struct reflist list; |
168 | int i; | 168 | int i; |
169 | 169 | ||
170 | header = 0; | 170 | header = 0; |
171 | list.refs = NULL; | 171 | list.refs = NULL; |
172 | list.alloc = list.count = 0; | 172 | list.alloc = list.count = 0; |
173 | for_each_tag_ref(cgit_refs_cb, &list); | 173 | for_each_tag_ref(cgit_refs_cb, &list); |
174 | if (list.count == 0) | 174 | if (list.count == 0) |
175 | return; | 175 | return; |
176 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 176 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
177 | if (!maxcount) | ||
178 | maxcount = list.count; | ||
179 | else if (maxcount > list.count) | ||
180 | maxcount = list.count; | ||
177 | print_tag_header(); | 181 | print_tag_header(); |
178 | for(i=0; i<list.count; i++) | 182 | for(i=0; i<maxcount; i++) |
179 | print_tag(list.refs[i]); | 183 | print_tag(list.refs[i]); |
180 | } | 184 | } |
181 | 185 | ||
182 | static void cgit_print_archives() | 186 | static void cgit_print_archives() |
183 | { | 187 | { |
184 | header = 0; | 188 | header = 0; |
185 | for_each_ref(cgit_print_archive_cb, NULL); | 189 | for_each_ref(cgit_print_archive_cb, NULL); |
186 | if (header) | 190 | if (header) |
187 | html("</table>"); | 191 | html("</table>"); |
188 | } | 192 | } |
189 | 193 | ||
190 | void cgit_print_summary() | 194 | void cgit_print_summary() |
191 | { | 195 | { |
192 | html("<div id='summary'>"); | 196 | html("<div id='summary'>"); |
193 | cgit_print_archives(); | 197 | cgit_print_archives(); |
194 | html("<h2>"); | 198 | html("<h2>"); |
195 | html_txt(cgit_repo->name); | 199 | html_txt(cgit_repo->name); |
196 | html(" - "); | 200 | html(" - "); |
197 | html_txt(cgit_repo->desc); | 201 | html_txt(cgit_repo->desc); |
198 | html("</h2>"); | 202 | html("</h2>"); |
199 | if (cgit_repo->readme) | 203 | if (cgit_repo->readme) |
200 | html_include(cgit_repo->readme); | 204 | html_include(cgit_repo->readme); |
201 | html("</div>"); | 205 | html("</div>"); |
202 | if (cgit_summary_log > 0) | 206 | if (cgit_summary_log > 0) |
203 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | 207 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); |
204 | html("<table class='list nowrap'>"); | 208 | html("<table class='list nowrap'>"); |
205 | if (cgit_summary_log > 0) | 209 | if (cgit_summary_log > 0) |
206 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 210 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
207 | cgit_print_branches(); | 211 | cgit_print_branches(); |
208 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 212 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
209 | cgit_print_tags(); | 213 | cgit_print_tags(cgit_summary_tags); |
210 | html("</table>"); | 214 | html("</table>"); |
211 | } | 215 | } |