diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-10-09 06:56:14 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-10-17 16:30:09 +0200 |
commit | 521e10c884055c800078e6dada97ccf6c5193aad (patch) | |
tree | f4a8398b2d64b171de909d57893441830a280712 | |
parent | ui: Remember to print ampersand as proper html entities. (diff) | |
download | cgit-pink-521e10c884055c800078e6dada97ccf6c5193aad.tar.gz cgit-pink-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 '')
-rw-r--r-- | cgit.c | 10 | ||||
-rw-r--r-- | cgit.h | 5 | ||||
-rw-r--r-- | cgitrc.5.txt | 28 | ||||
-rw-r--r-- | scan-tree.c | 48 | ||||
-rw-r--r-- | shared.c | 3 |
5 files changed, 36 insertions, 58 deletions
diff --git a/cgit.c b/cgit.c index a8dda23..d699cb6 100644 --- a/cgit.c +++ b/cgit.c @@ -163,10 +163,6 @@ void config_cb(const char *name, const char *value) ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-filter-overrides")) ctx.cfg.enable_filter_overrides = atoi(value); - else if (!strcmp(name, "enable-gitweb-desc")) - ctx.cfg.enable_gitweb_desc = atoi(value); - else if (!strcmp(name, "enable-gitweb-owner")) - ctx.cfg.enable_gitweb_owner = atoi(value); else if (!strcmp(name, "enable-http-clone")) ctx.cfg.enable_http_clone = atoi(value); else if (!strcmp(name, "enable-index-links")) @@ -183,6 +179,8 @@ void config_cb(const char *name, const char *value) ctx.cfg.enable_subject_links = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); + else if (!strcmp(name, "enable-git-config")) + ctx.cfg.enable_git_config = atoi(value); else if (!strcmp(name, "max-stats")) ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "cache-size")) @@ -343,11 +341,9 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.css = "/cgit.css"; ctx->cfg.logo = "/cgit.png"; ctx->cfg.local_time = 0; - ctx->cfg.enable_gitweb_desc = 1; - ctx->cfg.enable_gitweb_owner = 1; - ctx->cfg.enable_gitweb_section = 1; ctx->cfg.enable_http_clone = 1; ctx->cfg.enable_tree_linenumbers = 1; + ctx->cfg.enable_git_config = 0; ctx->cfg.max_repo_count = 50; ctx->cfg.max_commit_count = 50; ctx->cfg.max_lock_attempts = 5; diff --git a/cgit.h b/cgit.h index 8846e88..2742058 100644 --- a/cgit.h +++ b/cgit.h @@ -200,9 +200,6 @@ struct cgit_config { int case_sensitive_sort; int embedded; int enable_filter_overrides; - int enable_gitweb_owner; - int enable_gitweb_desc; - int enable_gitweb_section; int enable_http_clone; int enable_index_links; int enable_commit_graph; @@ -211,6 +208,7 @@ struct cgit_config { int enable_remote_branches; int enable_subject_links; int enable_tree_linenumbers; + int enable_git_config; int local_time; int max_atom_items; int max_repo_count; @@ -285,6 +283,7 @@ extern struct cgit_repolist cgit_repolist; extern struct cgit_context ctx; extern const struct cgit_snapshot_format cgit_snapshot_formats[]; +extern char *cgit_default_repo_desc; extern struct cgit_repo *cgit_add_repo(const char *url); extern struct cgit_repo *cgit_get_repoinfo(const char *url); extern void cgit_repo_config_cb(const char *name, const char *value); diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 7e1a93a..278de90 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -110,24 +110,6 @@ enable-filter-overrides:: Flag which, when set to "1", allows all filter settings to be overridden in repository-specific cgitrc files. Default value: none. -enable-gitweb-desc:: - If set to "1" and scan-path is enabled, we first check each repository - for the git config value "gitweb.description" to determine the owner. - Otherwise, the description is read from a file titled "description" - inside of the repository directory. - Default value: "1". See also: scan-path. - -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-gitweb-section:: - If set to "1" and scan-path is enabled, we first check each repository - for the git config value "gitweb.category" to determine the repository's - section. This value is overridden if section-from-path is enabled. - Default value: "1". See also: scan-path section-from-path. - enable-http-clone:: If set to "1", cgit will act as an dumb HTTP endpoint for git clones. If you use an alternate way of serving git repositories, you may wish @@ -163,6 +145,15 @@ enable-tree-linenumbers:: Flag which, when set to "1", will make cgit generate linenumber links for plaintext blobs printed in the tree view. Default value: "1". +enable-git-config:: + Flag which, when set to "1", will allow cgit to use git config to set + any repo specific settings. This option is used in conjunction with + "scan-path" to augment _repo._ settings. The keys gitweb.owner, + gitweb.category, and gitweb.description will map to the cgit keys + repo.owner, repo.section, and repo.desc, respectivly. All git config + keys that begin with "cgit." will be mapped to the corresponding "repo." + key in cgit. Default value: "0". See also: scan-path section-from-path. + favicon:: Url used as link to a shortcut icon for cgit. If specified, it is suggested to use the value "/favicon.ico" since certain browsers will @@ -394,6 +385,7 @@ virtual-root:: NOTE: cgit has recently learned how to use PATH_INFO to achieve the same kind of virtual urls, so this option will probably be deprecated. + REPOSITORY SETTINGS ------------------- repo.about-filter:: 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); } diff --git a/shared.c b/shared.c index 0a0e22e..3e20937 100644 --- a/shared.c +++ b/shared.c @@ -33,6 +33,7 @@ int chk_non_negative(int result, char *msg) return result; } +char *cgit_default_repo_desc = "[no description]"; struct cgit_repo *cgit_add_repo(const char *url) { struct cgit_repo *ret; @@ -52,7 +53,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->url = trim_end(url, '/'); ret->name = ret->url; ret->path = NULL; - ret->desc = "[no description]"; + ret->desc = cgit_default_repo_desc; ret->owner = NULL; ret->section = ctx.cfg.section; ret->snapshots = ctx.cfg.snapshots; |