summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 67eb67b..800c06a 100644
--- a/shared.c
+++ b/shared.c
@@ -434,48 +434,75 @@ int cgit_diff_files(const unsigned char *old_sha1,
434 emit_params.ctxlen = 3; 434 emit_params.ctxlen = 3;
435 emit_params.flags = XDL_EMIT_FUNCNAMES; 435 emit_params.flags = XDL_EMIT_FUNCNAMES;
436 emit_params.find_func = NULL; 436 emit_params.find_func = NULL;
437 emit_cb.outf = filediff_cb; 437 emit_cb.outf = filediff_cb;
438 emit_cb.priv = fn; 438 emit_cb.priv = fn;
439 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); 439 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
440 return 0; 440 return 0;
441} 441}
442 442
443void cgit_diff_tree(const unsigned char *old_sha1, 443void cgit_diff_tree(const unsigned char *old_sha1,
444 const unsigned char *new_sha1, 444 const unsigned char *new_sha1,
445 filepair_fn fn, const char *prefix) 445 filepair_fn fn, const char *prefix)
446{ 446{
447 struct diff_options opt; 447 struct diff_options opt;
448 int ret; 448 int ret;
449 int prefixlen; 449 int prefixlen;
450 450
451 diff_setup(&opt); 451 diff_setup(&opt);
452 opt.output_format = DIFF_FORMAT_CALLBACK; 452 opt.output_format = DIFF_FORMAT_CALLBACK;
453 opt.detect_rename = 1; 453 opt.detect_rename = 1;
454 opt.rename_limit = ctx.cfg.renamelimit; 454 opt.rename_limit = ctx.cfg.renamelimit;
455 DIFF_OPT_SET(&opt, RECURSIVE); 455 DIFF_OPT_SET(&opt, RECURSIVE);
456 opt.format_callback = cgit_diff_tree_cb; 456 opt.format_callback = cgit_diff_tree_cb;
457 opt.format_callback_data = fn; 457 opt.format_callback_data = fn;
458 if (prefix) { 458 if (prefix) {
459 opt.nr_paths = 1; 459 opt.nr_paths = 1;
460 opt.paths = &prefix; 460 opt.paths = &prefix;
461 prefixlen = strlen(prefix); 461 prefixlen = strlen(prefix);
462 opt.pathlens = &prefixlen; 462 opt.pathlens = &prefixlen;
463 } 463 }
464 diff_setup_done(&opt); 464 diff_setup_done(&opt);
465 465
466 if (old_sha1 && !is_null_sha1(old_sha1)) 466 if (old_sha1 && !is_null_sha1(old_sha1))
467 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); 467 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
468 else 468 else
469 ret = diff_root_tree_sha1(new_sha1, "", &opt); 469 ret = diff_root_tree_sha1(new_sha1, "", &opt);
470 diffcore_std(&opt); 470 diffcore_std(&opt);
471 diff_flush(&opt); 471 diff_flush(&opt);
472} 472}
473 473
474void cgit_diff_commit(struct commit *commit, filepair_fn fn) 474void cgit_diff_commit(struct commit *commit, filepair_fn fn)
475{ 475{
476 unsigned char *old_sha1 = NULL; 476 unsigned char *old_sha1 = NULL;
477 477
478 if (commit->parents) 478 if (commit->parents)
479 old_sha1 = commit->parents->item->object.sha1; 479 old_sha1 = commit->parents->item->object.sha1;
480 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); 480 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
481} 481}
482
483int cgit_parse_snapshots_mask(const char *str)
484{
485 const struct cgit_snapshot_format *f;
486 static const char *delim = " \t,:/|;";
487 int tl, sl, rv = 0;
488
489 /* favor legacy setting */
490 if(atoi(str))
491 return 1;
492 for(;;) {
493 str += strspn(str,delim);
494 tl = strcspn(str,delim);
495 if (!tl)
496 break;
497 for (f = cgit_snapshot_formats; f->suffix; f++) {
498 sl = strlen(f->suffix);
499 if((tl == sl && !strncmp(f->suffix, str, tl)) ||
500 (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
501 rv |= f->bit;
502 break;
503 }
504 }
505 str += tl;
506 }
507 return rv;
508}