-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 5 | ||||
-rw-r--r-- | scan-tree.c | 33 |
4 files changed, 33 insertions, 9 deletions
@@ -137,2 +137,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.enable_filter_overrides = atoi(value); + else if (!strcmp(name, "enable-gitweb-owner")) + ctx.cfg.enable_gitweb_owner = atoi(value); else if (!strcmp(name, "enable-index-links")) @@ -295,2 +297,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.local_time = 0; + ctx->cfg.enable_gitweb_owner = 1; ctx->cfg.enable_tree_linenumbers = 1; @@ -185,2 +185,3 @@ struct cgit_config { int enable_filter_overrides; + int enable_gitweb_owner; int enable_index_links; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 6fb1083..5d77973 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -97,2 +97,7 @@ enable-filter-overrides:: +enable-gitweb-owner:: + If set to "1" and scan-path is enabled, we first check each repository + for the git config value "gitweb.owner" to determine the owner. + Default value: "1". See also: scan-path. + enable-index-links:: diff --git a/scan-tree.c b/scan-tree.c index a83a78c..e987824 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -49,2 +49,3 @@ struct cgit_repo *repo; repo_config_fn config_fn; +char *owner; @@ -55,2 +56,9 @@ static void repo_config(const char *name, const char *value) +static int git_owner_config(const char *key, const char *value, void *cb) +{ + if (!strcmp(key, "gitweb.owner")) + owner = xstrdup(value); + return 0; +} + static void add_repo(const char *base, const char *path, repo_config_fn fn) @@ -69,7 +77,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) return; - if ((pwd = getpwuid(st.st_uid)) == NULL) { - fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", - path, strerror(errno), errno); - return; - } + + owner = NULL; + if (ctx.cfg.enable_gitweb_owner) + git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); if (base == path) @@ -88,6 +95,14 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) repo->path = xstrdup(path); - p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; - if (p) - *p = '\0'; - repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); + while (!owner) { + if ((pwd = getpwuid(st.st_uid)) == NULL) { + fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", + path, strerror(errno), errno); + break; + } + 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 = owner; |