aboutsummaryrefslogtreecommitdiff
path: root/scan-tree.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-10-09 06:56:14 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2012-10-17 16:30:09 +0200
commit521e10c884055c800078e6dada97ccf6c5193aad (patch)
treef4a8398b2d64b171de909d57893441830a280712 /scan-tree.c
parentc366bd6fa88fb7dbe1e42c84d56e2bda0b1682c5 (diff)
downloadcgit-521e10c884055c800078e6dada97ccf6c5193aad.tar.gz
cgit-521e10c884055c800078e6dada97ccf6c5193aad.tar.bz2
cgit-521e10c884055c800078e6dada97ccf6c5193aad.zip
scan-tree: Unify gitweb.* and cgit.* settings into one config option.
After some back and forth with Jamie and René, it looks like the git config semantics are going to be like this: - gitweb.category maps to the cgit repo config key "section" - gitweb.description maps to the cgit repo config key "desc" - gitweb.owner maps to the cgit repo config key "owner" - cgit.* maps to all cgit repo config keys This option can be enabled with "enable-git-config=1", and replaces all previous "enable-gitweb-*" config keys. The order of operations is as follows: - git config settings are applied in the order that they exist in the git config file - if the owner is not set from git config, get the owner using the usual getpwuid call - if the description is not set from git config, look inside the static $path/description file - if section-from-path=1, override whatever previous settings were inside of git config using the section-from-path logic - parse $path/cgitrc for local repo.* settings, that override all previous settings
Diffstat (limited to 'scan-tree.c')
-rw-r--r--scan-tree.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/scan-tree.c b/scan-tree.c
index 6d1941e..6ce8036 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -47,28 +47,26 @@ 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 gitweb_config(const char *key, const char *value, void *cb)
+static int gitconfig_config(const char *key, const char *value, void *cb)
{
- 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);
+ 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);
+
return 0;
}
-
-
static char *xstrrchr(char *s, char *from, int c)
{
while (from >= s && *from != c)
@@ -96,11 +94,6 @@ 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
@@ -110,12 +103,15 @@ 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 (!owner) {
+ while (!repo->owner) {
if ((pwd = getpwuid(st.st_uid)) == NULL) {
fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
path, strerror(errno), errno);
@@ -124,13 +120,10 @@ 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';
- owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
+ repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
}
- repo->owner = owner;
- if (desc)
- repo->desc = desc;
- else {
+ if (repo->desc == cgit_default_repo_desc || !repo->desc) {
p = fmt("%s/description", path);
if (!stat(p, &st))
readfile(p, &repo->desc, &size);
@@ -141,8 +134,6 @@ 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) {
@@ -167,10 +158,9 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
}
p = fmt("%s/cgitrc", path);
- if (!stat(p, &st)) {
- config_fn = fn;
+ if (!stat(p, &st))
parse_configfile(xstrdup(p), &repo_config);
- }
+
free(rel);
}