Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.zx2c4.com/cgit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/shared.c b/shared.c
index 7ec2e19..be2ae59 100644
--- a/shared.c
+++ b/shared.c
@@ -7,6 +7,8 @@
*/
#include "cgit.h"
+#include <stdio.h>
+#include <linux/limits.h>
struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
@@ -100,23 +102,15 @@ void *cgit_free_commitinfo(struct commitinfo *info)
char *trim_end(const char *str, char c)
{
int len;
- char *s, *t;
if (str == NULL)
return NULL;
- t = (char *)str;
- len = strlen(t);
- while(len > 0 && t[len - 1] == c)
+ len = strlen(str);
+ while(len > 0 && str[len - 1] == c)
len--;
-
if (len == 0)
return NULL;
-
- c = t[len];
- t[len] = '\0';
- s = xstrdup(t);
- t[len] = c;
- return s;
+ return xstrndup(str, len);
}
char *strlpart(char *txt, int maxlen)
@@ -311,7 +305,6 @@ void cgit_diff_tree(const unsigned char *old_sha1,
filepair_fn fn, const char *prefix, int ignorews)
{
struct diff_options opt;
- int ret;
int prefixlen;
diff_setup(&opt);
@@ -332,9 +325,9 @@ void cgit_diff_tree(const unsigned char *old_sha1,
diff_setup_done(&opt);
if (old_sha1 && !is_null_sha1(old_sha1))
- ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
+ diff_tree_sha1(old_sha1, new_sha1, "", &opt);
else
- ret = diff_root_tree_sha1(new_sha1, "", &opt);
+ diff_root_tree_sha1(new_sha1, "", &opt);
diffcore_std(&opt);
diff_flush(&opt);
}
@@ -376,7 +369,33 @@ int cgit_parse_snapshots_mask(const char *str)
return rv;
}
-int cgit_open_filter(struct cgit_filter *filter)
+typedef struct {
+ char * name;
+ char * value;
+} cgit_env_var;
+
+static void prepare_env(struct cgit_repo * repo) {
+ cgit_env_var env_vars[] = {
+ { .name = "CGIT_REPO_URL", .value = repo->url },
+ { .name = "CGIT_REPO_NAME", .value = repo->name },
+ { .name = "CGIT_REPO_PATH", .value = repo->path },
+ { .name = "CGIT_REPO_OWNER", .value = repo->owner },
+ { .name = "CGIT_REPO_DEFBRANCH", .value = repo->defbranch },
+ { .name = "CGIT_REPO_SECTION", .value = repo->section },
+ { .name = "CGIT_REPO_CLONE_URL", .value = repo->clone_url }
+ };
+ int env_var_count = ARRAY_SIZE(env_vars);
+ cgit_env_var *p, *q;
+ static char *warn = "cgit warning: failed to set env: %s=%s\n";
+
+ p = env_vars;
+ q = p + env_var_count;
+ for (; p < q; p++)
+ if (setenv(p->name, p->value, 1))
+ fprintf(stderr, warn, p->name, p->value);
+}
+
+int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)
{
filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
@@ -387,6 +406,8 @@ int cgit_open_filter(struct cgit_filter *filter)
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);