aboutsummaryrefslogtreecommitdiff
path: root/shared.c
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c51
1 files changed, 15 insertions, 36 deletions
diff --git a/shared.c b/shared.c
index be2ae59..7ec2e19 100644
--- a/shared.c
+++ b/shared.c
@@ -7,8 +7,6 @@
*/
#include "cgit.h"
-#include <stdio.h>
-#include <linux/limits.h>
struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
@@ -102,15 +100,23 @@ 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;
- len = strlen(str);
- while(len > 0 && str[len - 1] == c)
+ t = (char *)str;
+ len = strlen(t);
+ while(len > 0 && t[len - 1] == c)
len--;
+
if (len == 0)
return NULL;
- return xstrndup(str, len);
+
+ c = t[len];
+ t[len] = '\0';
+ s = xstrdup(t);
+ t[len] = c;
+ return s;
}
char *strlpart(char *txt, int maxlen)
@@ -305,6 +311,7 @@ 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);
@@ -325,9 +332,9 @@ void cgit_diff_tree(const unsigned char *old_sha1,
diff_setup_done(&opt);
if (old_sha1 && !is_null_sha1(old_sha1))
- diff_tree_sha1(old_sha1, new_sha1, "", &opt);
+ ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
else
- diff_root_tree_sha1(new_sha1, "", &opt);
+ ret = diff_root_tree_sha1(new_sha1, "", &opt);
diffcore_std(&opt);
diff_flush(&opt);
}
@@ -369,33 +376,7 @@ int cgit_parse_snapshots_mask(const char *str)
return rv;
}
-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)
+int cgit_open_filter(struct cgit_filter *filter)
{
filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
@@ -406,8 +387,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);