-rw-r--r-- | ui-shared.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c index 4fa506f..d5c4c10 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -263,259 +263,259 @@ void cgit_summary_link(const char *name, const char *title, const char *class, | |||
263 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 263 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
264 | } | 264 | } |
265 | 265 | ||
266 | void cgit_tag_link(const char *name, const char *title, const char *class, | 266 | void cgit_tag_link(const char *name, const char *title, const char *class, |
267 | const char *head, const char *rev) | 267 | const char *head, const char *rev) |
268 | { | 268 | { |
269 | reporevlink("tag", name, title, class, head, rev, NULL); | 269 | reporevlink("tag", name, title, class, head, rev, NULL); |
270 | } | 270 | } |
271 | 271 | ||
272 | void cgit_tree_link(const char *name, const char *title, const char *class, | 272 | void cgit_tree_link(const char *name, const char *title, const char *class, |
273 | const char *head, const char *rev, const char *path) | 273 | const char *head, const char *rev, const char *path) |
274 | { | 274 | { |
275 | reporevlink("tree", name, title, class, head, rev, path); | 275 | reporevlink("tree", name, title, class, head, rev, path); |
276 | } | 276 | } |
277 | 277 | ||
278 | void cgit_plain_link(const char *name, const char *title, const char *class, | 278 | void cgit_plain_link(const char *name, const char *title, const char *class, |
279 | const char *head, const char *rev, const char *path) | 279 | const char *head, const char *rev, const char *path) |
280 | { | 280 | { |
281 | reporevlink("plain", name, title, class, head, rev, path); | 281 | reporevlink("plain", name, title, class, head, rev, path); |
282 | } | 282 | } |
283 | 283 | ||
284 | void cgit_log_link(const char *name, const char *title, const char *class, | 284 | void cgit_log_link(const char *name, const char *title, const char *class, |
285 | const char *head, const char *rev, const char *path, | 285 | const char *head, const char *rev, const char *path, |
286 | int ofs, const char *grep, const char *pattern, int showmsg) | 286 | int ofs, const char *grep, const char *pattern, int showmsg) |
287 | { | 287 | { |
288 | char *delim; | 288 | char *delim; |
289 | 289 | ||
290 | delim = repolink(title, class, "log", head, path); | 290 | delim = repolink(title, class, "log", head, path); |
291 | if (rev && strcmp(rev, ctx.qry.head)) { | 291 | if (rev && strcmp(rev, ctx.qry.head)) { |
292 | html(delim); | 292 | html(delim); |
293 | html("id="); | 293 | html("id="); |
294 | html_url_arg(rev); | 294 | html_url_arg(rev); |
295 | delim = "&"; | 295 | delim = "&"; |
296 | } | 296 | } |
297 | if (grep && pattern) { | 297 | if (grep && pattern) { |
298 | html(delim); | 298 | html(delim); |
299 | html("qt="); | 299 | html("qt="); |
300 | html_url_arg(grep); | 300 | html_url_arg(grep); |
301 | delim = "&"; | 301 | delim = "&"; |
302 | html(delim); | 302 | html(delim); |
303 | html("q="); | 303 | html("q="); |
304 | html_url_arg(pattern); | 304 | html_url_arg(pattern); |
305 | } | 305 | } |
306 | if (ofs > 0) { | 306 | if (ofs > 0) { |
307 | html(delim); | 307 | html(delim); |
308 | html("ofs="); | 308 | html("ofs="); |
309 | htmlf("%d", ofs); | 309 | htmlf("%d", ofs); |
310 | delim = "&"; | 310 | delim = "&"; |
311 | } | 311 | } |
312 | if (showmsg) { | 312 | if (showmsg) { |
313 | html(delim); | 313 | html(delim); |
314 | html("showmsg=1"); | 314 | html("showmsg=1"); |
315 | } | 315 | } |
316 | html("'>"); | 316 | html("'>"); |
317 | html_txt(name); | 317 | html_txt(name); |
318 | html("</a>"); | 318 | html("</a>"); |
319 | } | 319 | } |
320 | 320 | ||
321 | void cgit_commit_link(char *name, const char *title, const char *class, | 321 | void cgit_commit_link(char *name, const char *title, const char *class, |
322 | const char *head, const char *rev, int toggle_ssdiff) | 322 | const char *head, const char *rev, int toggle_ssdiff) |
323 | { | 323 | { |
324 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 324 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
325 | name[ctx.cfg.max_msg_len] = '\0'; | 325 | name[ctx.cfg.max_msg_len] = '\0'; |
326 | name[ctx.cfg.max_msg_len - 1] = '.'; | 326 | name[ctx.cfg.max_msg_len - 1] = '.'; |
327 | name[ctx.cfg.max_msg_len - 2] = '.'; | 327 | name[ctx.cfg.max_msg_len - 2] = '.'; |
328 | name[ctx.cfg.max_msg_len - 3] = '.'; | 328 | name[ctx.cfg.max_msg_len - 3] = '.'; |
329 | } | 329 | } |
330 | 330 | ||
331 | char *delim; | 331 | char *delim; |
332 | 332 | ||
333 | delim = repolink(title, class, "commit", head, NULL); | 333 | delim = repolink(title, class, "commit", head, NULL); |
334 | if (rev && strcmp(rev, ctx.qry.head)) { | 334 | if (rev && strcmp(rev, ctx.qry.head)) { |
335 | html(delim); | 335 | html(delim); |
336 | html("id="); | 336 | html("id="); |
337 | html_url_arg(rev); | 337 | html_url_arg(rev); |
338 | delim = "&"; | 338 | delim = "&"; |
339 | } | 339 | } |
340 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 340 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
341 | html(delim); | 341 | html(delim); |
342 | html("ss=1"); | 342 | html("ss=1"); |
343 | } | 343 | } |
344 | html("'>"); | 344 | html("'>"); |
345 | html_txt(name); | 345 | html_txt(name); |
346 | html("</a>"); | 346 | html("</a>"); |
347 | } | 347 | } |
348 | 348 | ||
349 | void cgit_refs_link(const char *name, const char *title, const char *class, | 349 | void cgit_refs_link(const char *name, const char *title, const char *class, |
350 | const char *head, const char *rev, const char *path) | 350 | const char *head, const char *rev, const char *path) |
351 | { | 351 | { |
352 | reporevlink("refs", name, title, class, head, rev, path); | 352 | reporevlink("refs", name, title, class, head, rev, path); |
353 | } | 353 | } |
354 | 354 | ||
355 | void cgit_snapshot_link(const char *name, const char *title, const char *class, | 355 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
356 | const char *head, const char *rev, | 356 | const char *head, const char *rev, |
357 | const char *archivename) | 357 | const char *archivename) |
358 | { | 358 | { |
359 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 359 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
360 | } | 360 | } |
361 | 361 | ||
362 | void cgit_diff_link(const char *name, const char *title, const char *class, | 362 | void cgit_diff_link(const char *name, const char *title, const char *class, |
363 | const char *head, const char *new_rev, const char *old_rev, | 363 | const char *head, const char *new_rev, const char *old_rev, |
364 | const char *path, int toggle_ssdiff) | 364 | const char *path, int toggle_ssdiff) |
365 | { | 365 | { |
366 | char *delim; | 366 | char *delim; |
367 | 367 | ||
368 | delim = repolink(title, class, "diff", head, path); | 368 | delim = repolink(title, class, "diff", head, path); |
369 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { | 369 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
370 | html(delim); | 370 | html(delim); |
371 | html("id="); | 371 | html("id="); |
372 | html_url_arg(new_rev); | 372 | html_url_arg(new_rev); |
373 | delim = "&"; | 373 | delim = "&"; |
374 | } | 374 | } |
375 | if (old_rev) { | 375 | if (old_rev) { |
376 | html(delim); | 376 | html(delim); |
377 | html("id2="); | 377 | html("id2="); |
378 | html_url_arg(old_rev); | 378 | html_url_arg(old_rev); |
379 | delim = "&"; | 379 | delim = "&"; |
380 | } | 380 | } |
381 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 381 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
382 | html(delim); | 382 | html(delim); |
383 | html("ss=1"); | 383 | html("ss=1"); |
384 | } | 384 | } |
385 | html("'>"); | 385 | html("'>"); |
386 | html_txt(name); | 386 | html_txt(name); |
387 | html("</a>"); | 387 | html("</a>"); |
388 | } | 388 | } |
389 | 389 | ||
390 | void cgit_patch_link(const char *name, const char *title, const char *class, | 390 | void cgit_patch_link(const char *name, const char *title, const char *class, |
391 | const char *head, const char *rev) | 391 | const char *head, const char *rev, const char *path) |
392 | { | 392 | { |
393 | reporevlink("patch", name, title, class, head, rev, NULL); | 393 | reporevlink("patch", name, title, class, head, rev, path); |
394 | } | 394 | } |
395 | 395 | ||
396 | void cgit_stats_link(const char *name, const char *title, const char *class, | 396 | void cgit_stats_link(const char *name, const char *title, const char *class, |
397 | const char *head, const char *path) | 397 | const char *head, const char *path) |
398 | { | 398 | { |
399 | reporevlink("stats", name, title, class, head, NULL, path); | 399 | reporevlink("stats", name, title, class, head, NULL, path); |
400 | } | 400 | } |
401 | 401 | ||
402 | void cgit_self_link(char *name, const char *title, const char *class, | 402 | void cgit_self_link(char *name, const char *title, const char *class, |
403 | struct cgit_context *ctx) | 403 | struct cgit_context *ctx) |
404 | { | 404 | { |
405 | if (!strcmp(ctx->qry.page, "repolist")) | 405 | if (!strcmp(ctx->qry.page, "repolist")) |
406 | return cgit_index_link(name, title, class, ctx->qry.search, | 406 | return cgit_index_link(name, title, class, ctx->qry.search, |
407 | ctx->qry.ofs); | 407 | ctx->qry.ofs); |
408 | else if (!strcmp(ctx->qry.page, "summary")) | 408 | else if (!strcmp(ctx->qry.page, "summary")) |
409 | return cgit_summary_link(name, title, class, ctx->qry.head); | 409 | return cgit_summary_link(name, title, class, ctx->qry.head); |
410 | else if (!strcmp(ctx->qry.page, "tag")) | 410 | else if (!strcmp(ctx->qry.page, "tag")) |
411 | return cgit_tag_link(name, title, class, ctx->qry.head, | 411 | return cgit_tag_link(name, title, class, ctx->qry.head, |
412 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | 412 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); |
413 | else if (!strcmp(ctx->qry.page, "tree")) | 413 | else if (!strcmp(ctx->qry.page, "tree")) |
414 | return cgit_tree_link(name, title, class, ctx->qry.head, | 414 | return cgit_tree_link(name, title, class, ctx->qry.head, |
415 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 415 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
416 | ctx->qry.path); | 416 | ctx->qry.path); |
417 | else if (!strcmp(ctx->qry.page, "plain")) | 417 | else if (!strcmp(ctx->qry.page, "plain")) |
418 | return cgit_plain_link(name, title, class, ctx->qry.head, | 418 | return cgit_plain_link(name, title, class, ctx->qry.head, |
419 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 419 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
420 | ctx->qry.path); | 420 | ctx->qry.path); |
421 | else if (!strcmp(ctx->qry.page, "log")) | 421 | else if (!strcmp(ctx->qry.page, "log")) |
422 | return cgit_log_link(name, title, class, ctx->qry.head, | 422 | return cgit_log_link(name, title, class, ctx->qry.head, |
423 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 423 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
424 | ctx->qry.path, ctx->qry.ofs, | 424 | ctx->qry.path, ctx->qry.ofs, |
425 | ctx->qry.grep, ctx->qry.search, | 425 | ctx->qry.grep, ctx->qry.search, |
426 | ctx->qry.showmsg); | 426 | ctx->qry.showmsg); |
427 | else if (!strcmp(ctx->qry.page, "commit")) | 427 | else if (!strcmp(ctx->qry.page, "commit")) |
428 | return cgit_commit_link(name, title, class, ctx->qry.head, | 428 | return cgit_commit_link(name, title, class, ctx->qry.head, |
429 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 429 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
430 | ctx->qry.path, 0); | 430 | ctx->qry.path, 0); |
431 | else if (!strcmp(ctx->qry.page, "patch")) | 431 | else if (!strcmp(ctx->qry.page, "patch")) |
432 | return cgit_patch_link(name, title, class, ctx->qry.head, | 432 | return cgit_patch_link(name, title, class, ctx->qry.head, |
433 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 433 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
434 | ctx->qry.path); | 434 | ctx->qry.path); |
435 | else if (!strcmp(ctx->qry.page, "refs")) | 435 | else if (!strcmp(ctx->qry.page, "refs")) |
436 | return cgit_refs_link(name, title, class, ctx->qry.head, | 436 | return cgit_refs_link(name, title, class, ctx->qry.head, |
437 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 437 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
438 | ctx->qry.path); | 438 | ctx->qry.path); |
439 | else if (!strcmp(ctx->qry.page, "snapshot")) | 439 | else if (!strcmp(ctx->qry.page, "snapshot")) |
440 | return cgit_snapshot_link(name, title, class, ctx->qry.head, | 440 | return cgit_snapshot_link(name, title, class, ctx->qry.head, |
441 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 441 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
442 | ctx->qry.path); | 442 | ctx->qry.path); |
443 | else if (!strcmp(ctx->qry.page, "diff")) | 443 | else if (!strcmp(ctx->qry.page, "diff")) |
444 | return cgit_diff_link(name, title, class, ctx->qry.head, | 444 | return cgit_diff_link(name, title, class, ctx->qry.head, |
445 | ctx->qry.sha1, ctx->qry.sha2, | 445 | ctx->qry.sha1, ctx->qry.sha2, |
446 | ctx->qry.path, 0); | 446 | ctx->qry.path, 0); |
447 | else if (!strcmp(ctx->qry.page, "stats")) | 447 | else if (!strcmp(ctx->qry.page, "stats")) |
448 | return cgit_stats_link(name, title, class, ctx->qry.head, | 448 | return cgit_stats_link(name, title, class, ctx->qry.head, |
449 | ctx->qry.path); | 449 | ctx->qry.path); |
450 | 450 | ||
451 | /* Don't known how to make link for this page */ | 451 | /* Don't known how to make link for this page */ |
452 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); | 452 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); |
453 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); | 453 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); |
454 | html_txt(ctx->qry.page); | 454 | html_txt(ctx->qry.page); |
455 | html("' -->"); | 455 | html("' -->"); |
456 | html_txt(name); | 456 | html_txt(name); |
457 | html("</a>"); | 457 | html("</a>"); |
458 | } | 458 | } |
459 | 459 | ||
460 | void cgit_object_link(struct object *obj) | 460 | void cgit_object_link(struct object *obj) |
461 | { | 461 | { |
462 | char *page, *shortrev, *fullrev, *name; | 462 | char *page, *shortrev, *fullrev, *name; |
463 | 463 | ||
464 | fullrev = sha1_to_hex(obj->sha1); | 464 | fullrev = sha1_to_hex(obj->sha1); |
465 | shortrev = xstrdup(fullrev); | 465 | shortrev = xstrdup(fullrev); |
466 | shortrev[10] = '\0'; | 466 | shortrev[10] = '\0'; |
467 | if (obj->type == OBJ_COMMIT) { | 467 | if (obj->type == OBJ_COMMIT) { |
468 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 468 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
469 | ctx.qry.head, fullrev, 0); | 469 | ctx.qry.head, fullrev, 0); |
470 | return; | 470 | return; |
471 | } else if (obj->type == OBJ_TREE) | 471 | } else if (obj->type == OBJ_TREE) |
472 | page = "tree"; | 472 | page = "tree"; |
473 | else if (obj->type == OBJ_TAG) | 473 | else if (obj->type == OBJ_TAG) |
474 | page = "tag"; | 474 | page = "tag"; |
475 | else | 475 | else |
476 | page = "blob"; | 476 | page = "blob"; |
477 | name = fmt("%s %s...", typename(obj->type), shortrev); | 477 | name = fmt("%s %s...", typename(obj->type), shortrev); |
478 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 478 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
479 | } | 479 | } |
480 | 480 | ||
481 | void cgit_print_date(time_t secs, const char *format, int local_time) | 481 | void cgit_print_date(time_t secs, const char *format, int local_time) |
482 | { | 482 | { |
483 | char buf[64]; | 483 | char buf[64]; |
484 | struct tm *time; | 484 | struct tm *time; |
485 | 485 | ||
486 | if (!secs) | 486 | if (!secs) |
487 | return; | 487 | return; |
488 | if(local_time) | 488 | if(local_time) |
489 | time = localtime(&secs); | 489 | time = localtime(&secs); |
490 | else | 490 | else |
491 | time = gmtime(&secs); | 491 | time = gmtime(&secs); |
492 | strftime(buf, sizeof(buf)-1, format, time); | 492 | strftime(buf, sizeof(buf)-1, format, time); |
493 | html_txt(buf); | 493 | html_txt(buf); |
494 | } | 494 | } |
495 | 495 | ||
496 | void cgit_print_age(time_t t, time_t max_relative, const char *format) | 496 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
497 | { | 497 | { |
498 | time_t now, secs; | 498 | time_t now, secs; |
499 | 499 | ||
500 | if (!t) | 500 | if (!t) |
501 | return; | 501 | return; |
502 | time(&now); | 502 | time(&now); |
503 | secs = now - t; | 503 | secs = now - t; |
504 | 504 | ||
505 | if (secs > max_relative && max_relative >= 0) { | 505 | if (secs > max_relative && max_relative >= 0) { |
506 | cgit_print_date(t, format, ctx.cfg.local_time); | 506 | cgit_print_date(t, format, ctx.cfg.local_time); |
507 | return; | 507 | return; |
508 | } | 508 | } |
509 | 509 | ||
510 | if (secs < TM_HOUR * 2) { | 510 | if (secs < TM_HOUR * 2) { |
511 | htmlf("<span class='age-mins'>%.0f min.</span>", | 511 | htmlf("<span class='age-mins'>%.0f min.</span>", |
512 | secs * 1.0 / TM_MIN); | 512 | secs * 1.0 / TM_MIN); |
513 | return; | 513 | return; |
514 | } | 514 | } |
515 | if (secs < TM_DAY * 2) { | 515 | if (secs < TM_DAY * 2) { |
516 | htmlf("<span class='age-hours'>%.0f hours</span>", | 516 | htmlf("<span class='age-hours'>%.0f hours</span>", |
517 | secs * 1.0 / TM_HOUR); | 517 | secs * 1.0 / TM_HOUR); |
518 | return; | 518 | return; |
519 | } | 519 | } |
520 | if (secs < TM_WEEK * 2) { | 520 | if (secs < TM_WEEK * 2) { |
521 | htmlf("<span class='age-days'>%.0f days</span>", | 521 | htmlf("<span class='age-days'>%.0f days</span>", |