author | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 11:34:17 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 11:34:17 (UTC) |
commit | b4d4a25aa481aa3ac8ad69df4dfa53eaa5de6173 (patch) (unidiff) | |
tree | eac36573ba5ed7965d2b83f931a493aaef96307c | |
parent | dd0f27eb36e737261b57d6ebcbd9fe20e559470d (diff) | |
download | cgit-b4d4a25aa481aa3ac8ad69df4dfa53eaa5de6173.zip cgit-b4d4a25aa481aa3ac8ad69df4dfa53eaa5de6173.tar.gz cgit-b4d4a25aa481aa3ac8ad69df4dfa53eaa5de6173.tar.bz2 |
Cleanup code introduced by the filter-refs topic
The functions used to print branches and tags were only half-done and
somewhat confused. Fix it.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-summary.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/ui-summary.c b/ui-summary.c index 016fea2..178e959 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -27,98 +27,87 @@ static int cmp_age(int age1, int age2) | |||
27 | static int cmp_ref_name(const void *a, const void *b) | 27 | static int cmp_ref_name(const void *a, const void *b) |
28 | { | 28 | { |
29 | struct refinfo *r1 = *(struct refinfo **)a; | 29 | struct refinfo *r1 = *(struct refinfo **)a; |
30 | struct refinfo *r2 = *(struct refinfo **)b; | 30 | struct refinfo *r2 = *(struct refinfo **)b; |
31 | 31 | ||
32 | return strcmp(r1->refname, r2->refname); | 32 | return strcmp(r1->refname, r2->refname); |
33 | } | 33 | } |
34 | 34 | ||
35 | static int cmp_branch_age(const void *a, const void *b) | 35 | static int cmp_branch_age(const void *a, const void *b) |
36 | { | 36 | { |
37 | struct refinfo *r1 = *(struct refinfo **)a; | 37 | struct refinfo *r1 = *(struct refinfo **)a; |
38 | struct refinfo *r2 = *(struct refinfo **)b; | 38 | struct refinfo *r2 = *(struct refinfo **)b; |
39 | 39 | ||
40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
41 | } | 41 | } |
42 | 42 | ||
43 | static int cmp_tag_age(const void *a, const void *b) | 43 | static int cmp_tag_age(const void *a, const void *b) |
44 | { | 44 | { |
45 | struct refinfo *r1 = *(struct refinfo **)a; | 45 | struct refinfo *r1 = *(struct refinfo **)a; |
46 | struct refinfo *r2 = *(struct refinfo **)b; | 46 | struct refinfo *r2 = *(struct refinfo **)b; |
47 | 47 | ||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); |
49 | } | 49 | } |
50 | 50 | ||
51 | static void cgit_print_branch(struct refinfo *ref) | 51 | static int print_branch(struct refinfo *ref) |
52 | { | 52 | { |
53 | struct commit *commit; | 53 | struct commitinfo *info = ref->commit; |
54 | struct commitinfo *info; | ||
55 | char *name = (char *)ref->refname; | 54 | char *name = (char *)ref->refname; |
56 | 55 | ||
57 | commit = lookup_commit(ref->object->sha1); | 56 | if (!info) |
58 | // object is not really parsed at this point, because of some fallout | 57 | return 1; |
59 | // from previous calls to git functions in cgit_print_log() | 58 | html("<tr><td>"); |
60 | commit->object.parsed = 0; | 59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
61 | if (commit && !parse_commit(commit)){ | 60 | html("</td><td>"); |
62 | info = cgit_parse_commit(commit); | 61 | cgit_print_age(info->commit->date, -1, NULL); |
63 | html("<tr><td>"); | 62 | html("</td><td>"); |
64 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 63 | html_txt(info->author); |
65 | html("</td><td>"); | 64 | html("</td><td>"); |
66 | cgit_print_age(commit->date, -1, NULL); | 65 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); |
67 | html("</td><td>"); | 66 | html("</td></tr>\n"); |
68 | html_txt(info->author); | 67 | return 0; |
69 | html("</td><td>"); | ||
70 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | ||
71 | html("</td></tr>\n"); | ||
72 | cgit_free_commitinfo(info); | ||
73 | } else { | ||
74 | html("<tr><td>"); | ||
75 | html_txt(name); | ||
76 | html("</td><td colspan='3'>"); | ||
77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); | ||
78 | html("</td></tr>\n"); | ||
79 | } | ||
80 | } | 68 | } |
81 | 69 | ||
82 | static void print_tag_header() | 70 | static void print_tag_header() |
83 | { | 71 | { |
84 | html("<tr class='nohover'><th class='left'>Tag</th>" | 72 | html("<tr class='nohover'><th class='left'>Tag</th>" |
85 | "<th class='left'>Age</th>" | 73 | "<th class='left'>Age</th>" |
86 | "<th class='left'>Author</th>" | 74 | "<th class='left'>Author</th>" |
87 | "<th class='left'>Reference</th></tr>\n"); | 75 | "<th class='left'>Reference</th></tr>\n"); |
88 | header = 1; | 76 | header = 1; |
89 | } | 77 | } |
90 | 78 | ||
91 | static int print_tag(struct refinfo *ref) | 79 | static int print_tag(struct refinfo *ref) |
92 | { | 80 | { |
93 | struct tag *tag; | 81 | struct tag *tag; |
94 | struct taginfo *info; | 82 | struct taginfo *info; |
95 | char *url, *name = (char *)ref->refname; | 83 | char *url, *name = (char *)ref->refname; |
96 | 84 | ||
97 | if (ref->object->type == OBJ_TAG) { | 85 | if (ref->object->type == OBJ_TAG) { |
98 | tag = lookup_tag(ref->object->sha1); | 86 | tag = (struct tag *)ref->object; |
99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 87 | info = ref->tag; |
100 | return 2; | 88 | if (!tag || !info) |
89 | return 1; | ||
101 | html("<tr><td>"); | 90 | html("<tr><td>"); |
102 | url = cgit_pageurl(cgit_query_repo, "tag", | 91 | url = cgit_pageurl(cgit_query_repo, "tag", |
103 | fmt("id=%s", name)); | 92 | fmt("id=%s", name)); |
104 | html_link_open(url, NULL, NULL); | 93 | html_link_open(url, NULL, NULL); |
105 | html_txt(name); | 94 | html_txt(name); |
106 | html_link_close(); | 95 | html_link_close(); |
107 | html("</td><td>"); | 96 | html("</td><td>"); |
108 | if (info->tagger_date > 0) | 97 | if (info->tagger_date > 0) |
109 | cgit_print_age(info->tagger_date, -1, NULL); | 98 | cgit_print_age(info->tagger_date, -1, NULL); |
110 | html("</td><td>"); | 99 | html("</td><td>"); |
111 | if (info->tagger) | 100 | if (info->tagger) |
112 | html(info->tagger); | 101 | html(info->tagger); |
113 | html("</td><td>"); | 102 | html("</td><td>"); |
114 | cgit_object_link(tag->tagged); | 103 | cgit_object_link(tag->tagged); |
115 | html("</td></tr>\n"); | 104 | html("</td></tr>\n"); |
116 | } else { | 105 | } else { |
117 | if (!header) | 106 | if (!header) |
118 | print_tag_header(); | 107 | print_tag_header(); |
119 | html("<tr><td>"); | 108 | html("<tr><td>"); |
120 | html_txt(name); | 109 | html_txt(name); |
121 | html("</td><td colspan='2'/><td>"); | 110 | html("</td><td colspan='2'/><td>"); |
122 | cgit_object_link(ref->object); | 111 | cgit_object_link(ref->object); |
123 | html("</td></tr>\n"); | 112 | html("</td></tr>\n"); |
124 | } | 113 | } |
@@ -175,49 +164,49 @@ static void print_refs_link(char *path) | |||
175 | 164 | ||
176 | void cgit_print_branches(int maxcount) | 165 | void cgit_print_branches(int maxcount) |
177 | { | 166 | { |
178 | struct reflist list; | 167 | struct reflist list; |
179 | int i; | 168 | int i; |
180 | 169 | ||
181 | html("<tr class='nohover'><th class='left'>Branch</th>" | 170 | html("<tr class='nohover'><th class='left'>Branch</th>" |
182 | "<th class='left'>Idle</th>" | 171 | "<th class='left'>Idle</th>" |
183 | "<th class='left'>Author</th>" | 172 | "<th class='left'>Author</th>" |
184 | "<th class='left'>Head commit</th></tr>\n"); | 173 | "<th class='left'>Head commit</th></tr>\n"); |
185 | 174 | ||
186 | list.refs = NULL; | 175 | list.refs = NULL; |
187 | list.alloc = list.count = 0; | 176 | list.alloc = list.count = 0; |
188 | for_each_branch_ref(cgit_refs_cb, &list); | 177 | for_each_branch_ref(cgit_refs_cb, &list); |
189 | 178 | ||
190 | if (maxcount == 0 || maxcount > list.count) | 179 | if (maxcount == 0 || maxcount > list.count) |
191 | maxcount = list.count; | 180 | maxcount = list.count; |
192 | 181 | ||
193 | if (maxcount < list.count) { | 182 | if (maxcount < list.count) { |
194 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 183 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
195 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 184 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
196 | } | 185 | } |
197 | 186 | ||
198 | for(i=0; i<maxcount; i++) | 187 | for(i=0; i<maxcount; i++) |
199 | cgit_print_branch(list.refs[i]); | 188 | print_branch(list.refs[i]); |
200 | 189 | ||
201 | if (maxcount < list.count) | 190 | if (maxcount < list.count) |
202 | print_refs_link("heads"); | 191 | print_refs_link("heads"); |
203 | } | 192 | } |
204 | 193 | ||
205 | void cgit_print_tags(int maxcount) | 194 | void cgit_print_tags(int maxcount) |
206 | { | 195 | { |
207 | struct reflist list; | 196 | struct reflist list; |
208 | int i; | 197 | int i; |
209 | 198 | ||
210 | header = 0; | 199 | header = 0; |
211 | list.refs = NULL; | 200 | list.refs = NULL; |
212 | list.alloc = list.count = 0; | 201 | list.alloc = list.count = 0; |
213 | for_each_tag_ref(cgit_refs_cb, &list); | 202 | for_each_tag_ref(cgit_refs_cb, &list); |
214 | if (list.count == 0) | 203 | if (list.count == 0) |
215 | return; | 204 | return; |
216 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 205 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
217 | if (!maxcount) | 206 | if (!maxcount) |
218 | maxcount = list.count; | 207 | maxcount = list.count; |
219 | else if (maxcount > list.count) | 208 | else if (maxcount > list.count) |
220 | maxcount = list.count; | 209 | maxcount = list.count; |
221 | print_tag_header(); | 210 | print_tag_header(); |
222 | for(i=0; i<maxcount; i++) | 211 | for(i=0; i<maxcount; i++) |
223 | print_tag(list.refs[i]); | 212 | print_tag(list.refs[i]); |