diff options
Diffstat (limited to 'shared.c')
-rw-r--r-- | shared.c | 80 |
1 files changed, 80 insertions, 0 deletions
@@ -59,6 +59,7 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
60 | 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; | 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; |
63 | ret->module_link = ctx.cfg.module_link; | 64 | ret->module_link = ctx.cfg.module_link; |
64 | ret->readme = NULL; | 65 | ret->readme = NULL; |
@@ -279,6 +280,10 @@ int cgit_diff_files(const unsigned char *old_sha1, | |||
279 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || | 280 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || |
280 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { | 281 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { |
281 | *binary = 1; | 282 | *binary = 1; |
283 | if (file1.size) | ||
284 | free(file1.ptr); | ||
285 | if (file2.size) | ||
286 | free(file2.ptr); | ||
282 | return 0; | 287 | return 0; |
283 | } | 288 | } |
284 | 289 | ||
@@ -293,6 +298,10 @@ int cgit_diff_files(const unsigned char *old_sha1, | |||
293 | emit_cb.outf = filediff_cb; | 298 | emit_cb.outf = filediff_cb; |
294 | emit_cb.priv = fn; | 299 | emit_cb.priv = fn; |
295 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 300 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
301 | if (file1.size) | ||
302 | free(file1.ptr); | ||
303 | if (file2.size) | ||
304 | free(file2.ptr); | ||
296 | return 0; | 305 | return 0; |
297 | } | 306 | } |
298 | 307 | ||
@@ -428,3 +437,74 @@ int readfile(const char *path, char **buf, size_t *size) | |||
428 | close(fd); | 437 | close(fd); |
429 | return (*size == st.st_size ? 0 : e); | 438 | return (*size == st.st_size ? 0 : e); |
430 | } | 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 | } | ||