From 3ec6b309505dc5f7ba14abe8861b02da34a9df0b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 6 Jun 2011 19:29:58 +0000 Subject: cgit.c: always setup cgit repo environment variables When cgit learned to setup environment variables for certain repo settings before invoking a filter process, the setup occurred inside cgit_open_filter(). This patch moves the setup out of cgit_open_filter() and into prepare_repo_cmd() to prepare for additional uses of these variables. Reviewed-by: Ferry Huberts Signed-off-by: Lars Hjemli --- cgit.c | 1 + cgit.h | 4 +++- shared.c | 7 +++---- ui-commit.c | 6 +++--- ui-repolist.c | 2 +- ui-snapshot.c | 2 +- ui-summary.c | 2 +- ui-tree.c | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) 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("
"); if (ctx.repo->commit_filter) - cgit_open_filter(ctx.repo->commit_filter, ctx.repo); + cgit_open_filter(ctx.repo->commit_filter); html_txt(info->subject); if (ctx.repo->commit_filter) cgit_close_filter(ctx.repo->commit_filter); @@ -114,7 +114,7 @@ void cgit_print_commit(char *hex, const char *prefix) html("
"); html("
"); if (ctx.repo->commit_filter) - cgit_open_filter(ctx.repo->commit_filter, ctx.repo); + cgit_open_filter(ctx.repo->commit_filter); html_txt(info->msg); if (ctx.repo->commit_filter) cgit_close_filter(ctx.repo->commit_filter); @@ -123,7 +123,7 @@ void cgit_print_commit(char *hex, const char *prefix) html("
Notes
"); html("
"); if (ctx.repo->commit_filter) - cgit_open_filter(ctx.repo->commit_filter, ctx.repo); + cgit_open_filter(ctx.repo->commit_filter); html_txt(notes.buf); if (ctx.repo->commit_filter) cgit_close_filter(ctx.repo->commit_filter); diff --git a/ui-repolist.c b/ui-repolist.c index dce2eac..25c36ce 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -300,7 +300,7 @@ void cgit_print_site_readme() if (!ctx.cfg.root_readme) return; if (ctx.cfg.about_filter) - cgit_open_filter(ctx.cfg.about_filter, NULL); + cgit_open_filter(ctx.cfg.about_filter); html_include(ctx.cfg.root_readme); if (ctx.cfg.about_filter) cgit_close_filter(ctx.cfg.about_filter); diff --git a/ui-snapshot.c b/ui-snapshot.c index 126779d..07cc944 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -19,7 +19,7 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f f.argv = malloc(2 * sizeof(char *)); f.argv[0] = f.cmd; f.argv[1] = NULL; - cgit_open_filter(&f, NULL); + cgit_open_filter(&f); rv = write_tar_archive(args); cgit_close_filter(&f); return rv; diff --git a/ui-summary.c b/ui-summary.c index 1e9a1b6..5be2545 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -113,7 +113,7 @@ void cgit_print_repo_readme(char *path) */ html("
"); if (ctx.repo->about_filter) - cgit_open_filter(ctx.repo->about_filter, ctx.repo); + cgit_open_filter(ctx.repo->about_filter); if (ref) cgit_print_file(tmp, ref); else diff --git a/ui-tree.c b/ui-tree.c index 2d8d2f3..442b6be 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -45,7 +45,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size) if (ctx.repo->source_filter) { 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]);
-- 
cgit v1.2.3-54-g00ecf

ions'>+2
2008-01-20 r686@Devoty:  necoro | 2008-01-20 04:50:27 +0100Necoro1-2/+3
2008-01-20 r682@Devoty:  necoro | 2008-01-20 03:23:02 +0100Necoro2-5/+5
2008-01-20 r680@Devoty:  necoro | 2008-01-20 02:53:30 +0100Necoro7-55/+100
2008-01-19 r675@Devoty:  necoro | 2008-01-19 23:33:38 +0100Necoro2-366/+396
2008-01-18 r669@Devoty:  necoro | 2008-01-18 22:49:33 +0100Necoro1-6/+6
2008-01-18 r664@Devoty:  necoro | 2008-01-18 21:40:29 +0100Necoro5-26/+181
2008-01-18 r661@Devoty:  necoro | 2008-01-18 14:16:59 +0100Necoro8-211/+293
2008-01-18 r655@Devoty:  necoro | 2008-01-18 03:04:53 +0100Necoro1-1/+1
2008-01-18 r651@Devoty:  necoro | 2008-01-18 02:41:51 +0100Necoro3-393/+513
2008-01-18 r643@Devoty:  necoro | 2008-01-16 18:55:49 +0100Necoro14-249/+525
2008-01-14 r634@Devoty:  necoro | 2008-01-14 23:48:24 +0100Necoro3-1/+4
2008-01-14 r632@Devoty:  necoro | 2008-01-14 23:44:52 +0100Necoro3-175/+181
2008-01-14(no commit message)Necoro10-758/+1014
2008-01-14 r621@Devoty:  necoro | 2008-01-14 20:21:40 +0100Necoro2-21/+61
2008-01-14 r618@Devoty:  necoro | 2008-01-14 20:19:05 +0100Necoro2-35/+57
2008-01-14 r617@Devoty:  necoro | 2008-01-14 19:12:59 +0100Necoro2-10/+10
2008-01-14 r609@Devoty:  necoro | 2008-01-14 17:04:38 +0100Necoro9-394/+477
2008-01-14 r605@Devoty:  necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129
2008-01-14 r603@Devoty:  necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38
2008-01-11 r598@Devoty:  necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50
2008-01-11 r597@Devoty:  necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3
2008-01-10 r595@Devoty:  necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3
2008-01-09 r586@Devoty:  necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1
2007-12-06 r577@Devoty:  necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1
2007-12-06 r572@Devoty:  necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1
2007-11-27 r570@Devoty:  necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108