-rw-r--r-- | ui-shared.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index 45105dc..1418010 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -211,128 +211,131 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
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, | 230 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
231 | char *rev, char *path) | 231 | char *rev, char *path) |
232 | { | 232 | { |
233 | reporevlink("refs", name, title, class, head, rev, path); | 233 | reporevlink("refs", name, title, class, head, rev, path); |
234 | } | 234 | } |
235 | 235 | ||
236 | 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, |
237 | char *rev, char *archivename) | 237 | char *rev, char *archivename) |
238 | { | 238 | { |
239 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 239 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
240 | } | 240 | } |
241 | 241 | ||
242 | 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, |
243 | char *new_rev, char *old_rev, char *path) | 243 | char *new_rev, char *old_rev, char *path) |
244 | { | 244 | { |
245 | char *delim; | 245 | char *delim; |
246 | 246 | ||
247 | delim = repolink(title, class, "diff", head, path); | 247 | delim = repolink(title, class, "diff", head, path); |
248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
249 | html(delim); | 249 | html(delim); |
250 | html("id="); | 250 | html("id="); |
251 | html_attr(new_rev); | 251 | html_attr(new_rev); |
252 | delim = "&"; | 252 | delim = "&"; |
253 | } | 253 | } |
254 | if (old_rev) { | 254 | if (old_rev) { |
255 | html(delim); | 255 | html(delim); |
256 | html("id2="); | 256 | html("id2="); |
257 | html_attr(old_rev); | 257 | html_attr(old_rev); |
258 | } | 258 | } |
259 | html("'>"); | 259 | html("'>"); |
260 | html_txt(name); | 260 | html_txt(name); |
261 | html("</a>"); | 261 | html("</a>"); |
262 | } | 262 | } |
263 | 263 | ||
264 | void cgit_object_link(struct object *obj) | 264 | void cgit_object_link(struct object *obj) |
265 | { | 265 | { |
266 | char *page, *arg, *url; | 266 | char *page, *arg, *url; |
267 | 267 | ||
268 | if (obj->type == OBJ_COMMIT) { | 268 | if (obj->type == OBJ_COMMIT) { |
269 | 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, |
270 | cgit_query_head, sha1_to_hex(obj->sha1)); | 270 | cgit_query_head, sha1_to_hex(obj->sha1)); |
271 | return; | 271 | return; |
272 | } else if (obj->type == OBJ_TREE) { | 272 | } else if (obj->type == OBJ_TREE) { |
273 | page = "tree"; | 273 | page = "tree"; |
274 | arg = "id"; | 274 | arg = "id"; |
275 | } else if (obj->type == OBJ_TAG) { | ||
276 | page = "tag"; | ||
277 | arg = "id"; | ||
275 | } else { | 278 | } else { |
276 | page = "blob"; | 279 | page = "blob"; |
277 | arg = "id"; | 280 | arg = "id"; |
278 | } | 281 | } |
279 | 282 | ||
280 | url = cgit_pageurl(cgit_query_repo, page, | 283 | url = cgit_pageurl(cgit_query_repo, page, |
281 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 284 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
282 | html_link_open(url, NULL, NULL); | 285 | html_link_open(url, NULL, NULL); |
283 | htmlf("%s %s", typename(obj->type), | 286 | htmlf("%s %s", typename(obj->type), |
284 | sha1_to_hex(obj->sha1)); | 287 | sha1_to_hex(obj->sha1)); |
285 | html_link_close(); | 288 | html_link_close(); |
286 | } | 289 | } |
287 | 290 | ||
288 | void cgit_print_date(time_t secs, char *format) | 291 | void cgit_print_date(time_t secs, char *format) |
289 | { | 292 | { |
290 | char buf[64]; | 293 | char buf[64]; |
291 | struct tm *time; | 294 | struct tm *time; |
292 | 295 | ||
293 | time = gmtime(&secs); | 296 | time = gmtime(&secs); |
294 | strftime(buf, sizeof(buf)-1, format, time); | 297 | strftime(buf, sizeof(buf)-1, format, time); |
295 | html_txt(buf); | 298 | html_txt(buf); |
296 | } | 299 | } |
297 | 300 | ||
298 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 301 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
299 | { | 302 | { |
300 | time_t now, secs; | 303 | time_t now, secs; |
301 | 304 | ||
302 | time(&now); | 305 | time(&now); |
303 | secs = now - t; | 306 | secs = now - t; |
304 | 307 | ||
305 | if (secs > max_relative && max_relative >= 0) { | 308 | if (secs > max_relative && max_relative >= 0) { |
306 | cgit_print_date(t, format); | 309 | cgit_print_date(t, format); |
307 | return; | 310 | return; |
308 | } | 311 | } |
309 | 312 | ||
310 | if (secs < TM_HOUR * 2) { | 313 | if (secs < TM_HOUR * 2) { |
311 | htmlf("<span class='age-mins'>%.0f min.</span>", | 314 | htmlf("<span class='age-mins'>%.0f min.</span>", |
312 | secs * 1.0 / TM_MIN); | 315 | secs * 1.0 / TM_MIN); |
313 | return; | 316 | return; |
314 | } | 317 | } |
315 | if (secs < TM_DAY * 2) { | 318 | if (secs < TM_DAY * 2) { |
316 | htmlf("<span class='age-hours'>%.0f hours</span>", | 319 | htmlf("<span class='age-hours'>%.0f hours</span>", |
317 | secs * 1.0 / TM_HOUR); | 320 | secs * 1.0 / TM_HOUR); |
318 | return; | 321 | return; |
319 | } | 322 | } |
320 | if (secs < TM_WEEK * 2) { | 323 | if (secs < TM_WEEK * 2) { |
321 | htmlf("<span class='age-days'>%.0f days</span>", | 324 | htmlf("<span class='age-days'>%.0f days</span>", |
322 | secs * 1.0 / TM_DAY); | 325 | secs * 1.0 / TM_DAY); |
323 | return; | 326 | return; |
324 | } | 327 | } |
325 | if (secs < TM_MONTH * 2) { | 328 | if (secs < TM_MONTH * 2) { |
326 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 329 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
327 | secs * 1.0 / TM_WEEK); | 330 | secs * 1.0 / TM_WEEK); |
328 | return; | 331 | return; |
329 | } | 332 | } |
330 | if (secs < TM_YEAR * 2) { | 333 | if (secs < TM_YEAR * 2) { |
331 | htmlf("<span class='age-months'>%.0f months</span>", | 334 | htmlf("<span class='age-months'>%.0f months</span>", |
332 | secs * 1.0 / TM_MONTH); | 335 | secs * 1.0 / TM_MONTH); |
333 | return; | 336 | return; |
334 | } | 337 | } |
335 | htmlf("<span class='age-years'>%.0f years</span>", | 338 | htmlf("<span class='age-years'>%.0f years</span>", |
336 | secs * 1.0 / TM_YEAR); | 339 | secs * 1.0 / TM_YEAR); |
337 | } | 340 | } |
338 | 341 | ||