diff --git a/cgit.c b/cgit.c index 6be3754..dd40893 100644 --- a/cgit.c +++ b/cgit.c @@ -463,6 +463,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx) cgit_print_docend(); return 1; } + cgit_prepare_repo_env(ctx->repo); return 0; } diff --git a/cgit.h b/cgit.h index caa9d8e..df7ee5d 100644 --- a/cgit.h +++ b/cgit.h @@ -319,9 +319,11 @@ extern const char *cgit_repobasename(const char *reponame); extern int cgit_parse_snapshots_mask(const char *str); -extern int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo); +extern int cgit_open_filter(struct cgit_filter *filter); extern int cgit_close_filter(struct cgit_filter *filter); +extern void cgit_prepare_repo_env(struct cgit_repo * repo); + extern int readfile(const char *path, char **buf, size_t *size); extern char *expand_macros(const char *txt); diff --git a/shared.c b/shared.c index be2ae59..4adeaa8 100644 --- a/shared.c +++ b/shared.c @@ -374,7 +374,8 @@ typedef struct { char * value; } cgit_env_var; -static void prepare_env(struct cgit_repo * repo) { +void cgit_prepare_repo_env(struct cgit_repo * repo) +{ cgit_env_var env_vars[] = { { .name = "CGIT_REPO_URL", .value = repo->url }, { .name = "CGIT_REPO_NAME", .value = repo->name }, @@ -395,7 +396,7 @@ static void prepare_env(struct cgit_repo * repo) { fprintf(stderr, warn, p->name, p->value); } -int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo) +int cgit_open_filter(struct cgit_filter *filter) { filter->old_stdout = chk_positive(dup(STDOUT_FILENO), @@ -406,8 +407,6 @@ int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo) close(filter->pipe_fh[1]); chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), "Unable to use pipe as STDIN"); - if (repo) - prepare_env(repo); execvp(filter->cmd, filter->argv); die("Unable to exec subprocess %s: %s (%d)", filter->cmd, strerror(errno), errno); diff --git a/ui-commit.c b/ui-commit.c index a69dec6..536a8e8 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -106,7 +106,7 @@ void cgit_print_commit(char *hex, const char *prefix) html("\n"); html("
");
ctx.repo->source_filter->argv[1] = xstrdup(name);
- cgit_open_filter(ctx.repo->source_filter, ctx.repo);
+ cgit_open_filter(ctx.repo->source_filter);
html_raw(buf, size);
cgit_close_filter(ctx.repo->source_filter);
free(ctx.repo->source_filter->argv[1]);