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