|
diff --git a/shared.c b/shared.c index 6adf2b6..b42c2a2 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -12,3 +12,2 @@ struct cgit_repolist cgit_repolist; |
12 | struct cgit_context ctx; |
12 | struct cgit_context ctx; |
13 | int cgit_cmd; |
| |
14 | |
13 | |
@@ -61,2 +60,4 @@ struct cgit_repo *cgit_add_repo(const char *url) |
61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
| |
61 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
| |
62 | ret->enable_subject_links = ctx.cfg.enable_subject_links; |
62 | ret->max_stats = ctx.cfg.max_stats; |
63 | ret->max_stats = ctx.cfg.max_stats; |
@@ -264,3 +265,4 @@ int cgit_diff_files(const unsigned char *old_sha1, |
264 | const unsigned char *new_sha1, unsigned long *old_size, |
265 | const unsigned char *new_sha1, unsigned long *old_size, |
265 | unsigned long *new_size, int *binary, linediff_fn fn) |
266 | unsigned long *new_size, int *binary, int context, |
| |
267 | int ignorews, linediff_fn fn) |
266 | { |
268 | { |
@@ -291,3 +293,5 @@ int cgit_diff_files(const unsigned char *old_sha1, |
291 | diff_params.flags = XDF_NEED_MINIMAL; |
293 | diff_params.flags = XDF_NEED_MINIMAL; |
292 | emit_params.ctxlen = 3; |
294 | if (ignorews) |
| |
295 | diff_params.flags |= XDF_IGNORE_WHITESPACE; |
| |
296 | emit_params.ctxlen = context > 0 ? context : 3; |
293 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
297 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
@@ -305,3 +309,3 @@ void cgit_diff_tree(const unsigned char *old_sha1, |
305 | const unsigned char *new_sha1, |
309 | const unsigned char *new_sha1, |
306 | filepair_fn fn, const char *prefix) |
310 | filepair_fn fn, const char *prefix, int ignorews) |
307 | { |
311 | { |
@@ -316,2 +320,4 @@ void cgit_diff_tree(const unsigned char *old_sha1, |
316 | DIFF_OPT_SET(&opt, RECURSIVE); |
320 | DIFF_OPT_SET(&opt, RECURSIVE); |
| |
321 | if (ignorews) |
| |
322 | DIFF_XDL_SET(&opt, IGNORE_WHITESPACE); |
317 | opt.format_callback = cgit_diff_tree_cb; |
323 | opt.format_callback = cgit_diff_tree_cb; |
@@ -340,3 +346,4 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn) |
340 | old_sha1 = commit->parents->item->object.sha1; |
346 | old_sha1 = commit->parents->item->object.sha1; |
341 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); |
347 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL, |
| |
348 | ctx.qry.ignorews); |
342 | } |
349 | } |
@@ -432 +439,72 @@ int readfile(const char *path, char **buf, size_t *size) |
432 | } |
439 | } |
| |
440 | |
| |
441 | int is_token_char(char c) |
| |
442 | { |
| |
443 | return isalnum(c) || c == '_'; |
| |
444 | } |
| |
445 | |
| |
446 | /* Replace name with getenv(name), return pointer to zero-terminating char |
| |
447 | */ |
| |
448 | char *expand_macro(char *name, int maxlength) |
| |
449 | { |
| |
450 | char *value; |
| |
451 | int len; |
| |
452 | |
| |
453 | len = 0; |
| |
454 | value = getenv(name); |
| |
455 | if (value) { |
| |
456 | len = strlen(value); |
| |
457 | if (len > maxlength) |
| |
458 | len = maxlength; |
| |
459 | strncpy(name, value, len); |
| |
460 | } |
| |
461 | return name + len; |
| |
462 | } |
| |
463 | |
| |
464 | #define EXPBUFSIZE (1024 * 8) |
| |
465 | |
| |
466 | /* Replace all tokens prefixed by '$' in the specified text with the |
| |
467 | * value of the named environment variable. |
| |
468 | * NB: the return value is a static buffer, i.e. it must be strdup'd |
| |
469 | * by the caller. |
| |
470 | */ |
| |
471 | char *expand_macros(const char *txt) |
| |
472 | { |
| |
473 | static char result[EXPBUFSIZE]; |
| |
474 | char *p, *start; |
| |
475 | int len; |
| |
476 | |
| |
477 | p = result; |
| |
478 | start = NULL; |
| |
479 | while (p < result + EXPBUFSIZE - 1 && txt && *txt) { |
| |
480 | *p = *txt; |
| |
481 | if (start) { |
| |
482 | if (!is_token_char(*txt)) { |
| |
483 | if (p - start > 0) { |
| |
484 | *p = '\0'; |
| |
485 | len = result + EXPBUFSIZE - start - 1; |
| |
486 | p = expand_macro(start, len) - 1; |
| |
487 | } |
| |
488 | start = NULL; |
| |
489 | txt--; |
| |
490 | } |
| |
491 | p++; |
| |
492 | txt++; |
| |
493 | continue; |
| |
494 | } |
| |
495 | if (*txt == '$') { |
| |
496 | start = p; |
| |
497 | txt++; |
| |
498 | continue; |
| |
499 | } |
| |
500 | p++; |
| |
501 | txt++; |
| |
502 | } |
| |
503 | *p = '\0'; |
| |
504 | if (start && p - start > 0) { |
| |
505 | len = result + EXPBUFSIZE - start - 1; |
| |
506 | p = expand_macro(start, len); |
| |
507 | *p = '\0'; |
| |
508 | } |
| |
509 | return result; |
| |
510 | } |
|