author | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:55:10 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:55:10 (UTC) |
commit | dd0f27eb36e737261b57d6ebcbd9fe20e559470d (patch) (unidiff) | |
tree | 4729ecc84e0b24b044131546ff39bdd55a6cd9a6 /ui-summary.c | |
parent | 47bae9f58d5ecae437767b8e7835b23ad1804d0b (diff) | |
parent | ac1f493b6bbc589327e9ba3303f112fcd323c6b6 (diff) | |
download | cgit-dd0f27eb36e737261b57d6ebcbd9fe20e559470d.zip cgit-dd0f27eb36e737261b57d6ebcbd9fe20e559470d.tar.gz cgit-dd0f27eb36e737261b57d6ebcbd9fe20e559470d.tar.bz2 |
Merge branch 'filter-refs'
* filter-refs:
Add links to the new refs page from summary page
Add support for refs view
Make cgit_print_branches()/cgit_print_tags() external
Add descriptions of summary-branches and summary-tags to cgitrc
Add support for config param summary-branches
Move logic for age comparision from cmp_tag_age into cmp_age()
Add support for config param summary-tags
Sort tags by age
Use reflist to print tag info
Use reflist to print branch info
Add functions and types for ref lists
-rw-r--r-- | ui-summary.c | 139 |
1 files changed, 104 insertions, 35 deletions
diff --git a/ui-summary.c b/ui-summary.c index de8a180..016fea2 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -10,41 +10,73 @@ | |||
10 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cmp_age(int age1, int age2) |
14 | int flags, void *cb_data) | 14 | { |
15 | if (age1 != 0 && age2 != 0) | ||
16 | return age2 - age1; | ||
17 | |||
18 | if (age1 == 0 && age2 == 0) | ||
19 | return 0; | ||
20 | |||
21 | if (age1 == 0) | ||
22 | return +1; | ||
23 | |||
24 | return -1; | ||
25 | } | ||
26 | |||
27 | static int cmp_ref_name(const void *a, const void *b) | ||
28 | { | ||
29 | struct refinfo *r1 = *(struct refinfo **)a; | ||
30 | struct refinfo *r2 = *(struct refinfo **)b; | ||
31 | |||
32 | return strcmp(r1->refname, r2->refname); | ||
33 | } | ||
34 | |||
35 | static int cmp_branch_age(const void *a, const void *b) | ||
36 | { | ||
37 | struct refinfo *r1 = *(struct refinfo **)a; | ||
38 | struct refinfo *r2 = *(struct refinfo **)b; | ||
39 | |||
40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | ||
41 | } | ||
42 | |||
43 | static int cmp_tag_age(const void *a, const void *b) | ||
44 | { | ||
45 | struct refinfo *r1 = *(struct refinfo **)a; | ||
46 | struct refinfo *r2 = *(struct refinfo **)b; | ||
47 | |||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | ||
49 | } | ||
50 | |||
51 | static void cgit_print_branch(struct refinfo *ref) | ||
15 | { | 52 | { |
16 | struct commit *commit; | 53 | struct commit *commit; |
17 | struct commitinfo *info; | 54 | struct commitinfo *info; |
18 | char buf[256]; | 55 | char *name = (char *)ref->refname; |
19 | char *ref; | ||
20 | 56 | ||
21 | ref = xstrdup(refname); | 57 | commit = lookup_commit(ref->object->sha1); |
22 | strncpy(buf, refname, sizeof(buf)); | ||
23 | commit = lookup_commit(sha1); | ||
24 | // object is not really parsed at this point, because of some fallout | 58 | // object is not really parsed at this point, because of some fallout |
25 | // from previous calls to git functions in cgit_print_log() | 59 | // from previous calls to git functions in cgit_print_log() |
26 | commit->object.parsed = 0; | 60 | commit->object.parsed = 0; |
27 | if (commit && !parse_commit(commit)){ | 61 | if (commit && !parse_commit(commit)){ |
28 | info = cgit_parse_commit(commit); | 62 | info = cgit_parse_commit(commit); |
29 | html("<tr><td>"); | 63 | html("<tr><td>"); |
30 | cgit_log_link(ref, NULL, NULL, ref, NULL, NULL, 0); | 64 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
31 | html("</td><td>"); | 65 | html("</td><td>"); |
32 | cgit_print_age(commit->date, -1, NULL); | 66 | cgit_print_age(commit->date, -1, NULL); |
33 | html("</td><td>"); | 67 | html("</td><td>"); |
34 | html_txt(info->author); | 68 | html_txt(info->author); |
35 | html("</td><td>"); | 69 | html("</td><td>"); |
36 | cgit_commit_link(info->subject, NULL, NULL, ref, NULL); | 70 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); |
37 | html("</td></tr>\n"); | 71 | html("</td></tr>\n"); |
38 | cgit_free_commitinfo(info); | 72 | cgit_free_commitinfo(info); |
39 | } else { | 73 | } else { |
40 | html("<tr><td>"); | 74 | html("<tr><td>"); |
41 | html_txt(buf); | 75 | html_txt(name); |
42 | html("</td><td colspan='3'>"); | 76 | html("</td><td colspan='3'>"); |
43 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); |
44 | html("</td></tr>\n"); | 78 | html("</td></tr>\n"); |
45 | } | 79 | } |
46 | free(ref); | ||
47 | return 0; | ||
48 | } | 80 | } |
49 | 81 | ||
50 | static void print_tag_header() | 82 | static void print_tag_header() |
@@ -56,29 +88,21 @@ static void print_tag_header() | |||
56 | header = 1; | 88 | header = 1; |
57 | } | 89 | } |
58 | 90 | ||
59 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 91 | static int print_tag(struct refinfo *ref) |
60 | int flags, void *cb_data) | ||
61 | { | 92 | { |
62 | struct tag *tag; | 93 | struct tag *tag; |
63 | struct taginfo *info; | 94 | struct taginfo *info; |
64 | struct object *obj; | 95 | char *url, *name = (char *)ref->refname; |
65 | char buf[256], *url; | ||
66 | 96 | ||
67 | strncpy(buf, refname, sizeof(buf)); | 97 | if (ref->object->type == OBJ_TAG) { |
68 | obj = parse_object(sha1); | 98 | tag = lookup_tag(ref->object->sha1); |
69 | if (!obj) | ||
70 | return 1; | ||
71 | if (obj->type == OBJ_TAG) { | ||
72 | tag = lookup_tag(sha1); | ||
73 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
74 | return 2; | 100 | return 2; |
75 | if (!header) | ||
76 | print_tag_header(); | ||
77 | html("<tr><td>"); | 101 | html("<tr><td>"); |
78 | url = cgit_pageurl(cgit_query_repo, "tag", | 102 | url = cgit_pageurl(cgit_query_repo, "tag", |
79 | fmt("id=%s", refname)); | 103 | fmt("id=%s", name)); |
80 | html_link_open(url, NULL, NULL); | 104 | html_link_open(url, NULL, NULL); |
81 | html_txt(buf); | 105 | html_txt(name); |
82 | html_link_close(); | 106 | html_link_close(); |
83 | html("</td><td>"); | 107 | html("</td><td>"); |
84 | if (info->tagger_date > 0) | 108 | if (info->tagger_date > 0) |
@@ -93,9 +117,9 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | |||
93 | if (!header) | 117 | if (!header) |
94 | print_tag_header(); | 118 | print_tag_header(); |
95 | html("<tr><td>"); | 119 | html("<tr><td>"); |
96 | html_txt(buf); | 120 | html_txt(name); |
97 | html("</td><td colspan='2'/><td>"); | 121 | html("</td><td colspan='2'/><td>"); |
98 | cgit_object_link(obj); | 122 | cgit_object_link(ref->object); |
99 | html("</td></tr>\n"); | 123 | html("</td></tr>\n"); |
100 | } | 124 | } |
101 | return 0; | 125 | return 0; |
@@ -142,19 +166,64 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | |||
142 | return 0; | 166 | return 0; |
143 | } | 167 | } |
144 | 168 | ||
145 | static void cgit_print_branches() | 169 | static void print_refs_link(char *path) |
146 | { | 170 | { |
171 | html("<tr class='nohover'><td colspan='4'>"); | ||
172 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | ||
173 | html("</td></tr>"); | ||
174 | } | ||
175 | |||
176 | void cgit_print_branches(int maxcount) | ||
177 | { | ||
178 | struct reflist list; | ||
179 | int i; | ||
180 | |||
147 | html("<tr class='nohover'><th class='left'>Branch</th>" | 181 | html("<tr class='nohover'><th class='left'>Branch</th>" |
148 | "<th class='left'>Idle</th>" | 182 | "<th class='left'>Idle</th>" |
149 | "<th class='left'>Author</th>" | 183 | "<th class='left'>Author</th>" |
150 | "<th class='left'>Head commit</th></tr>\n"); | 184 | "<th class='left'>Head commit</th></tr>\n"); |
151 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 185 | |
186 | list.refs = NULL; | ||
187 | list.alloc = list.count = 0; | ||
188 | for_each_branch_ref(cgit_refs_cb, &list); | ||
189 | |||
190 | if (maxcount == 0 || maxcount > list.count) | ||
191 | maxcount = list.count; | ||
192 | |||
193 | if (maxcount < list.count) { | ||
194 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | ||
195 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | ||
196 | } | ||
197 | |||
198 | for(i=0; i<maxcount; i++) | ||
199 | cgit_print_branch(list.refs[i]); | ||
200 | |||
201 | if (maxcount < list.count) | ||
202 | print_refs_link("heads"); | ||
152 | } | 203 | } |
153 | 204 | ||
154 | static void cgit_print_tags() | 205 | void cgit_print_tags(int maxcount) |
155 | { | 206 | { |
207 | struct reflist list; | ||
208 | int i; | ||
209 | |||
156 | header = 0; | 210 | header = 0; |
157 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 211 | list.refs = NULL; |
212 | list.alloc = list.count = 0; | ||
213 | for_each_tag_ref(cgit_refs_cb, &list); | ||
214 | if (list.count == 0) | ||
215 | return; | ||
216 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | ||
217 | if (!maxcount) | ||
218 | maxcount = list.count; | ||
219 | else if (maxcount > list.count) | ||
220 | maxcount = list.count; | ||
221 | print_tag_header(); | ||
222 | for(i=0; i<maxcount; i++) | ||
223 | print_tag(list.refs[i]); | ||
224 | |||
225 | if (maxcount < list.count) | ||
226 | print_refs_link("tags"); | ||
158 | } | 227 | } |
159 | 228 | ||
160 | static void cgit_print_archives() | 229 | static void cgit_print_archives() |
@@ -182,8 +251,8 @@ void cgit_print_summary() | |||
182 | html("<table class='list nowrap'>"); | 251 | html("<table class='list nowrap'>"); |
183 | if (cgit_summary_log > 0) | 252 | if (cgit_summary_log > 0) |
184 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 253 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
185 | cgit_print_branches(); | 254 | cgit_print_branches(cgit_summary_branches); |
186 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 255 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
187 | cgit_print_tags(); | 256 | cgit_print_tags(cgit_summary_tags); |
188 | html("</table>"); | 257 | html("</table>"); |
189 | } | 258 | } |