mirror of
https://git.zx2c4.com/cgit
synced 2024-11-23 00:48:42 +00:00
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
This commit is contained in:
parent
c366bd6fa8
commit
521e10c884
10
cgit.c
10
cgit.c
@ -163,10 +163,6 @@ void config_cb(const char *name, const char *value)
|
|||||||
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
|
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
|
||||||
else if (!strcmp(name, "enable-filter-overrides"))
|
else if (!strcmp(name, "enable-filter-overrides"))
|
||||||
ctx.cfg.enable_filter_overrides = atoi(value);
|
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"))
|
else if (!strcmp(name, "enable-http-clone"))
|
||||||
ctx.cfg.enable_http_clone = atoi(value);
|
ctx.cfg.enable_http_clone = atoi(value);
|
||||||
else if (!strcmp(name, "enable-index-links"))
|
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);
|
ctx.cfg.enable_subject_links = atoi(value);
|
||||||
else if (!strcmp(name, "enable-tree-linenumbers"))
|
else if (!strcmp(name, "enable-tree-linenumbers"))
|
||||||
ctx.cfg.enable_tree_linenumbers = atoi(value);
|
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"))
|
else if (!strcmp(name, "max-stats"))
|
||||||
ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
|
ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
|
||||||
else if (!strcmp(name, "cache-size"))
|
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.css = "/cgit.css";
|
||||||
ctx->cfg.logo = "/cgit.png";
|
ctx->cfg.logo = "/cgit.png";
|
||||||
ctx->cfg.local_time = 0;
|
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_http_clone = 1;
|
||||||
ctx->cfg.enable_tree_linenumbers = 1;
|
ctx->cfg.enable_tree_linenumbers = 1;
|
||||||
|
ctx->cfg.enable_git_config = 0;
|
||||||
ctx->cfg.max_repo_count = 50;
|
ctx->cfg.max_repo_count = 50;
|
||||||
ctx->cfg.max_commit_count = 50;
|
ctx->cfg.max_commit_count = 50;
|
||||||
ctx->cfg.max_lock_attempts = 5;
|
ctx->cfg.max_lock_attempts = 5;
|
||||||
|
5
cgit.h
5
cgit.h
@ -200,9 +200,6 @@ struct cgit_config {
|
|||||||
int case_sensitive_sort;
|
int case_sensitive_sort;
|
||||||
int embedded;
|
int embedded;
|
||||||
int enable_filter_overrides;
|
int enable_filter_overrides;
|
||||||
int enable_gitweb_owner;
|
|
||||||
int enable_gitweb_desc;
|
|
||||||
int enable_gitweb_section;
|
|
||||||
int enable_http_clone;
|
int enable_http_clone;
|
||||||
int enable_index_links;
|
int enable_index_links;
|
||||||
int enable_commit_graph;
|
int enable_commit_graph;
|
||||||
@ -211,6 +208,7 @@ struct cgit_config {
|
|||||||
int enable_remote_branches;
|
int enable_remote_branches;
|
||||||
int enable_subject_links;
|
int enable_subject_links;
|
||||||
int enable_tree_linenumbers;
|
int enable_tree_linenumbers;
|
||||||
|
int enable_git_config;
|
||||||
int local_time;
|
int local_time;
|
||||||
int max_atom_items;
|
int max_atom_items;
|
||||||
int max_repo_count;
|
int max_repo_count;
|
||||||
@ -285,6 +283,7 @@ extern struct cgit_repolist cgit_repolist;
|
|||||||
extern struct cgit_context ctx;
|
extern struct cgit_context ctx;
|
||||||
extern const struct cgit_snapshot_format cgit_snapshot_formats[];
|
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_add_repo(const char *url);
|
||||||
extern struct cgit_repo *cgit_get_repoinfo(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);
|
extern void cgit_repo_config_cb(const char *name, const char *value);
|
||||||
|
28
cgitrc.5.txt
28
cgitrc.5.txt
@ -110,24 +110,6 @@ enable-filter-overrides::
|
|||||||
Flag which, when set to "1", allows all filter settings to be
|
Flag which, when set to "1", allows all filter settings to be
|
||||||
overridden in repository-specific cgitrc files. Default value: none.
|
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::
|
enable-http-clone::
|
||||||
If set to "1", cgit will act as an dumb HTTP endpoint for git clones.
|
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
|
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
|
Flag which, when set to "1", will make cgit generate linenumber links
|
||||||
for plaintext blobs printed in the tree view. Default value: "1".
|
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::
|
favicon::
|
||||||
Url used as link to a shortcut icon for cgit. If specified, it is
|
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
|
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
|
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.
|
same kind of virtual urls, so this option will probably be deprecated.
|
||||||
|
|
||||||
|
|
||||||
REPOSITORY SETTINGS
|
REPOSITORY SETTINGS
|
||||||
-------------------
|
-------------------
|
||||||
repo.about-filter::
|
repo.about-filter::
|
||||||
|
48
scan-tree.c
48
scan-tree.c
@ -47,28 +47,26 @@ static int is_git_dir(const char *path)
|
|||||||
|
|
||||||
struct cgit_repo *repo;
|
struct cgit_repo *repo;
|
||||||
repo_config_fn config_fn;
|
repo_config_fn config_fn;
|
||||||
char *owner;
|
|
||||||
char *desc;
|
|
||||||
char *section;
|
|
||||||
|
|
||||||
static void repo_config(const char *name, const char *value)
|
static void repo_config(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
config_fn(repo, name, 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"))
|
if (!strcmp(key, "gitweb.owner"))
|
||||||
owner = xstrdup(value);
|
config_fn(repo, "owner", value);
|
||||||
else if (ctx.cfg.enable_gitweb_desc && !strcmp(key, "gitweb.description"))
|
else if (!strcmp(key, "gitweb.description"))
|
||||||
desc = xstrdup(value);
|
config_fn(repo, "desc", value);
|
||||||
else if (ctx.cfg.enable_gitweb_section && !strcmp(key, "gitweb.category"))
|
else if (!strcmp(key, "gitweb.category"))
|
||||||
section = xstrdup(value);
|
config_fn(repo, "section", value);
|
||||||
|
else if (!prefixcmp(key, "cgit."))
|
||||||
|
config_fn(repo, key + 5, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char *xstrrchr(char *s, char *from, int c)
|
static char *xstrrchr(char *s, char *from, int c)
|
||||||
{
|
{
|
||||||
while (from >= s && *from != 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))
|
if (!stat(fmt("%s/noweb", path), &st))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
owner = NULL;
|
|
||||||
desc = NULL;
|
|
||||||
section = NULL;
|
|
||||||
git_config_from_file(gitweb_config, fmt("%s/config", path), NULL);
|
|
||||||
|
|
||||||
if (base == path)
|
if (base == path)
|
||||||
rel = xstrdup(fmt("%s", path));
|
rel = xstrdup(fmt("%s", path));
|
||||||
else
|
else
|
||||||
@ -110,12 +103,15 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
|
|||||||
rel[strlen(rel) - 5] = '\0';
|
rel[strlen(rel) - 5] = '\0';
|
||||||
|
|
||||||
repo = cgit_add_repo(rel);
|
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 (ctx.cfg.remove_suffix)
|
||||||
if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
|
if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
repo->name = repo->url;
|
|
||||||
repo->path = xstrdup(path);
|
repo->path = xstrdup(path);
|
||||||
while (!owner) {
|
while (!repo->owner) {
|
||||||
if ((pwd = getpwuid(st.st_uid)) == NULL) {
|
if ((pwd = getpwuid(st.st_uid)) == NULL) {
|
||||||
fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
|
fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
|
||||||
path, strerror(errno), errno);
|
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 (pwd->pw_gecos)
|
||||||
if ((p = strchr(pwd->pw_gecos, ',')))
|
if ((p = strchr(pwd->pw_gecos, ',')))
|
||||||
*p = '\0';
|
*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)
|
if (repo->desc == cgit_default_repo_desc || !repo->desc) {
|
||||||
repo->desc = desc;
|
|
||||||
else {
|
|
||||||
p = fmt("%s/description", path);
|
p = fmt("%s/description", path);
|
||||||
if (!stat(p, &st))
|
if (!stat(p, &st))
|
||||||
readfile(p, &repo->desc, &size);
|
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))
|
if (!stat(p, &st))
|
||||||
repo->readme = "README.html";
|
repo->readme = "README.html";
|
||||||
}
|
}
|
||||||
if (section)
|
|
||||||
repo->section = section;
|
|
||||||
if (ctx.cfg.section_from_path) {
|
if (ctx.cfg.section_from_path) {
|
||||||
n = ctx.cfg.section_from_path;
|
n = ctx.cfg.section_from_path;
|
||||||
if (n > 0) {
|
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);
|
p = fmt("%s/cgitrc", path);
|
||||||
if (!stat(p, &st)) {
|
if (!stat(p, &st))
|
||||||
config_fn = fn;
|
|
||||||
parse_configfile(xstrdup(p), &repo_config);
|
parse_configfile(xstrdup(p), &repo_config);
|
||||||
}
|
|
||||||
|
|
||||||
free(rel);
|
free(rel);
|
||||||
}
|
}
|
||||||
|
3
shared.c
3
shared.c
@ -33,6 +33,7 @@ int chk_non_negative(int result, char *msg)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *cgit_default_repo_desc = "[no description]";
|
||||||
struct cgit_repo *cgit_add_repo(const char *url)
|
struct cgit_repo *cgit_add_repo(const char *url)
|
||||||
{
|
{
|
||||||
struct cgit_repo *ret;
|
struct cgit_repo *ret;
|
||||||
@ -52,7 +53,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
|
|||||||
ret->url = trim_end(url, '/');
|
ret->url = trim_end(url, '/');
|
||||||
ret->name = ret->url;
|
ret->name = ret->url;
|
||||||
ret->path = NULL;
|
ret->path = NULL;
|
||||||
ret->desc = "[no description]";
|
ret->desc = cgit_default_repo_desc;
|
||||||
ret->owner = NULL;
|
ret->owner = NULL;
|
||||||
ret->section = ctx.cfg.section;
|
ret->section = ctx.cfg.section;
|
||||||
ret->snapshots = ctx.cfg.snapshots;
|
ret->snapshots = ctx.cfg.snapshots;
|
||||||
|
Loading…
Reference in New Issue
Block a user