summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-10-25 08:13:25 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-27 07:34:15 (UTC)
commit0c1ebce2042e69569d99551d7749b97b4e579609 (patch) (unidiff)
treea0bcb407541d4c11017d78380866600096d39c22
parente397ff7024293223f48f235fcf072fc526cae7af (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c30
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,71 +1,65 @@
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 cgit_print_branch_cb(const char *refname, const unsigned char *sha1, 13static 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
50static void print_tag_header() 44static 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
59static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, 53static 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) {
@@ -123,53 +117,61 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
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&amp;path=%s", sha1_to_hex(fileid), 130 fmt("id=%s&amp;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
145static void cgit_print_branches() 139static 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
154static void cgit_print_tags() 156static 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
160static void cgit_print_archives() 162static 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
168void cgit_print_summary() 170void 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);