Diffstat (limited to 'scan-tree.c')
| -rw-r--r-- | scan-tree.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/scan-tree.c b/scan-tree.c index 6ce8036..6d1941e 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -47,26 +47,28 @@ static int is_git_dir(const char *path) struct cgit_repo *repo; repo_config_fn config_fn; +char *owner; +char *desc; +char *section; static void repo_config(const char *name, const char *value) { config_fn(repo, name, value); } -static int gitconfig_config(const char *key, const char *value, void *cb) +static int gitweb_config(const char *key, const char *value, void *cb) { - if (!strcmp(key, "gitweb.owner")) - config_fn(repo, "owner", value); - else if (!strcmp(key, "gitweb.description")) - config_fn(repo, "desc", value); - else if (!strcmp(key, "gitweb.category")) - config_fn(repo, "section", value); - else if (!prefixcmp(key, "cgit.")) - config_fn(repo, key + 5, value); - + if (ctx.cfg.enable_gitweb_owner && !strcmp(key, "gitweb.owner")) + owner = xstrdup(value); + else if (ctx.cfg.enable_gitweb_desc && !strcmp(key, "gitweb.description")) + desc = xstrdup(value); + else if (ctx.cfg.enable_gitweb_section && !strcmp(key, "gitweb.category")) + section = xstrdup(value); return 0; } + + static char *xstrrchr(char *s, char *from, int c) { while (from >= s && *from != c) @@ -94,6 +96,11 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) if (!stat(fmt("%s/noweb", path), &st)) return; + owner = NULL; + desc = NULL; + section = NULL; + git_config_from_file(gitweb_config, fmt("%s/config", path), NULL); + if (base == path) rel = xstrdup(fmt("%s", path)); else @@ -103,15 +110,12 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) rel[strlen(rel) - 5] = '\0'; repo = cgit_add_repo(rel); - config_fn = fn; - if (ctx.cfg.enable_git_config) - git_config_from_file(gitconfig_config, fmt("%s/config", path), NULL); - if (ctx.cfg.remove_suffix) if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) *p = '\0'; + repo->name = repo->url; repo->path = xstrdup(path); - while (!repo->owner) { + while (!owner) { if ((pwd = getpwuid(st.st_uid)) == NULL) { fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", path, strerror(errno), errno); @@ -120,10 +124,13 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) if (pwd->pw_gecos) if ((p = strchr(pwd->pw_gecos, ','))) *p = '\0'; - repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); + owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); } + repo->owner = owner; - if (repo->desc == cgit_default_repo_desc || !repo->desc) { + if (desc) + repo->desc = desc; + else { p = fmt("%s/description", path); if (!stat(p, &st)) readfile(p, &repo->desc, &size); @@ -134,6 +141,8 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) if (!stat(p, &st)) repo->readme = "README.html"; } + if (section) + repo->section = section; if (ctx.cfg.section_from_path) { n = ctx.cfg.section_from_path; if (n > 0) { @@ -158,9 +167,10 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) } p = fmt("%s/cgitrc", path); - if (!stat(p, &st)) + if (!stat(p, &st)) { + config_fn = fn; parse_configfile(xstrdup(p), &repo_config); - + } free(rel); } |