{"thread":{"id":"26652","subject":"[CGit] [PATCH v2 0/6] Communicate the repo name to the filter scripts","startedAt":"2011-03-04T00:31:29Z","lastAt":"2011-03-04T00:31:35Z","messageCount":7,"participants":["Ferry Huberts"],"isPatch":true,"patchVersion":2,"patchTotal":6},"messages":[{"id":"162744","messageId":"1299198695-23215-1-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":null,"subject":"[CGit] [PATCH v2 0/6] Communicate the repo name to the filter scripts","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:29Z","receivedAt":"2011-03-04T00:31:29Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nChanges compared to v1:\n- Rewritten to communicate the repo configuration via environment variables\n\n\nThis patch series fixes two bugs, does a cleanup and communicates the repo\nconfiguration to the filter scripts.\n\nI have a server setup in which each repo has a trac instance and\nfor the commit filter I really need to know with which repo I'm\ndealing in order to be able to resolve the #123 ticket numbers\ninto hyperlinks into the correct trac instance.\n\nPatch 0001 fixes a memory leak and can be applied regardless of the other\n           patches.\nPatch 0002 makes sure that all arguments for the filter are correctly\n           initialised so that the argv[] list is always terminated with a NULL\n           pointer, which is currently not the case for the source filter.\nPatch 0003 does a cleanup by introducing an enum for the filter type so that\n           the number of extra arguments can be determined in a single place.\n\nThe other patches implement my desired functionality.\n\n\nFerry Huberts (6):\n  source_filter: fix a memory leak\n  new_filter: correctly initialise all arguments for a new filter\n  new_filter: determine extra_args from filter type\n  cgit_open_filter: also take the repo as a parameter\n  cgit_open_filter: hand down repo configuration to script\n  filters: document environment variables in filter scripts\n\n cgit.c                         |   34 +++++++++---\n cgit.h                         |    6 ++-\n filters/commit-links.sh        |   11 ++++\n filters/syntax-highlighting.sh |   11 ++++\n shared.c                       |  110 +++++++++++++++++++++++++++++++++++++++-\n ui-commit.c                    |    6 +-\n ui-repolist.c                  |    2 +-\n ui-snapshot.c                  |    2 +-\n ui-summary.c                   |    2 +-\n ui-tree.c                      |    4 +-\n 10 files changed, 169 insertions(+), 19 deletions(-)\n\n-- \n1.7.4\n"},{"id":"162745","messageId":"1299198695-23215-2-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 1/6] source_filter: fix a memory leak","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:30Z","receivedAt":"2011-03-04T00:31:30Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n ui-tree.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/ui-tree.c b/ui-tree.c\nindex 0b1b531..442b6be 100644\n--- a/ui-tree.c\n+++ b/ui-tree.c\n@@ -48,6 +48,8 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)\n \t\tcgit_open_filter(ctx.repo->source_filter);\n \t\thtml_raw(buf, size);\n \t\tcgit_close_filter(ctx.repo->source_filter);\n+\t\tfree(ctx.repo->source_filter->argv[1]);\n+\t\tctx.repo->source_filter->argv[1] = NULL;\n \t\thtml(\"</code></pre></td></tr></table>\\n\");\n \t\treturn;\n \t}\n-- \n1.7.4\n"},{"id":"162747","messageId":"1299198695-23215-3-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 2/6] new_filter: correctly initialise all arguments for a new filter","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:31Z","receivedAt":"2011-03-04T00:31:31Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n cgit.c |    7 +++++--\n 1 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/cgit.c b/cgit.c\nindex 412fbf0..4440feb 100644\n--- a/cgit.c\n+++ b/cgit.c\n@@ -28,6 +28,7 @@ void add_mimetype(const char *name, const char *value)\n \n struct cgit_filter *new_filter(const char *cmd, int extra_args)\n {\n+\tint i = 0;\n \tstruct cgit_filter *f;\n \n \tif (!cmd || !cmd[0])\n@@ -36,8 +37,10 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args)\n \tf = xmalloc(sizeof(struct cgit_filter));\n \tf->cmd = xstrdup(cmd);\n \tf->argv = xmalloc((2 + extra_args) * sizeof(char *));\n-\tf->argv[0] = f->cmd;\n-\tf->argv[1] = NULL;\n+\tf->argv[i++] = f->cmd;\n+\twhile (i < (2 + extra_args)) {\n+\t  f->argv[i++] = NULL;\n+\t}\n \treturn f;\n }\n \n-- \n1.7.4\n"},{"id":"162746","messageId":"1299198695-23215-4-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 3/6] new_filter: determine extra_args from filter type","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:32Z","receivedAt":"2011-03-04T00:31:32Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n cgit.c |   27 ++++++++++++++++++++-------\n cgit.h |    4 ++++\n 2 files changed, 24 insertions(+), 7 deletions(-)\n\ndiff --git a/cgit.c b/cgit.c\nindex 4440feb..5874034 100644\n--- a/cgit.c\n+++ b/cgit.c\n@@ -26,14 +26,27 @@ void add_mimetype(const char *name, const char *value)\n \titem->util = xstrdup(value);\n }\n \n-struct cgit_filter *new_filter(const char *cmd, int extra_args)\n+struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)\n {\n \tint i = 0;\n \tstruct cgit_filter *f;\n+\tint extra_args;\n \n \tif (!cmd || !cmd[0])\n \t\treturn NULL;\n \n+\tswitch (filtertype) {\n+\t\tcase SOURCE:\n+\t\t\textra_args = 1;\n+\t\t\tbreak;\n+\n+\t\tcase ABOUT:\n+\t\tcase COMMIT:\n+\t\tdefault:\n+\t\t\textra_args = 0;\n+\t\t\tbreak;\n+\t}\n+\n \tf = xmalloc(sizeof(struct cgit_filter));\n \tf->cmd = xstrdup(cmd);\n \tf->argv = xmalloc((2 + extra_args) * sizeof(char *));\n@@ -78,11 +91,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)\n \t\trepo->readme = xstrdup(value);\n \t} else if (ctx.cfg.enable_filter_overrides) {\n \t\tif (!strcmp(name, \"about-filter\"))\n-\t\t\trepo->about_filter = new_filter(value, 0);\n+\t\t\trepo->about_filter = new_filter(value, ABOUT);\n \t\telse if (!strcmp(name, \"commit-filter\"))\n-\t\t\trepo->commit_filter = new_filter(value, 0);\n+\t\t\trepo->commit_filter = new_filter(value, COMMIT);\n \t\telse if (!strcmp(name, \"source-filter\"))\n-\t\t\trepo->source_filter = new_filter(value, 1);\n+\t\t\trepo->source_filter = new_filter(value, SOURCE);\n \t}\n }\n \n@@ -171,9 +184,9 @@ void config_cb(const char *name, const char *value)\n \telse if (!strcmp(name, \"cache-dynamic-ttl\"))\n \t\tctx.cfg.cache_dynamic_ttl = atoi(value);\n \telse if (!strcmp(name, \"about-filter\"))\n-\t\tctx.cfg.about_filter = new_filter(value, 0);\n+\t\tctx.cfg.about_filter = new_filter(value, ABOUT);\n \telse if (!strcmp(name, \"commit-filter\"))\n-\t\tctx.cfg.commit_filter = new_filter(value, 0);\n+\t\tctx.cfg.commit_filter = new_filter(value, COMMIT);\n \telse if (!strcmp(name, \"embedded\"))\n \t\tctx.cfg.embedded = atoi(value);\n \telse if (!strcmp(name, \"max-atom-items\"))\n@@ -201,7 +214,7 @@ void config_cb(const char *name, const char *value)\n \telse if (!strcmp(name, \"section-from-path\"))\n \t\tctx.cfg.section_from_path = atoi(value);\n \telse if (!strcmp(name, \"source-filter\"))\n-\t\tctx.cfg.source_filter = new_filter(value, 1);\n+\t\tctx.cfg.source_filter = new_filter(value, SOURCE);\n \telse if (!strcmp(name, \"summary-log\"))\n \t\tctx.cfg.summary_log = atoi(value);\n \telse if (!strcmp(name, \"summary-branches\"))\ndiff --git a/cgit.h b/cgit.h\nindex f5f68ac..be29d6e 100644\n--- a/cgit.h\n+++ b/cgit.h\n@@ -50,6 +50,10 @@ typedef void (*configfn)(const char *name, const char *value);\n typedef void (*filepair_fn)(struct diff_filepair *pair);\n typedef void (*linediff_fn)(char *line, int len);\n \n+typedef enum {\n+\tABOUT, COMMIT, SOURCE\n+} filter_type;\n+\n struct cgit_filter {\n \tchar *cmd;\n \tchar **argv;\n-- \n1.7.4\n"},{"id":"162749","messageId":"1299198695-23215-5-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 4/6] cgit_open_filter: also take the repo as a parameter","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:33Z","receivedAt":"2011-03-04T00:31:33Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nTo prepare for handing repo configuration to the\nscript that is executed.\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n cgit.h        |    2 +-\n shared.c      |    2 +-\n ui-commit.c   |    6 +++---\n ui-repolist.c |    2 +-\n ui-snapshot.c |    2 +-\n ui-summary.c  |    2 +-\n ui-tree.c     |    2 +-\n 7 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/cgit.h b/cgit.h\nindex be29d6e..2551cb7 100644\n--- a/cgit.h\n+++ b/cgit.h\n@@ -312,7 +312,7 @@ extern const char *cgit_repobasename(const char *reponame);\n \n extern int cgit_parse_snapshots_mask(const char *str);\n \n-extern int cgit_open_filter(struct cgit_filter *filter);\n+extern int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo);\n extern int cgit_close_filter(struct cgit_filter *filter);\n \n extern int readfile(const char *path, char **buf, size_t *size);\ndiff --git a/shared.c b/shared.c\nindex 765cd27..49128ad 100644\n--- a/shared.c\n+++ b/shared.c\n@@ -375,7 +375,7 @@ int cgit_parse_snapshots_mask(const char *str)\n \treturn rv;\n }\n \n-int cgit_open_filter(struct cgit_filter *filter)\n+int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)\n {\n \n \tfilter->old_stdout = chk_positive(dup(STDOUT_FILENO),\ndiff --git a/ui-commit.c b/ui-commit.c\nindex 2b4f677..2da9fcf 100644\n--- a/ui-commit.c\n+++ b/ui-commit.c\n@@ -110,7 +110,7 @@ void cgit_print_commit(char *hex, const char *prefix)\n \thtml(\"</table>\\n\");\n \thtml(\"<div class='commit-subject'>\");\n \tif (ctx.repo->commit_filter)\n-\t\tcgit_open_filter(ctx.repo->commit_filter);\n+\t\tcgit_open_filter(ctx.repo->commit_filter, ctx.repo);\n \thtml_txt(info->subject);\n \tif (ctx.repo->commit_filter)\n \t\tcgit_close_filter(ctx.repo->commit_filter);\n@@ -118,7 +118,7 @@ void cgit_print_commit(char *hex, const char *prefix)\n \thtml(\"</div>\");\n \thtml(\"<div class='commit-msg'>\");\n \tif (ctx.repo->commit_filter)\n-\t\tcgit_open_filter(ctx.repo->commit_filter);\n+\t\tcgit_open_filter(ctx.repo->commit_filter, ctx.repo);\n \thtml_txt(info->msg);\n \tif (ctx.repo->commit_filter)\n \t\tcgit_close_filter(ctx.repo->commit_filter);\n@@ -127,7 +127,7 @@ void cgit_print_commit(char *hex, const char *prefix)\n \t\thtml(\"<div class='notes-header'>Notes</div>\");\n \t\thtml(\"<div class='notes'>\");\n \t\tif (ctx.repo->commit_filter)\n-\t\t\tcgit_open_filter(ctx.repo->commit_filter);\n+\t\t\tcgit_open_filter(ctx.repo->commit_filter, ctx.repo);\n \t\thtml_txt(notes.buf);\n \t\tif (ctx.repo->commit_filter)\n \t\t\tcgit_close_filter(ctx.repo->commit_filter);\ndiff --git a/ui-repolist.c b/ui-repolist.c\nindex 2c98668..05b4548 100644\n--- a/ui-repolist.c\n+++ b/ui-repolist.c\n@@ -291,7 +291,7 @@ void cgit_print_site_readme()\n \tif (!ctx.cfg.root_readme)\n \t\treturn;\n \tif (ctx.cfg.about_filter)\n-\t\tcgit_open_filter(ctx.cfg.about_filter);\n+\t\tcgit_open_filter(ctx.cfg.about_filter, NULL);\n \thtml_include(ctx.cfg.root_readme);\n \tif (ctx.cfg.about_filter)\n \t\tcgit_close_filter(ctx.cfg.about_filter);\ndiff --git a/ui-snapshot.c b/ui-snapshot.c\nindex 6e3412c..067082c 100644\n--- a/ui-snapshot.c\n+++ b/ui-snapshot.c\n@@ -19,7 +19,7 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f\n \tf.argv = malloc(2 * sizeof(char *));\n \tf.argv[0] = f.cmd;\n \tf.argv[1] = NULL;\n-\tcgit_open_filter(&f);\n+\tcgit_open_filter(&f, NULL);\n \trv = write_tar_archive(args);\n \tcgit_close_filter(&f);\n \treturn rv;\ndiff --git a/ui-summary.c b/ui-summary.c\nindex b203bcc..1b1d93b 100644\n--- a/ui-summary.c\n+++ b/ui-summary.c\n@@ -113,7 +113,7 @@ void cgit_print_repo_readme(char *path)\n \t */\n \thtml(\"<div id='summary'>\");\n \tif (ctx.repo->about_filter)\n-\t\tcgit_open_filter(ctx.repo->about_filter);\n+\t\tcgit_open_filter(ctx.repo->about_filter, ctx.repo);\n \tif (ref)\n \t\tcgit_print_file(tmp, ref);\n \telse\ndiff --git a/ui-tree.c b/ui-tree.c\nindex 442b6be..2d8d2f3 100644\n--- a/ui-tree.c\n+++ b/ui-tree.c\n@@ -45,7 +45,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)\n \tif (ctx.repo->source_filter) {\n \t\thtml(\"<td class='lines'><pre><code>\");\n \t\tctx.repo->source_filter->argv[1] = xstrdup(name);\n-\t\tcgit_open_filter(ctx.repo->source_filter);\n+\t\tcgit_open_filter(ctx.repo->source_filter, ctx.repo);\n \t\thtml_raw(buf, size);\n \t\tcgit_close_filter(ctx.repo->source_filter);\n \t\tfree(ctx.repo->source_filter->argv[1]);\n-- \n1.7.4\n"},{"id":"162750","messageId":"1299198695-23215-6-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 5/6] cgit_open_filter: hand down repo configuration to script","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:34Z","receivedAt":"2011-03-04T00:31:34Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n shared.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 107 insertions(+), 1 deletions(-)\n\ndiff --git a/shared.c b/shared.c\nindex 49128ad..5f09a63 100644\n--- a/shared.c\n+++ b/shared.c\n@@ -7,6 +7,8 @@\n  */\n \n #include \"cgit.h\"\n+#include <stdio.h>\n+#include <linux/limits.h>\n \n struct cgit_repolist cgit_repolist;\n struct cgit_context ctx;\n@@ -375,6 +377,100 @@ int cgit_parse_snapshots_mask(const char *str)\n \treturn rv;\n }\n \n+#define ENV_VARS\t\t\t7\n+#define ENV_SIZE_PER_VAR\t(PATH_MAX + 64)\n+#define ENV_SIZE\t\t\t(ENV_VARS * ENV_SIZE_PER_VAR)\n+\n+typedef struct {\n+\tchar * vars[ENV_VARS + 1];\n+\tchar buffer[ENV_SIZE];\n+} env_struct;\n+\n+static env_struct * prepare_env(struct cgit_repo * repo) {\n+\tlong buffer_space = sizeof(env_struct);\n+\tenv_struct * env = malloc(buffer_space);\n+\tint var_index = 0;\n+\tchar * buffer_var_index;\n+\tunsigned int chars_printed;\n+\n+\tif (!env)\n+\t\treturn NULL;\n+\n+\t/**\n+\t * CGIT_REPO_URL\n+\t * CGIT_REPO_NAME\n+\t * CGIT_REPO_PATH\n+\t * CGIT_REPO_OWNER\n+\t * CGIT_REPO_DEFBRANCH\n+\t * CGIT_REPO_SECTION\n+\t * CGIT_REPO_CLONE_URL\n+\t */\n+\n+\tbuffer_var_index = &env->buffer[0];\n+\n+\twhile (var_index < ENV_VARS) {\n+\t\tchars_printed = 0;\n+\t\tswitch (var_index) {\n+\t\tcase 0:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_URL=%s\", (repo->url) ? repo->url : \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 1:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_NAME=%s\", (repo->name) ? repo->name : \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 2:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_PATH=%s\", (repo->path) ? repo->path : \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 3:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_OWNER=%s\", (repo->owner) ? repo->owner : \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 4:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_DEFBRANCH=%s\",\n+\t\t\t\t\t(repo->defbranch) ? repo->defbranch : \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 5:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_SECTION=%s\", (repo->section) ? repo->section\n+\t\t\t\t\t\t\t: \"\");\n+\t\t\tbreak;\n+\n+\t\tcase 6:\n+\t\t\tchars_printed = snprintf(buffer_var_index, buffer_space,\n+\t\t\t\t\t\"CGIT_REPO_CLONE_URL=%s\",\n+\t\t\t\t\t(repo->clone_url) ? repo->clone_url : \"\");\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (chars_printed > buffer_space) {\n+\t\t\tfree(env);\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\tenv->vars[var_index] = buffer_var_index;\n+\t\tbuffer_var_index[chars_printed] = '\\0';\n+\t\tbuffer_var_index += chars_printed + 1;\n+\t\tbuffer_space -= chars_printed;\n+\n+\t\tvar_index++;\n+\t}\n+\tenv->vars[var_index] = NULL;\n+\n+\treturn env;\n+}\n+\n+\n int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)\n {\n \n@@ -383,10 +479,20 @@ int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)\n \tchk_zero(pipe(filter->pipe_fh), \"Unable to create pipe to subprocess\");\n \tfilter->pid = chk_non_negative(fork(), \"Unable to create subprocess\");\n \tif (filter->pid == 0) {\n+\t\tenv_struct * env = NULL;\n+\n \t\tclose(filter->pipe_fh[1]);\n \t\tchk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),\n \t\t\t\"Unable to use pipe as STDIN\");\n-\t\texecvp(filter->cmd, filter->argv);\n+\n+\t\tif (repo)\n+\t\t\tenv = prepare_env(repo);\n+\n+\t\texecve(filter->cmd, filter->argv, (env) ? &env->vars[0] : NULL);\n+\n+\t\tif (env)\n+\t\t\tfree(env);\n+\n \t\tdie(\"Unable to exec subprocess %s: %s (%d)\", filter->cmd,\n \t\t\tstrerror(errno), errno);\n \t}\n-- \n1.7.4\n"},{"id":"162748","messageId":"1299198695-23215-7-git-send-email-mailings@hupie.com","threadId":"26652","inReplyTo":"1299198695-23215-1-git-send-email-mailings@hupie.com","subject":"[CGit] [PATCH v2 6/6] filters: document environment variables in filter scripts","fromName":"Ferry Huberts","fromEmail":"mailings@hupie.com","sentAt":"2011-03-04T00:31:35Z","receivedAt":"2011-03-04T00:31:35Z","isPatch":true,"sender":{"key":"mailings@hupie.com","avatar":"https://gravatar.com/avatar/ca355376c0713475e17ae413a49f6b98bcbc54cd8364cab7113c53107fb839bb?d=mp&s=160"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n filters/commit-links.sh        |   11 +++++++++++\n filters/syntax-highlighting.sh |   11 +++++++++++\n 2 files changed, 22 insertions(+), 0 deletions(-)\n\ndiff --git a/filters/commit-links.sh b/filters/commit-links.sh\nindex 110c609..d2cd2b3 100755\n--- a/filters/commit-links.sh\n+++ b/filters/commit-links.sh\n@@ -3,6 +3,17 @@\n #\n # To use this script, refer to this file with either the commit-filter or the\n # repo.commit-filter options in cgitrc.\n+#\n+# The following environment variables can be used to retrieve the configuration\n+# of the repository for which this script is called:\n+# CGIT_REPO_URL        ( = repo.url       setting )\n+# CGIT_REPO_NAME       ( = repo.name      setting )\n+# CGIT_REPO_PATH       ( = repo.path      setting )\n+# CGIT_REPO_OWNER      ( = repo.owner     setting )\n+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )\n+# CGIT_REPO_SECTION    ( = section        setting )\n+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )\n+#\n \n # This expression generates links to commits referenced by their SHA1.\n regex=$regex'\ndiff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh\nindex 6b1c576..6283ce9 100755\n--- a/filters/syntax-highlighting.sh\n+++ b/filters/syntax-highlighting.sh\n@@ -23,6 +23,17 @@\n # table.blob .kwb  { color:#830000; }\n # table.blob .kwc  { color:#000000; font-weight:bold; }\n # table.blob .kwd  { color:#010181; }\n+#\n+# The following environment variables can be used to retrieve the configuration\n+# of the repository for which this script is called:\n+# CGIT_REPO_URL        ( = repo.url       setting )\n+# CGIT_REPO_NAME       ( = repo.name      setting )\n+# CGIT_REPO_PATH       ( = repo.path      setting )\n+# CGIT_REPO_OWNER      ( = repo.owner     setting )\n+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )\n+# CGIT_REPO_SECTION    ( = section        setting )\n+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )\n+#\n \n # store filename and extension in local vars\n BASENAME=\"$1\"\n-- \n1.7.4\n"}]}