|
diff --git a/shared.c b/shared.c index 67eb67b..800c06a 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -386,96 +386,123 @@ int buflen = 0; |
386 | |
386 | |
387 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
387 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
388 | { |
388 | { |
389 | int i; |
389 | int i; |
390 | |
390 | |
391 | for (i = 0; i < nbuf; i++) { |
391 | for (i = 0; i < nbuf; i++) { |
392 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
392 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
393 | /* Incomplete line */ |
393 | /* Incomplete line */ |
394 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
394 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
395 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
395 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
396 | buflen += mb[i].size; |
396 | buflen += mb[i].size; |
397 | continue; |
397 | continue; |
398 | } |
398 | } |
399 | |
399 | |
400 | /* we have a complete line */ |
400 | /* we have a complete line */ |
401 | if (!diffbuf) { |
401 | if (!diffbuf) { |
402 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
402 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
403 | continue; |
403 | continue; |
404 | } |
404 | } |
405 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
405 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
406 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
406 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
407 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
407 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
408 | free(diffbuf); |
408 | free(diffbuf); |
409 | diffbuf = NULL; |
409 | diffbuf = NULL; |
410 | buflen = 0; |
410 | buflen = 0; |
411 | } |
411 | } |
412 | if (diffbuf) { |
412 | if (diffbuf) { |
413 | ((linediff_fn)priv)(diffbuf, buflen); |
413 | ((linediff_fn)priv)(diffbuf, buflen); |
414 | free(diffbuf); |
414 | free(diffbuf); |
415 | diffbuf = NULL; |
415 | diffbuf = NULL; |
416 | buflen = 0; |
416 | buflen = 0; |
417 | } |
417 | } |
418 | return 0; |
418 | return 0; |
419 | } |
419 | } |
420 | |
420 | |
421 | int cgit_diff_files(const unsigned char *old_sha1, |
421 | int cgit_diff_files(const unsigned char *old_sha1, |
422 | const unsigned char *new_sha1, |
422 | const unsigned char *new_sha1, |
423 | linediff_fn fn) |
423 | linediff_fn fn) |
424 | { |
424 | { |
425 | mmfile_t file1, file2; |
425 | mmfile_t file1, file2; |
426 | xpparam_t diff_params; |
426 | xpparam_t diff_params; |
427 | xdemitconf_t emit_params; |
427 | xdemitconf_t emit_params; |
428 | xdemitcb_t emit_cb; |
428 | xdemitcb_t emit_cb; |
429 | |
429 | |
430 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
430 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
431 | return 1; |
431 | return 1; |
432 | |
432 | |
433 | diff_params.flags = XDF_NEED_MINIMAL; |
433 | diff_params.flags = XDF_NEED_MINIMAL; |
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 | |
443 | void cgit_diff_tree(const unsigned char *old_sha1, |
443 | void 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 | |
474 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) |
474 | void 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 | |
| |
483 | int 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 | } |
|