-rw-r--r-- | ui-summary.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/ui-summary.c b/ui-summary.c index 29b76e3..03dd078 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,214 +1,214 @@ | |||
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 int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
14 | int flags, void *cb_data) | 14 | int flags, void *cb_data) |
15 | { | 15 | { |
16 | struct commit *commit; | 16 | struct commit *commit; |
17 | struct commitinfo *info; | 17 | struct commitinfo *info; |
18 | char buf[256], *url; | 18 | char buf[256]; |
19 | char *ref; | ||
19 | 20 | ||
21 | ref = xstrdup(refname); | ||
20 | strncpy(buf, refname, sizeof(buf)); | 22 | strncpy(buf, refname, sizeof(buf)); |
21 | commit = lookup_commit(sha1); | 23 | commit = lookup_commit(sha1); |
22 | // object is not really parsed at this point, because of some fallout | 24 | // object is not really parsed at this point, because of some fallout |
23 | // from previous calls to git functions in cgit_print_log() | 25 | // from previous calls to git functions in cgit_print_log() |
24 | commit->object.parsed = 0; | 26 | commit->object.parsed = 0; |
25 | if (commit && !parse_commit(commit)){ | 27 | if (commit && !parse_commit(commit)){ |
26 | info = cgit_parse_commit(commit); | 28 | info = cgit_parse_commit(commit); |
27 | html("<tr><td>"); | 29 | html("<tr><td>"); |
28 | cgit_log_link(refname, NULL, NULL, refname, NULL, NULL); | 30 | cgit_log_link(ref, NULL, NULL, ref, NULL, NULL); |
29 | html("</td><td>"); | 31 | html("</td><td>"); |
30 | cgit_print_age(commit->date, -1, NULL); | 32 | cgit_print_age(commit->date, -1, NULL); |
31 | html("</td><td>"); | 33 | html("</td><td>"); |
32 | html_txt(info->author); | 34 | html_txt(info->author); |
33 | html("</td><td>"); | 35 | html("</td><td>"); |
34 | url = cgit_pageurl(cgit_query_repo, "commit", | 36 | cgit_commit_link(info->subject, NULL, NULL, ref, NULL); |
35 | fmt("h=%s", sha1_to_hex(sha1))); | ||
36 | html_link_open(url, NULL, NULL); | ||
37 | html_ntxt(cgit_max_msg_len, info->subject); | ||
38 | html_link_close(); | ||
39 | html("</td></tr>\n"); | 37 | html("</td></tr>\n"); |
40 | cgit_free_commitinfo(info); | 38 | cgit_free_commitinfo(info); |
41 | } else { | 39 | } else { |
42 | html("<tr><td>"); | 40 | html("<tr><td>"); |
43 | html_txt(buf); | 41 | html_txt(buf); |
44 | html("</td><td colspan='3'>"); | 42 | html("</td><td colspan='3'>"); |
45 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 43 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
46 | html("</td></tr>\n"); | 44 | html("</td></tr>\n"); |
47 | } | 45 | } |
46 | free(ref); | ||
48 | return 0; | 47 | return 0; |
49 | } | 48 | } |
50 | 49 | ||
51 | 50 | ||
52 | static void cgit_print_object_ref(struct object *obj) | 51 | static void cgit_print_object_ref(struct object *obj) |
53 | { | 52 | { |
54 | char *page, *arg, *url; | 53 | char *page, *arg, *url; |
55 | 54 | ||
56 | if (obj->type == OBJ_COMMIT) { | 55 | if (obj->type == OBJ_COMMIT) { |
57 | page = "commit"; | 56 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
58 | arg = "h"; | 57 | cgit_query_head, sha1_to_hex(obj->sha1)); |
58 | return; | ||
59 | } else if (obj->type == OBJ_TREE) { | 59 | } else if (obj->type == OBJ_TREE) { |
60 | page = "tree"; | 60 | page = "tree"; |
61 | arg = "id"; | 61 | arg = "id"; |
62 | } else { | 62 | } else { |
63 | page = "view"; | 63 | page = "view"; |
64 | arg = "id"; | 64 | arg = "id"; |
65 | } | 65 | } |
66 | 66 | ||
67 | url = cgit_pageurl(cgit_query_repo, page, | 67 | url = cgit_pageurl(cgit_query_repo, page, |
68 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 68 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
69 | html_link_open(url, NULL, NULL); | 69 | html_link_open(url, NULL, NULL); |
70 | htmlf("%s %s", typename(obj->type), | 70 | htmlf("%s %s", typename(obj->type), |
71 | sha1_to_hex(obj->sha1)); | 71 | sha1_to_hex(obj->sha1)); |
72 | html_link_close(); | 72 | html_link_close(); |
73 | } | 73 | } |
74 | 74 | ||
75 | static void print_tag_header() | 75 | static void print_tag_header() |
76 | { | 76 | { |
77 | html("<tr class='nohover'><th class='left'>Tag</th>" | 77 | html("<tr class='nohover'><th class='left'>Tag</th>" |
78 | "<th class='left'>Age</th>" | 78 | "<th class='left'>Age</th>" |
79 | "<th class='left'>Author</th>" | 79 | "<th class='left'>Author</th>" |
80 | "<th class='left'>Reference</th></tr>\n"); | 80 | "<th class='left'>Reference</th></tr>\n"); |
81 | header = 1; | 81 | header = 1; |
82 | } | 82 | } |
83 | 83 | ||
84 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 84 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
85 | int flags, void *cb_data) | 85 | int flags, void *cb_data) |
86 | { | 86 | { |
87 | struct tag *tag; | 87 | struct tag *tag; |
88 | struct taginfo *info; | 88 | struct taginfo *info; |
89 | struct object *obj; | 89 | struct object *obj; |
90 | char buf[256], *url; | 90 | char buf[256], *url; |
91 | 91 | ||
92 | strncpy(buf, refname, sizeof(buf)); | 92 | strncpy(buf, refname, sizeof(buf)); |
93 | obj = parse_object(sha1); | 93 | obj = parse_object(sha1); |
94 | if (!obj) | 94 | if (!obj) |
95 | return 1; | 95 | return 1; |
96 | if (obj->type == OBJ_TAG) { | 96 | if (obj->type == OBJ_TAG) { |
97 | tag = lookup_tag(sha1); | 97 | tag = lookup_tag(sha1); |
98 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 98 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
99 | return 2; | 99 | return 2; |
100 | if (!header) | 100 | if (!header) |
101 | print_tag_header(); | 101 | print_tag_header(); |
102 | html("<tr><td>"); | 102 | html("<tr><td>"); |
103 | url = cgit_pageurl(cgit_query_repo, "view", | 103 | url = cgit_pageurl(cgit_query_repo, "view", |
104 | fmt("id=%s", sha1_to_hex(sha1))); | 104 | fmt("id=%s", sha1_to_hex(sha1))); |
105 | html_link_open(url, NULL, NULL); | 105 | html_link_open(url, NULL, NULL); |
106 | html_txt(buf); | 106 | html_txt(buf); |
107 | html_link_close(); | 107 | html_link_close(); |
108 | html("</td><td>"); | 108 | html("</td><td>"); |
109 | if (info->tagger_date > 0) | 109 | if (info->tagger_date > 0) |
110 | cgit_print_age(info->tagger_date, -1, NULL); | 110 | cgit_print_age(info->tagger_date, -1, NULL); |
111 | html("</td><td>"); | 111 | html("</td><td>"); |
112 | if (info->tagger) | 112 | if (info->tagger) |
113 | html(info->tagger); | 113 | html(info->tagger); |
114 | html("</td><td>"); | 114 | html("</td><td>"); |
115 | cgit_print_object_ref(tag->tagged); | 115 | cgit_print_object_ref(tag->tagged); |
116 | html("</td></tr>\n"); | 116 | html("</td></tr>\n"); |
117 | } else { | 117 | } else { |
118 | if (!header) | 118 | if (!header) |
119 | print_tag_header(); | 119 | print_tag_header(); |
120 | html("<tr><td>"); | 120 | html("<tr><td>"); |
121 | html_txt(buf); | 121 | html_txt(buf); |
122 | html("</td><td colspan='2'/><td>"); | 122 | html("</td><td colspan='2'/><td>"); |
123 | cgit_print_object_ref(obj); | 123 | cgit_print_object_ref(obj); |
124 | html("</td></tr>\n"); | 124 | html("</td></tr>\n"); |
125 | } | 125 | } |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | 128 | ||
129 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 129 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
130 | int flags, void *cb_data) | 130 | int flags, void *cb_data) |
131 | { | 131 | { |
132 | struct tag *tag; | 132 | struct tag *tag; |
133 | struct taginfo *info; | 133 | struct taginfo *info; |
134 | struct object *obj; | 134 | struct object *obj; |
135 | char buf[256], *url; | 135 | char buf[256], *url; |
136 | unsigned char fileid[20]; | 136 | unsigned char fileid[20]; |
137 | 137 | ||
138 | if (prefixcmp(refname, "refs/archives")) | 138 | if (prefixcmp(refname, "refs/archives")) |
139 | return 0; | 139 | return 0; |
140 | strncpy(buf, refname+14, sizeof(buf)); | 140 | strncpy(buf, refname+14, sizeof(buf)); |
141 | obj = parse_object(sha1); | 141 | obj = parse_object(sha1); |
142 | if (!obj) | 142 | if (!obj) |
143 | return 1; | 143 | return 1; |
144 | if (obj->type == OBJ_TAG) { | 144 | if (obj->type == OBJ_TAG) { |
145 | tag = lookup_tag(sha1); | 145 | tag = lookup_tag(sha1); |
146 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 146 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
147 | return 0; | 147 | return 0; |
148 | hashcpy(fileid, tag->tagged->sha1); | 148 | hashcpy(fileid, tag->tagged->sha1); |
149 | } else if (obj->type != OBJ_BLOB) { | 149 | } else if (obj->type != OBJ_BLOB) { |
150 | return 0; | 150 | return 0; |
151 | } else { | 151 | } else { |
152 | hashcpy(fileid, sha1); | 152 | hashcpy(fileid, sha1); |
153 | } | 153 | } |
154 | if (!header) { | 154 | if (!header) { |
155 | html("<table id='downloads'>"); | 155 | html("<table id='downloads'>"); |
156 | html("<tr><th>Downloads</th></tr>"); | 156 | html("<tr><th>Downloads</th></tr>"); |
157 | header = 1; | 157 | header = 1; |
158 | } | 158 | } |
159 | html("<tr><td>"); | 159 | html("<tr><td>"); |
160 | url = cgit_pageurl(cgit_query_repo, "blob", | 160 | url = cgit_pageurl(cgit_query_repo, "blob", |
161 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 161 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
162 | buf)); | 162 | buf)); |
163 | html_link_open(url, NULL, NULL); | 163 | html_link_open(url, NULL, NULL); |
164 | html_txt(buf); | 164 | html_txt(buf); |
165 | html_link_close(); | 165 | html_link_close(); |
166 | html("</td></tr>"); | 166 | html("</td></tr>"); |
167 | return 0; | 167 | return 0; |
168 | } | 168 | } |
169 | 169 | ||
170 | static void cgit_print_branches() | 170 | static void cgit_print_branches() |
171 | { | 171 | { |
172 | html("<tr class='nohover'><th class='left'>Branch</th>" | 172 | html("<tr class='nohover'><th class='left'>Branch</th>" |
173 | "<th class='left'>Idle</th>" | 173 | "<th class='left'>Idle</th>" |
174 | "<th class='left'>Author</th>" | 174 | "<th class='left'>Author</th>" |
175 | "<th class='left'>Head commit</th></tr>\n"); | 175 | "<th class='left'>Head commit</th></tr>\n"); |
176 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 176 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
177 | } | 177 | } |
178 | 178 | ||
179 | static void cgit_print_tags() | 179 | static void cgit_print_tags() |
180 | { | 180 | { |
181 | header = 0; | 181 | header = 0; |
182 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 182 | for_each_tag_ref(cgit_print_tag_cb, NULL); |
183 | } | 183 | } |
184 | 184 | ||
185 | static void cgit_print_archives() | 185 | static void cgit_print_archives() |
186 | { | 186 | { |
187 | header = 0; | 187 | header = 0; |
188 | for_each_ref(cgit_print_archive_cb, NULL); | 188 | for_each_ref(cgit_print_archive_cb, NULL); |
189 | if (header) | 189 | if (header) |
190 | html("</table>"); | 190 | html("</table>"); |
191 | } | 191 | } |
192 | 192 | ||
193 | void cgit_print_summary() | 193 | void cgit_print_summary() |
194 | { | 194 | { |
195 | html("<div id='summary'>"); | 195 | html("<div id='summary'>"); |
196 | cgit_print_archives(); | 196 | cgit_print_archives(); |
197 | html("<h2>"); | 197 | html("<h2>"); |
198 | html_txt(cgit_repo->name); | 198 | html_txt(cgit_repo->name); |
199 | html(" - "); | 199 | html(" - "); |
200 | html_txt(cgit_repo->desc); | 200 | html_txt(cgit_repo->desc); |
201 | html("</h2>"); | 201 | html("</h2>"); |
202 | if (cgit_repo->readme) | 202 | if (cgit_repo->readme) |
203 | html_include(cgit_repo->readme); | 203 | html_include(cgit_repo->readme); |
204 | html("</div>"); | 204 | html("</div>"); |
205 | if (cgit_summary_log > 0) | 205 | if (cgit_summary_log > 0) |
206 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | 206 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); |
207 | html("<table class='list nowrap'>"); | 207 | html("<table class='list nowrap'>"); |
208 | if (cgit_summary_log > 0) | 208 | if (cgit_summary_log > 0) |
209 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 209 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
210 | cgit_print_branches(); | 210 | cgit_print_branches(); |
211 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 211 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
212 | cgit_print_tags(); | 212 | cgit_print_tags(); |
213 | html("</table>"); | 213 | html("</table>"); |
214 | } | 214 | } |