-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 6 | ||||
-rw-r--r-- | ui-summary.c | 13 |
3 files changed, 21 insertions, 0 deletions
@@ -143,132 +143,134 @@ extern int cgit_cache_repo_ttl; | |||
143 | extern int cgit_cache_dynamic_ttl; | 143 | extern int cgit_cache_dynamic_ttl; |
144 | extern int cgit_cache_static_ttl; | 144 | extern int cgit_cache_static_ttl; |
145 | extern int cgit_cache_max_create_time; | 145 | extern int cgit_cache_max_create_time; |
146 | extern int cgit_summary_log; | 146 | extern int cgit_summary_log; |
147 | extern int cgit_summary_tags; | 147 | extern int cgit_summary_tags; |
148 | extern int cgit_summary_branches; | 148 | extern int cgit_summary_branches; |
149 | 149 | ||
150 | extern int cgit_max_msg_len; | 150 | extern int cgit_max_msg_len; |
151 | extern int cgit_max_repodesc_len; | 151 | extern int cgit_max_repodesc_len; |
152 | extern int cgit_max_commit_count; | 152 | extern int cgit_max_commit_count; |
153 | 153 | ||
154 | extern int cgit_query_has_symref; | 154 | extern int cgit_query_has_symref; |
155 | extern int cgit_query_has_sha1; | 155 | extern int cgit_query_has_sha1; |
156 | 156 | ||
157 | extern char *cgit_querystring; | 157 | extern char *cgit_querystring; |
158 | extern char *cgit_query_repo; | 158 | extern char *cgit_query_repo; |
159 | extern char *cgit_query_page; | 159 | extern char *cgit_query_page; |
160 | extern char *cgit_query_search; | 160 | extern char *cgit_query_search; |
161 | extern char *cgit_query_head; | 161 | extern char *cgit_query_head; |
162 | extern char *cgit_query_sha1; | 162 | extern char *cgit_query_sha1; |
163 | extern char *cgit_query_sha2; | 163 | extern char *cgit_query_sha2; |
164 | extern char *cgit_query_path; | 164 | extern char *cgit_query_path; |
165 | extern char *cgit_query_name; | 165 | extern char *cgit_query_name; |
166 | extern int cgit_query_ofs; | 166 | extern int cgit_query_ofs; |
167 | 167 | ||
168 | extern int htmlfd; | 168 | extern int htmlfd; |
169 | 169 | ||
170 | extern int cgit_get_cmd_index(const char *cmd); | 170 | extern int cgit_get_cmd_index(const char *cmd); |
171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
172 | extern void cgit_global_config_cb(const char *name, const char *value); | 172 | extern void cgit_global_config_cb(const char *name, const char *value); |
173 | extern void cgit_repo_config_cb(const char *name, const char *value); | 173 | extern void cgit_repo_config_cb(const char *name, const char *value); |
174 | extern void cgit_querystring_cb(const char *name, const char *value); | 174 | extern void cgit_querystring_cb(const char *name, const char *value); |
175 | 175 | ||
176 | extern int chk_zero(int result, char *msg); | 176 | extern int chk_zero(int result, char *msg); |
177 | extern int chk_positive(int result, char *msg); | 177 | extern int chk_positive(int result, char *msg); |
178 | extern int chk_non_negative(int result, char *msg); | 178 | extern int chk_non_negative(int result, char *msg); |
179 | 179 | ||
180 | extern int hextoint(char c); | 180 | extern int hextoint(char c); |
181 | extern char *trim_end(const char *str, char c); | 181 | extern char *trim_end(const char *str, char c); |
182 | 182 | ||
183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
185 | int flags, void *cb_data); | 185 | int flags, void *cb_data); |
186 | 186 | ||
187 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 187 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
188 | 188 | ||
189 | extern int cgit_diff_files(const unsigned char *old_sha1, | 189 | extern int cgit_diff_files(const unsigned char *old_sha1, |
190 | const unsigned char *new_sha1, | 190 | const unsigned char *new_sha1, |
191 | linediff_fn fn); | 191 | linediff_fn fn); |
192 | 192 | ||
193 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 193 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
194 | const unsigned char *new_sha1, | 194 | const unsigned char *new_sha1, |
195 | filepair_fn fn, const char *prefix); | 195 | filepair_fn fn, const char *prefix); |
196 | 196 | ||
197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
198 | 198 | ||
199 | extern char *fmt(const char *format,...); | 199 | extern char *fmt(const char *format,...); |
200 | 200 | ||
201 | extern void html(const char *txt); | 201 | extern void html(const char *txt); |
202 | extern void htmlf(const char *format,...); | 202 | extern void htmlf(const char *format,...); |
203 | extern void html_txt(char *txt); | 203 | extern void html_txt(char *txt); |
204 | extern void html_ntxt(int len, char *txt); | 204 | extern void html_ntxt(int len, char *txt); |
205 | extern void html_attr(char *txt); | 205 | extern void html_attr(char *txt); |
206 | extern void html_hidden(char *name, char *value); | 206 | extern void html_hidden(char *name, char *value); |
207 | extern void html_link_open(char *url, char *title, char *class); | 207 | extern void html_link_open(char *url, char *title, char *class); |
208 | extern void html_link_close(void); | 208 | extern void html_link_close(void); |
209 | extern void html_filemode(unsigned short mode); | 209 | extern void html_filemode(unsigned short mode); |
210 | extern int html_include(const char *filename); | 210 | extern int html_include(const char *filename); |
211 | 211 | ||
212 | extern int cgit_read_config(const char *filename, configfn fn); | 212 | extern int cgit_read_config(const char *filename, configfn fn); |
213 | extern int cgit_parse_query(char *txt, configfn fn); | 213 | extern int cgit_parse_query(char *txt, configfn fn); |
214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
216 | extern void cgit_parse_url(const char *url); | 216 | extern void cgit_parse_url(const char *url); |
217 | 217 | ||
218 | extern char *cache_safe_filename(const char *unsafe); | 218 | extern char *cache_safe_filename(const char *unsafe); |
219 | extern int cache_lock(struct cacheitem *item); | 219 | extern int cache_lock(struct cacheitem *item); |
220 | extern int cache_unlock(struct cacheitem *item); | 220 | extern int cache_unlock(struct cacheitem *item); |
221 | extern int cache_cancel_lock(struct cacheitem *item); | 221 | extern int cache_cancel_lock(struct cacheitem *item); |
222 | extern int cache_exist(struct cacheitem *item); | 222 | extern int cache_exist(struct cacheitem *item); |
223 | extern int cache_expired(struct cacheitem *item); | 223 | extern int cache_expired(struct cacheitem *item); |
224 | 224 | ||
225 | extern char *cgit_repourl(const char *reponame); | 225 | extern char *cgit_repourl(const char *reponame); |
226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
227 | const char *filename, const char *query); | 227 | const char *filename, const char *query); |
228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
229 | const char *query); | 229 | const char *query); |
230 | 230 | ||
231 | extern const char *cgit_repobasename(const char *reponame); | 231 | extern const char *cgit_repobasename(const char *reponame); |
232 | 232 | ||
233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
234 | char *rev, char *path); | 234 | char *rev, char *path); |
235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
236 | char *rev, char *path, int ofs); | 236 | char *rev, char *path, int ofs); |
237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
238 | char *rev); | 238 | char *rev); |
239 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
240 | char *rev, char *path); | ||
239 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 241 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
240 | char *head, char *rev, char *archivename); | 242 | char *head, char *rev, char *archivename); |
241 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 243 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
242 | char *new_rev, char *old_rev, char *path); | 244 | char *new_rev, char *old_rev, char *path); |
243 | 245 | ||
244 | extern void cgit_object_link(struct object *obj); | 246 | extern void cgit_object_link(struct object *obj); |
245 | 247 | ||
246 | extern void cgit_print_error(char *msg); | 248 | extern void cgit_print_error(char *msg); |
247 | extern void cgit_print_date(time_t secs, char *format); | 249 | extern void cgit_print_date(time_t secs, char *format); |
248 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 250 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
249 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 251 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
250 | extern void cgit_print_docend(); | 252 | extern void cgit_print_docend(); |
251 | extern void cgit_print_pageheader(char *title, int show_search); | 253 | extern void cgit_print_pageheader(char *title, int show_search); |
252 | extern void cgit_print_snapshot_start(const char *mimetype, | 254 | extern void cgit_print_snapshot_start(const char *mimetype, |
253 | const char *filename, | 255 | const char *filename, |
254 | struct cacheitem *item); | 256 | struct cacheitem *item); |
255 | extern void cgit_print_branches(int maxcount); | 257 | extern void cgit_print_branches(int maxcount); |
256 | extern void cgit_print_tags(int maxcount); | 258 | extern void cgit_print_tags(int maxcount); |
257 | 259 | ||
258 | extern void cgit_print_repolist(struct cacheitem *item); | 260 | extern void cgit_print_repolist(struct cacheitem *item); |
259 | extern void cgit_print_summary(); | 261 | extern void cgit_print_summary(); |
260 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 262 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
261 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 263 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
262 | extern void cgit_print_tree(const char *rev, char *path); | 264 | extern void cgit_print_tree(const char *rev, char *path); |
263 | extern void cgit_print_commit(char *hex); | 265 | extern void cgit_print_commit(char *hex); |
264 | extern void cgit_print_refs(); | 266 | extern void cgit_print_refs(); |
265 | extern void cgit_print_tag(char *revname); | 267 | extern void cgit_print_tag(char *revname); |
266 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 268 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
267 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 269 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
268 | const char *hex, const char *prefix, | 270 | const char *hex, const char *prefix, |
269 | const char *filename, int snapshot); | 271 | const char *filename, int snapshot); |
270 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 272 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
271 | const char *hex, int snapshots); | 273 | const char *hex, int snapshots); |
272 | extern int cgit_parse_snapshots_mask(const char *str); | 274 | extern int cgit_parse_snapshots_mask(const char *str); |
273 | 275 | ||
274 | #endif /* CGIT_H */ | 276 | #endif /* CGIT_H */ |
diff --git a/ui-shared.c b/ui-shared.c index 5c5bcf3..e4bb98f 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -134,192 +134,198 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
134 | html_attr(class); | 134 | html_attr(class); |
135 | html("'"); | 135 | html("'"); |
136 | } | 136 | } |
137 | html(" href='"); | 137 | html(" href='"); |
138 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
139 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
141 | html("/"); | 141 | html("/"); |
142 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | if (page) { | 145 | if (page) { |
146 | html(page); | 146 | html(page); |
147 | html("/"); | 147 | html("/"); |
148 | if (path) | 148 | if (path) |
149 | html_attr(path); | 149 | html_attr(path); |
150 | } | 150 | } |
151 | } else { | 151 | } else { |
152 | html(cgit_script_name); | 152 | html(cgit_script_name); |
153 | html("?url="); | 153 | html("?url="); |
154 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
156 | html("/"); | 156 | html("/"); |
157 | if (page) { | 157 | if (page) { |
158 | html(page); | 158 | html(page); |
159 | html("/"); | 159 | html("/"); |
160 | if (path) | 160 | if (path) |
161 | html_attr(path); | 161 | html_attr(path); |
162 | } | 162 | } |
163 | delim = "&"; | 163 | delim = "&"; |
164 | } | 164 | } |
165 | if (head && strcmp(head, cgit_repo->defbranch)) { | 165 | if (head && strcmp(head, cgit_repo->defbranch)) { |
166 | html(delim); | 166 | html(delim); |
167 | html("h="); | 167 | html("h="); |
168 | html_attr(head); | 168 | html_attr(head); |
169 | delim = "&"; | 169 | delim = "&"; |
170 | } | 170 | } |
171 | return fmt("%s", delim); | 171 | return fmt("%s", delim); |
172 | } | 172 | } |
173 | 173 | ||
174 | static void reporevlink(char *page, char *name, char *title, char *class, | 174 | static void reporevlink(char *page, char *name, char *title, char *class, |
175 | char *head, char *rev, char *path) | 175 | char *head, char *rev, char *path) |
176 | { | 176 | { |
177 | char *delim; | 177 | char *delim; |
178 | 178 | ||
179 | delim = repolink(title, class, page, head, path); | 179 | delim = repolink(title, class, page, head, path); |
180 | if (rev && strcmp(rev, cgit_query_head)) { | 180 | if (rev && strcmp(rev, cgit_query_head)) { |
181 | html(delim); | 181 | html(delim); |
182 | html("id="); | 182 | html("id="); |
183 | html_attr(rev); | 183 | html_attr(rev); |
184 | } | 184 | } |
185 | html("'>"); | 185 | html("'>"); |
186 | html_txt(name); | 186 | html_txt(name); |
187 | html("</a>"); | 187 | html("</a>"); |
188 | } | 188 | } |
189 | 189 | ||
190 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 190 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
191 | char *rev, char *path) | 191 | char *rev, char *path) |
192 | { | 192 | { |
193 | reporevlink("tree", name, title, class, head, rev, path); | 193 | reporevlink("tree", name, title, class, head, rev, path); |
194 | } | 194 | } |
195 | 195 | ||
196 | void cgit_log_link(char *name, char *title, char *class, char *head, | 196 | void cgit_log_link(char *name, char *title, char *class, char *head, |
197 | char *rev, char *path, int ofs) | 197 | char *rev, char *path, int ofs) |
198 | { | 198 | { |
199 | char *delim; | 199 | char *delim; |
200 | 200 | ||
201 | delim = repolink(title, class, "log", head, path); | 201 | delim = repolink(title, class, "log", head, path); |
202 | if (rev && strcmp(rev, cgit_query_head)) { | 202 | if (rev && strcmp(rev, cgit_query_head)) { |
203 | html(delim); | 203 | html(delim); |
204 | html("id="); | 204 | html("id="); |
205 | html_attr(rev); | 205 | html_attr(rev); |
206 | delim = "&"; | 206 | delim = "&"; |
207 | } | 207 | } |
208 | if (ofs > 0) { | 208 | if (ofs > 0) { |
209 | html(delim); | 209 | html(delim); |
210 | html("ofs="); | 210 | html("ofs="); |
211 | htmlf("%d", ofs); | 211 | htmlf("%d", ofs); |
212 | } | 212 | } |
213 | html("'>"); | 213 | html("'>"); |
214 | html_txt(name); | 214 | html_txt(name); |
215 | html("</a>"); | 215 | html("</a>"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 218 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
219 | char *rev) | 219 | char *rev) |
220 | { | 220 | { |
221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
222 | name[cgit_max_msg_len] = '\0'; | 222 | name[cgit_max_msg_len] = '\0'; |
223 | name[cgit_max_msg_len - 1] = '.'; | 223 | name[cgit_max_msg_len - 1] = '.'; |
224 | name[cgit_max_msg_len - 2] = '.'; | 224 | name[cgit_max_msg_len - 2] = '.'; |
225 | name[cgit_max_msg_len - 3] = '.'; | 225 | name[cgit_max_msg_len - 3] = '.'; |
226 | } | 226 | } |
227 | reporevlink("commit", name, title, class, head, rev, NULL); | 227 | reporevlink("commit", name, title, class, head, rev, NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
231 | char *rev, char *path) | ||
232 | { | ||
233 | reporevlink("refs", name, title, class, head, rev, path); | ||
234 | } | ||
235 | |||
230 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 236 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
231 | char *rev, char *archivename) | 237 | char *rev, char *archivename) |
232 | { | 238 | { |
233 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 239 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
234 | } | 240 | } |
235 | 241 | ||
236 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 242 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
237 | char *new_rev, char *old_rev, char *path) | 243 | char *new_rev, char *old_rev, char *path) |
238 | { | 244 | { |
239 | char *delim; | 245 | char *delim; |
240 | 246 | ||
241 | delim = repolink(title, class, "diff", head, path); | 247 | delim = repolink(title, class, "diff", head, path); |
242 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
243 | html(delim); | 249 | html(delim); |
244 | html("id="); | 250 | html("id="); |
245 | html_attr(new_rev); | 251 | html_attr(new_rev); |
246 | delim = "&"; | 252 | delim = "&"; |
247 | } | 253 | } |
248 | if (old_rev) { | 254 | if (old_rev) { |
249 | html(delim); | 255 | html(delim); |
250 | html("id2="); | 256 | html("id2="); |
251 | html_attr(old_rev); | 257 | html_attr(old_rev); |
252 | } | 258 | } |
253 | html("'>"); | 259 | html("'>"); |
254 | html_txt(name); | 260 | html_txt(name); |
255 | html("</a>"); | 261 | html("</a>"); |
256 | } | 262 | } |
257 | 263 | ||
258 | void cgit_object_link(struct object *obj) | 264 | void cgit_object_link(struct object *obj) |
259 | { | 265 | { |
260 | char *page, *arg, *url; | 266 | char *page, *arg, *url; |
261 | 267 | ||
262 | if (obj->type == OBJ_COMMIT) { | 268 | if (obj->type == OBJ_COMMIT) { |
263 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 269 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
264 | cgit_query_head, sha1_to_hex(obj->sha1)); | 270 | cgit_query_head, sha1_to_hex(obj->sha1)); |
265 | return; | 271 | return; |
266 | } else if (obj->type == OBJ_TREE) { | 272 | } else if (obj->type == OBJ_TREE) { |
267 | page = "tree"; | 273 | page = "tree"; |
268 | arg = "id"; | 274 | arg = "id"; |
269 | } else { | 275 | } else { |
270 | page = "blob"; | 276 | page = "blob"; |
271 | arg = "id"; | 277 | arg = "id"; |
272 | } | 278 | } |
273 | 279 | ||
274 | url = cgit_pageurl(cgit_query_repo, page, | 280 | url = cgit_pageurl(cgit_query_repo, page, |
275 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 281 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
276 | html_link_open(url, NULL, NULL); | 282 | html_link_open(url, NULL, NULL); |
277 | htmlf("%s %s", typename(obj->type), | 283 | htmlf("%s %s", typename(obj->type), |
278 | sha1_to_hex(obj->sha1)); | 284 | sha1_to_hex(obj->sha1)); |
279 | html_link_close(); | 285 | html_link_close(); |
280 | } | 286 | } |
281 | 287 | ||
282 | void cgit_print_date(time_t secs, char *format) | 288 | void cgit_print_date(time_t secs, char *format) |
283 | { | 289 | { |
284 | char buf[64]; | 290 | char buf[64]; |
285 | struct tm *time; | 291 | struct tm *time; |
286 | 292 | ||
287 | time = gmtime(&secs); | 293 | time = gmtime(&secs); |
288 | strftime(buf, sizeof(buf)-1, format, time); | 294 | strftime(buf, sizeof(buf)-1, format, time); |
289 | html_txt(buf); | 295 | html_txt(buf); |
290 | } | 296 | } |
291 | 297 | ||
292 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 298 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
293 | { | 299 | { |
294 | time_t now, secs; | 300 | time_t now, secs; |
295 | 301 | ||
296 | time(&now); | 302 | time(&now); |
297 | secs = now - t; | 303 | secs = now - t; |
298 | 304 | ||
299 | if (secs > max_relative && max_relative >= 0) { | 305 | if (secs > max_relative && max_relative >= 0) { |
300 | cgit_print_date(t, format); | 306 | cgit_print_date(t, format); |
301 | return; | 307 | return; |
302 | } | 308 | } |
303 | 309 | ||
304 | if (secs < TM_HOUR * 2) { | 310 | if (secs < TM_HOUR * 2) { |
305 | htmlf("<span class='age-mins'>%.0f min.</span>", | 311 | htmlf("<span class='age-mins'>%.0f min.</span>", |
306 | secs * 1.0 / TM_MIN); | 312 | secs * 1.0 / TM_MIN); |
307 | return; | 313 | return; |
308 | } | 314 | } |
309 | if (secs < TM_DAY * 2) { | 315 | if (secs < TM_DAY * 2) { |
310 | htmlf("<span class='age-hours'>%.0f hours</span>", | 316 | htmlf("<span class='age-hours'>%.0f hours</span>", |
311 | secs * 1.0 / TM_HOUR); | 317 | secs * 1.0 / TM_HOUR); |
312 | return; | 318 | return; |
313 | } | 319 | } |
314 | if (secs < TM_WEEK * 2) { | 320 | if (secs < TM_WEEK * 2) { |
315 | htmlf("<span class='age-days'>%.0f days</span>", | 321 | htmlf("<span class='age-days'>%.0f days</span>", |
316 | secs * 1.0 / TM_DAY); | 322 | secs * 1.0 / TM_DAY); |
317 | return; | 323 | return; |
318 | } | 324 | } |
319 | if (secs < TM_MONTH * 2) { | 325 | if (secs < TM_MONTH * 2) { |
320 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 326 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
321 | secs * 1.0 / TM_WEEK); | 327 | secs * 1.0 / TM_WEEK); |
322 | return; | 328 | return; |
323 | } | 329 | } |
324 | if (secs < TM_YEAR * 2) { | 330 | if (secs < TM_YEAR * 2) { |
325 | htmlf("<span class='age-months'>%.0f months</span>", | 331 | htmlf("<span class='age-months'>%.0f months</span>", |
diff --git a/ui-summary.c b/ui-summary.c index 97f1b57..016fea2 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -73,173 +73,186 @@ static void cgit_print_branch(struct refinfo *ref) | |||
73 | } else { | 73 | } else { |
74 | html("<tr><td>"); | 74 | html("<tr><td>"); |
75 | html_txt(name); | 75 | html_txt(name); |
76 | html("</td><td colspan='3'>"); | 76 | html("</td><td colspan='3'>"); |
77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); | 77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); |
78 | html("</td></tr>\n"); | 78 | html("</td></tr>\n"); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | static void print_tag_header() | 82 | static void print_tag_header() |
83 | { | 83 | { |
84 | html("<tr class='nohover'><th class='left'>Tag</th>" | 84 | html("<tr class='nohover'><th class='left'>Tag</th>" |
85 | "<th class='left'>Age</th>" | 85 | "<th class='left'>Age</th>" |
86 | "<th class='left'>Author</th>" | 86 | "<th class='left'>Author</th>" |
87 | "<th class='left'>Reference</th></tr>\n"); | 87 | "<th class='left'>Reference</th></tr>\n"); |
88 | header = 1; | 88 | header = 1; |
89 | } | 89 | } |
90 | 90 | ||
91 | static int print_tag(struct refinfo *ref) | 91 | static int print_tag(struct refinfo *ref) |
92 | { | 92 | { |
93 | struct tag *tag; | 93 | struct tag *tag; |
94 | struct taginfo *info; | 94 | struct taginfo *info; |
95 | char *url, *name = (char *)ref->refname; | 95 | char *url, *name = (char *)ref->refname; |
96 | 96 | ||
97 | if (ref->object->type == OBJ_TAG) { | 97 | if (ref->object->type == OBJ_TAG) { |
98 | tag = lookup_tag(ref->object->sha1); | 98 | tag = lookup_tag(ref->object->sha1); |
99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
100 | return 2; | 100 | return 2; |
101 | html("<tr><td>"); | 101 | html("<tr><td>"); |
102 | url = cgit_pageurl(cgit_query_repo, "tag", | 102 | url = cgit_pageurl(cgit_query_repo, "tag", |
103 | fmt("id=%s", name)); | 103 | fmt("id=%s", name)); |
104 | html_link_open(url, NULL, NULL); | 104 | html_link_open(url, NULL, NULL); |
105 | html_txt(name); | 105 | html_txt(name); |
106 | html_link_close(); | 106 | html_link_close(); |
107 | html("</td><td>"); | 107 | html("</td><td>"); |
108 | if (info->tagger_date > 0) | 108 | if (info->tagger_date > 0) |
109 | cgit_print_age(info->tagger_date, -1, NULL); | 109 | cgit_print_age(info->tagger_date, -1, NULL); |
110 | html("</td><td>"); | 110 | html("</td><td>"); |
111 | if (info->tagger) | 111 | if (info->tagger) |
112 | html(info->tagger); | 112 | html(info->tagger); |
113 | html("</td><td>"); | 113 | html("</td><td>"); |
114 | cgit_object_link(tag->tagged); | 114 | cgit_object_link(tag->tagged); |
115 | html("</td></tr>\n"); | 115 | html("</td></tr>\n"); |
116 | } else { | 116 | } else { |
117 | if (!header) | 117 | if (!header) |
118 | print_tag_header(); | 118 | print_tag_header(); |
119 | html("<tr><td>"); | 119 | html("<tr><td>"); |
120 | html_txt(name); | 120 | html_txt(name); |
121 | html("</td><td colspan='2'/><td>"); | 121 | html("</td><td colspan='2'/><td>"); |
122 | cgit_object_link(ref->object); | 122 | cgit_object_link(ref->object); |
123 | html("</td></tr>\n"); | 123 | html("</td></tr>\n"); |
124 | } | 124 | } |
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 128 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
129 | int flags, void *cb_data) | 129 | int flags, void *cb_data) |
130 | { | 130 | { |
131 | struct tag *tag; | 131 | struct tag *tag; |
132 | struct taginfo *info; | 132 | struct taginfo *info; |
133 | struct object *obj; | 133 | struct object *obj; |
134 | char buf[256], *url; | 134 | char buf[256], *url; |
135 | unsigned char fileid[20]; | 135 | unsigned char fileid[20]; |
136 | 136 | ||
137 | if (prefixcmp(refname, "refs/archives")) | 137 | if (prefixcmp(refname, "refs/archives")) |
138 | return 0; | 138 | return 0; |
139 | strncpy(buf, refname+14, sizeof(buf)); | 139 | strncpy(buf, refname+14, sizeof(buf)); |
140 | obj = parse_object(sha1); | 140 | obj = parse_object(sha1); |
141 | if (!obj) | 141 | if (!obj) |
142 | return 1; | 142 | return 1; |
143 | if (obj->type == OBJ_TAG) { | 143 | if (obj->type == OBJ_TAG) { |
144 | tag = lookup_tag(sha1); | 144 | tag = lookup_tag(sha1); |
145 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 145 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
146 | return 0; | 146 | return 0; |
147 | hashcpy(fileid, tag->tagged->sha1); | 147 | hashcpy(fileid, tag->tagged->sha1); |
148 | } else if (obj->type != OBJ_BLOB) { | 148 | } else if (obj->type != OBJ_BLOB) { |
149 | return 0; | 149 | return 0; |
150 | } else { | 150 | } else { |
151 | hashcpy(fileid, sha1); | 151 | hashcpy(fileid, sha1); |
152 | } | 152 | } |
153 | if (!header) { | 153 | if (!header) { |
154 | html("<table id='downloads'>"); | 154 | html("<table id='downloads'>"); |
155 | html("<tr><th>Downloads</th></tr>"); | 155 | html("<tr><th>Downloads</th></tr>"); |
156 | header = 1; | 156 | header = 1; |
157 | } | 157 | } |
158 | html("<tr><td>"); | 158 | html("<tr><td>"); |
159 | url = cgit_pageurl(cgit_query_repo, "blob", | 159 | url = cgit_pageurl(cgit_query_repo, "blob", |
160 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 160 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
161 | buf)); | 161 | buf)); |
162 | html_link_open(url, NULL, NULL); | 162 | html_link_open(url, NULL, NULL); |
163 | html_txt(buf); | 163 | html_txt(buf); |
164 | html_link_close(); | 164 | html_link_close(); |
165 | html("</td></tr>"); | 165 | html("</td></tr>"); |
166 | return 0; | 166 | return 0; |
167 | } | 167 | } |
168 | 168 | ||
169 | static void print_refs_link(char *path) | ||
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 | |||
169 | void cgit_print_branches(int maxcount) | 176 | void cgit_print_branches(int maxcount) |
170 | { | 177 | { |
171 | struct reflist list; | 178 | struct reflist list; |
172 | int i; | 179 | int i; |
173 | 180 | ||
174 | html("<tr class='nohover'><th class='left'>Branch</th>" | 181 | html("<tr class='nohover'><th class='left'>Branch</th>" |
175 | "<th class='left'>Idle</th>" | 182 | "<th class='left'>Idle</th>" |
176 | "<th class='left'>Author</th>" | 183 | "<th class='left'>Author</th>" |
177 | "<th class='left'>Head commit</th></tr>\n"); | 184 | "<th class='left'>Head commit</th></tr>\n"); |
178 | 185 | ||
179 | list.refs = NULL; | 186 | list.refs = NULL; |
180 | list.alloc = list.count = 0; | 187 | list.alloc = list.count = 0; |
181 | for_each_branch_ref(cgit_refs_cb, &list); | 188 | for_each_branch_ref(cgit_refs_cb, &list); |
182 | 189 | ||
183 | if (maxcount == 0 || maxcount > list.count) | 190 | if (maxcount == 0 || maxcount > list.count) |
184 | maxcount = list.count; | 191 | maxcount = list.count; |
185 | 192 | ||
186 | if (maxcount < list.count) { | 193 | if (maxcount < list.count) { |
187 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 194 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
188 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 195 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
189 | } | 196 | } |
190 | 197 | ||
191 | for(i=0; i<maxcount; i++) | 198 | for(i=0; i<maxcount; i++) |
192 | cgit_print_branch(list.refs[i]); | 199 | cgit_print_branch(list.refs[i]); |
200 | |||
201 | if (maxcount < list.count) | ||
202 | print_refs_link("heads"); | ||
193 | } | 203 | } |
194 | 204 | ||
195 | void cgit_print_tags(int maxcount) | 205 | void cgit_print_tags(int maxcount) |
196 | { | 206 | { |
197 | struct reflist list; | 207 | struct reflist list; |
198 | int i; | 208 | int i; |
199 | 209 | ||
200 | header = 0; | 210 | header = 0; |
201 | list.refs = NULL; | 211 | list.refs = NULL; |
202 | list.alloc = list.count = 0; | 212 | list.alloc = list.count = 0; |
203 | for_each_tag_ref(cgit_refs_cb, &list); | 213 | for_each_tag_ref(cgit_refs_cb, &list); |
204 | if (list.count == 0) | 214 | if (list.count == 0) |
205 | return; | 215 | return; |
206 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 216 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
207 | if (!maxcount) | 217 | if (!maxcount) |
208 | maxcount = list.count; | 218 | maxcount = list.count; |
209 | else if (maxcount > list.count) | 219 | else if (maxcount > list.count) |
210 | maxcount = list.count; | 220 | maxcount = list.count; |
211 | print_tag_header(); | 221 | print_tag_header(); |
212 | for(i=0; i<maxcount; i++) | 222 | for(i=0; i<maxcount; i++) |
213 | print_tag(list.refs[i]); | 223 | print_tag(list.refs[i]); |
224 | |||
225 | if (maxcount < list.count) | ||
226 | print_refs_link("tags"); | ||
214 | } | 227 | } |
215 | 228 | ||
216 | static void cgit_print_archives() | 229 | static void cgit_print_archives() |
217 | { | 230 | { |
218 | header = 0; | 231 | header = 0; |
219 | for_each_ref(cgit_print_archive_cb, NULL); | 232 | for_each_ref(cgit_print_archive_cb, NULL); |
220 | if (header) | 233 | if (header) |
221 | html("</table>"); | 234 | html("</table>"); |
222 | } | 235 | } |
223 | 236 | ||
224 | void cgit_print_summary() | 237 | void cgit_print_summary() |
225 | { | 238 | { |
226 | html("<div id='summary'>"); | 239 | html("<div id='summary'>"); |
227 | cgit_print_archives(); | 240 | cgit_print_archives(); |
228 | html("<h2>"); | 241 | html("<h2>"); |
229 | html_txt(cgit_repo->name); | 242 | html_txt(cgit_repo->name); |
230 | html(" - "); | 243 | html(" - "); |
231 | html_txt(cgit_repo->desc); | 244 | html_txt(cgit_repo->desc); |
232 | html("</h2>"); | 245 | html("</h2>"); |
233 | if (cgit_repo->readme) | 246 | if (cgit_repo->readme) |
234 | html_include(cgit_repo->readme); | 247 | html_include(cgit_repo->readme); |
235 | html("</div>"); | 248 | html("</div>"); |
236 | if (cgit_summary_log > 0) | 249 | if (cgit_summary_log > 0) |
237 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | 250 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); |
238 | html("<table class='list nowrap'>"); | 251 | html("<table class='list nowrap'>"); |
239 | if (cgit_summary_log > 0) | 252 | if (cgit_summary_log > 0) |
240 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 253 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
241 | cgit_print_branches(cgit_summary_branches); | 254 | cgit_print_branches(cgit_summary_branches); |
242 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 255 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
243 | cgit_print_tags(cgit_summary_tags); | 256 | cgit_print_tags(cgit_summary_tags); |
244 | html("</table>"); | 257 | html("</table>"); |
245 | } | 258 | } |