author | Lars Hjemli <hjemli@gmail.com> | 2008-10-05 19:12:08 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-10-05 19:12:08 (UTC) |
commit | 8b5fc6de036cf159ffa61a55158044749bd6f4d9 (patch) (unidiff) | |
tree | c1accdd309b0af0f17fd97e91b8980185db79b21 | |
parent | 2e884f3162771880a2a5260713d6b7d1aa25bc6f (diff) | |
download | cgit-8b5fc6de036cf159ffa61a55158044749bd6f4d9.zip cgit-8b5fc6de036cf159ffa61a55158044749bd6f4d9.tar.gz cgit-8b5fc6de036cf159ffa61a55158044749bd6f4d9.tar.bz2 |
ui-shared: generate proper links in cgit_object_link()
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/ui-shared.c b/ui-shared.c index 1e12529..a959224 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -314,119 +314,111 @@ void cgit_commit_link(char *name, char *title, char *class, char *head, | |||
314 | name[ctx.cfg.max_msg_len - 2] = '.'; | 314 | name[ctx.cfg.max_msg_len - 2] = '.'; |
315 | name[ctx.cfg.max_msg_len - 3] = '.'; | 315 | name[ctx.cfg.max_msg_len - 3] = '.'; |
316 | } | 316 | } |
317 | reporevlink("commit", name, title, class, head, rev, NULL); | 317 | reporevlink("commit", name, title, class, head, rev, NULL); |
318 | } | 318 | } |
319 | 319 | ||
320 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 320 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
321 | char *rev, char *path) | 321 | char *rev, char *path) |
322 | { | 322 | { |
323 | reporevlink("refs", name, title, class, head, rev, path); | 323 | reporevlink("refs", name, title, class, head, rev, path); |
324 | } | 324 | } |
325 | 325 | ||
326 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 326 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
327 | char *rev, char *archivename) | 327 | char *rev, char *archivename) |
328 | { | 328 | { |
329 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 329 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
330 | } | 330 | } |
331 | 331 | ||
332 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 332 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
333 | char *new_rev, char *old_rev, char *path) | 333 | char *new_rev, char *old_rev, char *path) |
334 | { | 334 | { |
335 | char *delim; | 335 | char *delim; |
336 | 336 | ||
337 | delim = repolink(title, class, "diff", head, path); | 337 | delim = repolink(title, class, "diff", head, path); |
338 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 338 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
339 | html(delim); | 339 | html(delim); |
340 | html("id="); | 340 | html("id="); |
341 | html_url_arg(new_rev); | 341 | html_url_arg(new_rev); |
342 | delim = "&"; | 342 | delim = "&"; |
343 | } | 343 | } |
344 | if (old_rev) { | 344 | if (old_rev) { |
345 | html(delim); | 345 | html(delim); |
346 | html("id2="); | 346 | html("id2="); |
347 | html_url_arg(old_rev); | 347 | html_url_arg(old_rev); |
348 | } | 348 | } |
349 | html("'>"); | 349 | html("'>"); |
350 | html_txt(name); | 350 | html_txt(name); |
351 | html("</a>"); | 351 | html("</a>"); |
352 | } | 352 | } |
353 | 353 | ||
354 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 354 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
355 | char *rev) | 355 | char *rev) |
356 | { | 356 | { |
357 | reporevlink("patch", name, title, class, head, rev, NULL); | 357 | reporevlink("patch", name, title, class, head, rev, NULL); |
358 | } | 358 | } |
359 | 359 | ||
360 | void cgit_object_link(struct object *obj) | 360 | void cgit_object_link(struct object *obj) |
361 | { | 361 | { |
362 | char *page, *arg, *url; | 362 | char *page, *rev, *name; |
363 | 363 | ||
364 | if (obj->type == OBJ_COMMIT) { | 364 | if (obj->type == OBJ_COMMIT) { |
365 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 365 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
366 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 366 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
367 | return; | 367 | return; |
368 | } else if (obj->type == OBJ_TREE) { | 368 | } else if (obj->type == OBJ_TREE) |
369 | page = "tree"; | 369 | page = "tree"; |
370 | arg = "id"; | 370 | else if (obj->type == OBJ_TAG) |
371 | } else if (obj->type == OBJ_TAG) { | ||
372 | page = "tag"; | 371 | page = "tag"; |
373 | arg = "id"; | 372 | else |
374 | } else { | ||
375 | page = "blob"; | 373 | page = "blob"; |
376 | arg = "id"; | 374 | rev = sha1_to_hex(obj->sha1); |
377 | } | 375 | name = fmt("%s %s", typename(obj->type), rev); |
378 | 376 | reporevlink(page, name, NULL, NULL, ctx.qry.head, rev, NULL); | |
379 | url = cgit_pageurl(ctx.qry.repo, page, | ||
380 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | ||
381 | html_link_open(url, NULL, NULL); | ||
382 | htmlf("%s %s", typename(obj->type), | ||
383 | sha1_to_hex(obj->sha1)); | ||
384 | html_link_close(); | ||
385 | } | 377 | } |
386 | 378 | ||
387 | void cgit_print_date(time_t secs, char *format, int local_time) | 379 | void cgit_print_date(time_t secs, char *format, int local_time) |
388 | { | 380 | { |
389 | char buf[64]; | 381 | char buf[64]; |
390 | struct tm *time; | 382 | struct tm *time; |
391 | 383 | ||
392 | if (!secs) | 384 | if (!secs) |
393 | return; | 385 | return; |
394 | if(local_time) | 386 | if(local_time) |
395 | time = localtime(&secs); | 387 | time = localtime(&secs); |
396 | else | 388 | else |
397 | time = gmtime(&secs); | 389 | time = gmtime(&secs); |
398 | strftime(buf, sizeof(buf)-1, format, time); | 390 | strftime(buf, sizeof(buf)-1, format, time); |
399 | html_txt(buf); | 391 | html_txt(buf); |
400 | } | 392 | } |
401 | 393 | ||
402 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 394 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
403 | { | 395 | { |
404 | time_t now, secs; | 396 | time_t now, secs; |
405 | 397 | ||
406 | if (!t) | 398 | if (!t) |
407 | return; | 399 | return; |
408 | time(&now); | 400 | time(&now); |
409 | secs = now - t; | 401 | secs = now - t; |
410 | 402 | ||
411 | if (secs > max_relative && max_relative >= 0) { | 403 | if (secs > max_relative && max_relative >= 0) { |
412 | cgit_print_date(t, format, ctx.cfg.local_time); | 404 | cgit_print_date(t, format, ctx.cfg.local_time); |
413 | return; | 405 | return; |
414 | } | 406 | } |
415 | 407 | ||
416 | if (secs < TM_HOUR * 2) { | 408 | if (secs < TM_HOUR * 2) { |
417 | htmlf("<span class='age-mins'>%.0f min.</span>", | 409 | htmlf("<span class='age-mins'>%.0f min.</span>", |
418 | secs * 1.0 / TM_MIN); | 410 | secs * 1.0 / TM_MIN); |
419 | return; | 411 | return; |
420 | } | 412 | } |
421 | if (secs < TM_DAY * 2) { | 413 | if (secs < TM_DAY * 2) { |
422 | htmlf("<span class='age-hours'>%.0f hours</span>", | 414 | htmlf("<span class='age-hours'>%.0f hours</span>", |
423 | secs * 1.0 / TM_HOUR); | 415 | secs * 1.0 / TM_HOUR); |
424 | return; | 416 | return; |
425 | } | 417 | } |
426 | if (secs < TM_WEEK * 2) { | 418 | if (secs < TM_WEEK * 2) { |
427 | htmlf("<span class='age-days'>%.0f days</span>", | 419 | htmlf("<span class='age-days'>%.0f days</span>", |
428 | secs * 1.0 / TM_DAY); | 420 | secs * 1.0 / TM_DAY); |
429 | return; | 421 | return; |
430 | } | 422 | } |
431 | if (secs < TM_MONTH * 2) { | 423 | if (secs < TM_MONTH * 2) { |
432 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 424 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |