summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorJohan Herland <johan@herland.net>2010-06-10 18:15:51 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 11:00:07 (UTC)
commitd20313e3daf855ee5d4808e050f54614c200d7b1 (patch) (unidiff)
tree5c462f3ba6ec97c0b099a309dfd0fa87d03fbc72 /ui-shared.c
parent6180e6169d6e87a3bea7e4da835dca17f93e5cfd (diff)
downloadcgit-d20313e3daf855ee5d4808e050f54614c200d7b1.zip
cgit-d20313e3daf855ee5d4808e050f54614c200d7b1.tar.gz
cgit-d20313e3daf855ee5d4808e050f54614c200d7b1.tar.bz2
ui-diff: Add links to increase/decrease number of context lines in diffs
Add two links to the "Diffstat" line to show more/less context lines in the generated diff. To support this, cgit_commit_link() and cgit_diff_link() has learned to preserve the ctx.qry.context variable. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index e991799..c99bcec 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -216,297 +216,311 @@ static char *repolink(const char *title, const char *class, const char *page,
216 html("/"); 216 html("/");
217 if (path) 217 if (path)
218 html_url_path(path); 218 html_url_path(path);
219 } 219 }
220 } else { 220 } else {
221 html(ctx.cfg.script_name); 221 html(ctx.cfg.script_name);
222 html("?url="); 222 html("?url=");
223 html_url_arg(ctx.repo->url); 223 html_url_arg(ctx.repo->url);
224 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 224 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
225 html("/"); 225 html("/");
226 if (page) { 226 if (page) {
227 html_url_arg(page); 227 html_url_arg(page);
228 html("/"); 228 html("/");
229 if (path) 229 if (path)
230 html_url_arg(path); 230 html_url_arg(path);
231 } 231 }
232 delim = "&amp;"; 232 delim = "&amp;";
233 } 233 }
234 if (head && strcmp(head, ctx.repo->defbranch)) { 234 if (head && strcmp(head, ctx.repo->defbranch)) {
235 html(delim); 235 html(delim);
236 html("h="); 236 html("h=");
237 html_url_arg(head); 237 html_url_arg(head);
238 delim = "&amp;"; 238 delim = "&amp;";
239 } 239 }
240 return fmt("%s", delim); 240 return fmt("%s", delim);
241} 241}
242 242
243static void reporevlink(const char *page, const char *name, const char *title, 243static void reporevlink(const char *page, const char *name, const char *title,
244 const char *class, const char *head, const char *rev, 244 const char *class, const char *head, const char *rev,
245 const char *path) 245 const char *path)
246{ 246{
247 char *delim; 247 char *delim;
248 248
249 delim = repolink(title, class, page, head, path); 249 delim = repolink(title, class, page, head, path);
250 if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { 250 if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
251 html(delim); 251 html(delim);
252 html("id="); 252 html("id=");
253 html_url_arg(rev); 253 html_url_arg(rev);
254 } 254 }
255 html("'>"); 255 html("'>");
256 html_txt(name); 256 html_txt(name);
257 html("</a>"); 257 html("</a>");
258} 258}
259 259
260void cgit_summary_link(const char *name, const char *title, const char *class, 260void cgit_summary_link(const char *name, const char *title, const char *class,
261 const char *head) 261 const char *head)
262{ 262{
263 reporevlink(NULL, name, title, class, head, NULL, NULL); 263 reporevlink(NULL, name, title, class, head, NULL, NULL);
264} 264}
265 265
266void cgit_tag_link(const char *name, const char *title, const char *class, 266void 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
272void cgit_tree_link(const char *name, const char *title, const char *class, 272void 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
278void cgit_plain_link(const char *name, const char *title, const char *class, 278void 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
284void cgit_log_link(const char *name, const char *title, const char *class, 284void 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
321void cgit_commit_link(char *name, const char *title, const char *class, 321void cgit_commit_link(char *name, const char *title, const char *class,
322 const char *head, const char *rev, const char *path, 322 const char *head, const char *rev, const char *path,
323 int toggle_ssdiff) 323 int toggle_ssdiff)
324{ 324{
325 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 325 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
326 name[ctx.cfg.max_msg_len] = '\0'; 326 name[ctx.cfg.max_msg_len] = '\0';
327 name[ctx.cfg.max_msg_len - 1] = '.'; 327 name[ctx.cfg.max_msg_len - 1] = '.';
328 name[ctx.cfg.max_msg_len - 2] = '.'; 328 name[ctx.cfg.max_msg_len - 2] = '.';
329 name[ctx.cfg.max_msg_len - 3] = '.'; 329 name[ctx.cfg.max_msg_len - 3] = '.';
330 } 330 }
331 331
332 char *delim; 332 char *delim;
333 333
334 delim = repolink(title, class, "commit", head, path); 334 delim = repolink(title, class, "commit", head, path);
335 if (rev && strcmp(rev, ctx.qry.head)) { 335 if (rev && strcmp(rev, ctx.qry.head)) {
336 html(delim); 336 html(delim);
337 html("id="); 337 html("id=");
338 html_url_arg(rev); 338 html_url_arg(rev);
339 delim = "&amp;"; 339 delim = "&amp;";
340 } 340 }
341 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { 341 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
342 html(delim); 342 html(delim);
343 html("ss=1"); 343 html("ss=1");
344 delim = "&amp;";
345 }
346 if (ctx.qry.context > 0 && ctx.qry.context != 3) {
347 html(delim);
348 html("context=");
349 htmlf("%d", ctx.qry.context);
350 delim = "&amp;";
344 } 351 }
345 html("'>"); 352 html("'>");
346 html_txt(name); 353 html_txt(name);
347 html("</a>"); 354 html("</a>");
348} 355}
349 356
350void cgit_refs_link(const char *name, const char *title, const char *class, 357void cgit_refs_link(const char *name, const char *title, const char *class,
351 const char *head, const char *rev, const char *path) 358 const char *head, const char *rev, const char *path)
352{ 359{
353 reporevlink("refs", name, title, class, head, rev, path); 360 reporevlink("refs", name, title, class, head, rev, path);
354} 361}
355 362
356void cgit_snapshot_link(const char *name, const char *title, const char *class, 363void cgit_snapshot_link(const char *name, const char *title, const char *class,
357 const char *head, const char *rev, 364 const char *head, const char *rev,
358 const char *archivename) 365 const char *archivename)
359{ 366{
360 reporevlink("snapshot", name, title, class, head, rev, archivename); 367 reporevlink("snapshot", name, title, class, head, rev, archivename);
361} 368}
362 369
363void cgit_diff_link(const char *name, const char *title, const char *class, 370void cgit_diff_link(const char *name, const char *title, const char *class,
364 const char *head, const char *new_rev, const char *old_rev, 371 const char *head, const char *new_rev, const char *old_rev,
365 const char *path, int toggle_ssdiff) 372 const char *path, int toggle_ssdiff)
366{ 373{
367 char *delim; 374 char *delim;
368 375
369 delim = repolink(title, class, "diff", head, path); 376 delim = repolink(title, class, "diff", head, path);
370 if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { 377 if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
371 html(delim); 378 html(delim);
372 html("id="); 379 html("id=");
373 html_url_arg(new_rev); 380 html_url_arg(new_rev);
374 delim = "&amp;"; 381 delim = "&amp;";
375 } 382 }
376 if (old_rev) { 383 if (old_rev) {
377 html(delim); 384 html(delim);
378 html("id2="); 385 html("id2=");
379 html_url_arg(old_rev); 386 html_url_arg(old_rev);
380 delim = "&amp;"; 387 delim = "&amp;";
381 } 388 }
382 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { 389 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
383 html(delim); 390 html(delim);
384 html("ss=1"); 391 html("ss=1");
392 delim = "&amp;";
393 }
394 if (ctx.qry.context > 0 && ctx.qry.context != 3) {
395 html(delim);
396 html("context=");
397 htmlf("%d", ctx.qry.context);
398 delim = "&amp;";
385 } 399 }
386 html("'>"); 400 html("'>");
387 html_txt(name); 401 html_txt(name);
388 html("</a>"); 402 html("</a>");
389} 403}
390 404
391void cgit_patch_link(const char *name, const char *title, const char *class, 405void cgit_patch_link(const char *name, const char *title, const char *class,
392 const char *head, const char *rev, const char *path) 406 const char *head, const char *rev, const char *path)
393{ 407{
394 reporevlink("patch", name, title, class, head, rev, path); 408 reporevlink("patch", name, title, class, head, rev, path);
395} 409}
396 410
397void cgit_stats_link(const char *name, const char *title, const char *class, 411void cgit_stats_link(const char *name, const char *title, const char *class,
398 const char *head, const char *path) 412 const char *head, const char *path)
399{ 413{
400 reporevlink("stats", name, title, class, head, NULL, path); 414 reporevlink("stats", name, title, class, head, NULL, path);
401} 415}
402 416
403void cgit_self_link(char *name, const char *title, const char *class, 417void cgit_self_link(char *name, const char *title, const char *class,
404 struct cgit_context *ctx) 418 struct cgit_context *ctx)
405{ 419{
406 if (!strcmp(ctx->qry.page, "repolist")) 420 if (!strcmp(ctx->qry.page, "repolist"))
407 return cgit_index_link(name, title, class, ctx->qry.search, 421 return cgit_index_link(name, title, class, ctx->qry.search,
408 ctx->qry.ofs); 422 ctx->qry.ofs);
409 else if (!strcmp(ctx->qry.page, "summary")) 423 else if (!strcmp(ctx->qry.page, "summary"))
410 return cgit_summary_link(name, title, class, ctx->qry.head); 424 return cgit_summary_link(name, title, class, ctx->qry.head);
411 else if (!strcmp(ctx->qry.page, "tag")) 425 else if (!strcmp(ctx->qry.page, "tag"))
412 return cgit_tag_link(name, title, class, ctx->qry.head, 426 return cgit_tag_link(name, title, class, ctx->qry.head,
413 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); 427 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL);
414 else if (!strcmp(ctx->qry.page, "tree")) 428 else if (!strcmp(ctx->qry.page, "tree"))
415 return cgit_tree_link(name, title, class, ctx->qry.head, 429 return cgit_tree_link(name, title, class, ctx->qry.head,
416 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 430 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
417 ctx->qry.path); 431 ctx->qry.path);
418 else if (!strcmp(ctx->qry.page, "plain")) 432 else if (!strcmp(ctx->qry.page, "plain"))
419 return cgit_plain_link(name, title, class, ctx->qry.head, 433 return cgit_plain_link(name, title, class, ctx->qry.head,
420 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 434 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
421 ctx->qry.path); 435 ctx->qry.path);
422 else if (!strcmp(ctx->qry.page, "log")) 436 else if (!strcmp(ctx->qry.page, "log"))
423 return cgit_log_link(name, title, class, ctx->qry.head, 437 return cgit_log_link(name, title, class, ctx->qry.head,
424 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 438 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
425 ctx->qry.path, ctx->qry.ofs, 439 ctx->qry.path, ctx->qry.ofs,
426 ctx->qry.grep, ctx->qry.search, 440 ctx->qry.grep, ctx->qry.search,
427 ctx->qry.showmsg); 441 ctx->qry.showmsg);
428 else if (!strcmp(ctx->qry.page, "commit")) 442 else if (!strcmp(ctx->qry.page, "commit"))
429 return cgit_commit_link(name, title, class, ctx->qry.head, 443 return cgit_commit_link(name, title, class, ctx->qry.head,
430 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 444 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
431 ctx->qry.path, 0); 445 ctx->qry.path, 0);
432 else if (!strcmp(ctx->qry.page, "patch")) 446 else if (!strcmp(ctx->qry.page, "patch"))
433 return cgit_patch_link(name, title, class, ctx->qry.head, 447 return cgit_patch_link(name, title, class, ctx->qry.head,
434 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 448 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
435 ctx->qry.path); 449 ctx->qry.path);
436 else if (!strcmp(ctx->qry.page, "refs")) 450 else if (!strcmp(ctx->qry.page, "refs"))
437 return cgit_refs_link(name, title, class, ctx->qry.head, 451 return cgit_refs_link(name, title, class, ctx->qry.head,
438 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 452 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
439 ctx->qry.path); 453 ctx->qry.path);
440 else if (!strcmp(ctx->qry.page, "snapshot")) 454 else if (!strcmp(ctx->qry.page, "snapshot"))
441 return cgit_snapshot_link(name, title, class, ctx->qry.head, 455 return cgit_snapshot_link(name, title, class, ctx->qry.head,
442 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 456 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
443 ctx->qry.path); 457 ctx->qry.path);
444 else if (!strcmp(ctx->qry.page, "diff")) 458 else if (!strcmp(ctx->qry.page, "diff"))
445 return cgit_diff_link(name, title, class, ctx->qry.head, 459 return cgit_diff_link(name, title, class, ctx->qry.head,
446 ctx->qry.sha1, ctx->qry.sha2, 460 ctx->qry.sha1, ctx->qry.sha2,
447 ctx->qry.path, 0); 461 ctx->qry.path, 0);
448 else if (!strcmp(ctx->qry.page, "stats")) 462 else if (!strcmp(ctx->qry.page, "stats"))
449 return cgit_stats_link(name, title, class, ctx->qry.head, 463 return cgit_stats_link(name, title, class, ctx->qry.head,
450 ctx->qry.path); 464 ctx->qry.path);
451 465
452 /* Don't known how to make link for this page */ 466 /* Don't known how to make link for this page */
453 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); 467 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
454 html("><!-- cgit_self_link() doesn't know how to make link for page '"); 468 html("><!-- cgit_self_link() doesn't know how to make link for page '");
455 html_txt(ctx->qry.page); 469 html_txt(ctx->qry.page);
456 html("' -->"); 470 html("' -->");
457 html_txt(name); 471 html_txt(name);
458 html("</a>"); 472 html("</a>");
459} 473}
460 474
461void cgit_object_link(struct object *obj) 475void cgit_object_link(struct object *obj)
462{ 476{
463 char *page, *shortrev, *fullrev, *name; 477 char *page, *shortrev, *fullrev, *name;
464 478
465 fullrev = sha1_to_hex(obj->sha1); 479 fullrev = sha1_to_hex(obj->sha1);
466 shortrev = xstrdup(fullrev); 480 shortrev = xstrdup(fullrev);
467 shortrev[10] = '\0'; 481 shortrev[10] = '\0';
468 if (obj->type == OBJ_COMMIT) { 482 if (obj->type == OBJ_COMMIT) {
469 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, 483 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
470 ctx.qry.head, fullrev, NULL, 0); 484 ctx.qry.head, fullrev, NULL, 0);
471 return; 485 return;
472 } else if (obj->type == OBJ_TREE) 486 } else if (obj->type == OBJ_TREE)
473 page = "tree"; 487 page = "tree";
474 else if (obj->type == OBJ_TAG) 488 else if (obj->type == OBJ_TAG)
475 page = "tag"; 489 page = "tag";
476 else 490 else
477 page = "blob"; 491 page = "blob";
478 name = fmt("%s %s...", typename(obj->type), shortrev); 492 name = fmt("%s %s...", typename(obj->type), shortrev);
479 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 493 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
480} 494}
481 495
482void cgit_print_date(time_t secs, const char *format, int local_time) 496void cgit_print_date(time_t secs, const char *format, int local_time)
483{ 497{
484 char buf[64]; 498 char buf[64];
485 struct tm *time; 499 struct tm *time;
486 500
487 if (!secs) 501 if (!secs)
488 return; 502 return;
489 if(local_time) 503 if(local_time)
490 time = localtime(&secs); 504 time = localtime(&secs);
491 else 505 else
492 time = gmtime(&secs); 506 time = gmtime(&secs);
493 strftime(buf, sizeof(buf)-1, format, time); 507 strftime(buf, sizeof(buf)-1, format, time);
494 html_txt(buf); 508 html_txt(buf);
495} 509}
496 510
497void cgit_print_age(time_t t, time_t max_relative, const char *format) 511void cgit_print_age(time_t t, time_t max_relative, const char *format)
498{ 512{
499 time_t now, secs; 513 time_t now, secs;
500 514
501 if (!t) 515 if (!t)
502 return; 516 return;
503 time(&now); 517 time(&now);
504 secs = now - t; 518 secs = now - t;
505 519
506 if (secs > max_relative && max_relative >= 0) { 520 if (secs > max_relative && max_relative >= 0) {
507 cgit_print_date(t, format, ctx.cfg.local_time); 521 cgit_print_date(t, format, ctx.cfg.local_time);
508 return; 522 return;
509 } 523 }
510 524
511 if (secs < TM_HOUR * 2) { 525 if (secs < TM_HOUR * 2) {
512 htmlf("<span class='age-mins'>%.0f min.</span>", 526 htmlf("<span class='age-mins'>%.0f min.</span>",