about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJason A. Donenfeld2012-10-09 06:56:14 -0400
committerJason A. Donenfeld2012-10-17 16:30:09 +0200
commit521e10c884055c800078e6dada97ccf6c5193aad (patch)
treef4a8398b2d64b171de909d57893441830a280712
parentui: Remember to print ampersand as proper html entities. (diff)
downloadcgit-521e10c884055c800078e6dada97ccf6c5193aad.tar.gz
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
-rw-r--r--cgit.c10
-rw-r--r--cgit.h5
-rw-r--r--cgitrc.5.txt28
-rw-r--r--scan-tree.c48
-rw-r--r--shared.c3
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)
163 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 163 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
164 else if (!strcmp(name, "enable-filter-overrides")) 164 else if (!strcmp(name, "enable-filter-overrides"))
165 ctx.cfg.enable_filter_overrides = atoi(value); 165 ctx.cfg.enable_filter_overrides = atoi(value);
166 else if (!strcmp(name, "enable-gitweb-desc"))
167 ctx.cfg.enable_gitweb_desc = atoi(value);
168 else if (!strcmp(name, "enable-gitweb-owner"))
169 ctx.cfg.enable_gitweb_owner = atoi(value);
170 else if (!strcmp(name, "enable-http-clone")) 166 else if (!strcmp(name, "enable-http-clone"))
171 ctx.cfg.enable_http_clone = atoi(value); 167 ctx.cfg.enable_http_clone = atoi(value);
172 else if (!strcmp(name, "enable-index-links")) 168 else if (!strcmp(name, "enable-index-links"))
@@ -183,6 +179,8 @@ void config_cb(const char *name, const char *value)
183 ctx.cfg.enable_subject_links = atoi(value); 179 ctx.cfg.enable_subject_links = atoi(value);
184 else if (!strcmp(name, "enable-tree-linenumbers")) 180 else if (!strcmp(name, "enable-tree-linenumbers"))
185 ctx.cfg.enable_tree_linenumbers = atoi(value); 181 ctx.cfg.enable_tree_linenumbers = atoi(value);
182 else if (!strcmp(name, "enable-git-config"))
183 ctx.cfg.enable_git_config = atoi(value);
186 else if (!strcmp(name, "max-stats")) 184 else if (!strcmp(name, "max-stats"))
187 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 185 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
188 else if (!strcmp(name, "cache-size")) 186 else if (!strcmp(name, "cache-size"))
@@ -343,11 +341,9 @@ static void prepare_context(struct cgit_context *ctx)
343 ctx->cfg.css = "/cgit.css"; 341 ctx->cfg.css = "/cgit.css";
344 ctx->cfg.logo = "/cgit.png"; 342 ctx->cfg.logo = "/cgit.png";
345 ctx->cfg.local_time = 0; 343 ctx->cfg.local_time = 0;
346 ctx->cfg.enable_gitweb_desc = 1;
347 ctx->cfg.enable_gitweb_owner = 1;
348 ctx->cfg.enable_gitweb_section = 1;
349 ctx->cfg.enable_http_clone = 1; 344 ctx->cfg.enable_http_clone = 1;
350 ctx->cfg.enable_tree_linenumbers = 1; 345 ctx->cfg.enable_tree_linenumbers = 1;
346 ctx->cfg.enable_git_config = 0;
351 ctx->cfg.max_repo_count = 50; 347 ctx->cfg.max_repo_count = 50;
352 ctx->cfg.max_commit_count = 50; 348 ctx->cfg.max_commit_count = 50;
353 ctx->cfg.max_lock_attempts = 5; 349 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 {
200 int case_sensitive_sort; 200 int case_sensitive_sort;
201 int embedded; 201 int embedded;
202 int enable_filter_overrides; 202 int enable_filter_overrides;
203 int enable_gitweb_owner;
204 int enable_gitweb_desc;
205 int enable_gitweb_section;
206 int enable_http_clone; 203 int enable_http_clone;
207 int enable_index_links; 204 int enable_index_links;
208 int enable_commit_graph; 205 int enable_commit_graph;
@@ -211,6 +208,7 @@ struct cgit_config {
211 int enable_remote_branches; 208 int enable_remote_branches;
212 int enable_subject_links; 209 int enable_subject_links;
213 int enable_tree_linenumbers; 210 int enable_tree_linenumbers;
211 int enable_git_config;
214 int local_time; 212 int local_time;
215 int max_atom_items; 213 int max_atom_items;
216 int max_repo_count; 214 int max_repo_count;
@@ -285,6 +283,7 @@ extern struct cgit_repolist cgit_repolist;
285extern struct cgit_context ctx; 283extern struct cgit_context ctx;
286extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 284extern const struct cgit_snapshot_format cgit_snapshot_formats[];
287 285
286extern char *cgit_default_repo_desc;
288extern struct cgit_repo *cgit_add_repo(const char *url); 287extern struct cgit_repo *cgit_add_repo(const char *url);
289extern struct cgit_repo *cgit_get_repoinfo(const char *url); 288extern struct cgit_repo *cgit_get_repoinfo(const char *url);
290extern void cgit_repo_config_cb(const char *name, const char *value); 289extern 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::
110 Flag which, when set to "1", allows all filter settings to be 110 Flag which, when set to "1", allows all filter settings to be
111 overridden in repository-specific cgitrc files. Default value: none. 111 overridden in repository-specific cgitrc files. Default value: none.
112 112
113enable-gitweb-desc::
114 If set to "1" and scan-path is enabled, we first check each repository
115 for the git config value "gitweb.description" to determine the owner.
116 Otherwise, the description is read from a file titled "description"
117 inside of the repository directory.
118 Default value: "1". See also: scan-path.
119
120enable-gitweb-owner::
121 If set to "1" and scan-path is enabled, we first check each repository
122 for the git config value "gitweb.owner" to determine the owner.
123 Default value: "1". See also: scan-path.
124
125enable-gitweb-section::
126 If set to "1" and scan-path is enabled, we first check each repository
127 for the git config value "gitweb.category" to determine the repository's
128 section. This value is overridden if section-from-path is enabled.
129 Default value: "1". See also: scan-path section-from-path.
130
131enable-http-clone:: 113enable-http-clone::
132 If set to "1", cgit will act as an dumb HTTP endpoint for git clones. 114 If set to "1", cgit will act as an dumb HTTP endpoint for git clones.
133 If you use an alternate way of serving git repositories, you may wish 115 If you use an alternate way of serving git repositories, you may wish
@@ -163,6 +145,15 @@ enable-tree-linenumbers::
163 Flag which, when set to "1", will make cgit generate linenumber links 145 Flag which, when set to "1", will make cgit generate linenumber links
164 for plaintext blobs printed in the tree view. Default value: "1". 146 for plaintext blobs printed in the tree view. Default value: "1".
165 147
148enable-git-config::
149 Flag which, when set to "1", will allow cgit to use git config to set
150 any repo specific settings. This option is used in conjunction with
151 "scan-path" to augment _repo._ settings. The keys gitweb.owner,
152 gitweb.category, and gitweb.description will map to the cgit keys
153 repo.owner, repo.section, and repo.desc, respectivly. All git config
154 keys that begin with "cgit." will be mapped to the corresponding "repo."
155 key in cgit. Default value: "0". See also: scan-path section-from-path.
156
166favicon:: 157favicon::
167 Url used as link to a shortcut icon for cgit. If specified, it is 158 Url used as link to a shortcut icon for cgit. If specified, it is
168 suggested to use the value "/favicon.ico" since certain browsers will 159 suggested to use the value "/favicon.ico" since certain browsers will
@@ -394,6 +385,7 @@ virtual-root::
394 NOTE: cgit has recently learned how to use PATH_INFO to achieve the 385 NOTE: cgit has recently learned how to use PATH_INFO to achieve the
395 same kind of virtual urls, so this option will probably be deprecated. 386 same kind of virtual urls, so this option will probably be deprecated.
396 387
388
397REPOSITORY SETTINGS 389REPOSITORY SETTINGS
398------------------- 390-------------------
399repo.about-filter:: 391repo.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)
47 47
48struct cgit_repo *repo; 48struct cgit_repo *repo;
49repo_config_fn config_fn; 49repo_config_fn config_fn;
50char *owner;
51char *desc;
52char *section;
53 50
54static void repo_config(const char *name, const char *value) 51static void repo_config(const char *name, const char *value)
55{ 52{
56 config_fn(repo, name, value); 53 config_fn(repo, name, value);
57} 54}
58 55
59static int gitweb_config(const char *key, const char *value, void *cb) 56static int gitconfig_config(const char *key, const char *value, void *cb)
60{ 57{
61 if (ctx.cfg.enable_gitweb_owner && !strcmp(key, "gitweb.owner")) 58 if (!strcmp(key, "gitweb.owner"))
62 owner = xstrdup(value); 59 config_fn(repo, "owner", value);
63 else if (ctx.cfg.enable_gitweb_desc && !strcmp(key, "gitweb.description")) 60 else if (!strcmp(key, "gitweb.description"))
64 desc = xstrdup(value); 61 config_fn(repo, "desc", value);
65 else if (ctx.cfg.enable_gitweb_section && !strcmp(key, "gitweb.category")) 62 else if (!strcmp(key, "gitweb.category"))
66 section = xstrdup(value); 63 config_fn(repo, "section", value);
64 else if (!prefixcmp(key, "cgit."))
65 config_fn(repo, key + 5, value);
66
67 return 0; 67 return 0;
68} 68}
69 69
70
71
72static char *xstrrchr(char *s, char *from, int c) 70static char *xstrrchr(char *s, char *from, int c)
73{ 71{
74 while (from >= s && *from != c) 72 while (from >= s && *from != c)
@@ -96,11 +94,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
96 if (!stat(fmt("%s/noweb", path), &st)) 94 if (!stat(fmt("%s/noweb", path), &st))
97 return; 95 return;
98 96
99 owner = NULL;
100 desc = NULL;
101 section = NULL;
102 git_config_from_file(gitweb_config, fmt("%s/config", path), NULL);
103
104 if (base == path) 97 if (base == path)
105 rel = xstrdup(fmt("%s", path)); 98 rel = xstrdup(fmt("%s", path));
106 else 99 else
@@ -110,12 +103,15 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
110 rel[strlen(rel) - 5] = '\0'; 103 rel[strlen(rel) - 5] = '\0';
111 104
112 repo = cgit_add_repo(rel); 105 repo = cgit_add_repo(rel);
106 config_fn = fn;
107 if (ctx.cfg.enable_git_config)
108 git_config_from_file(gitconfig_config, fmt("%s/config", path), NULL);
109
113 if (ctx.cfg.remove_suffix) 110 if (ctx.cfg.remove_suffix)
114 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) 111 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
115 *p = '\0'; 112 *p = '\0';
116 repo->name = repo->url;
117 repo->path = xstrdup(path); 113 repo->path = xstrdup(path);
118 while (!owner) { 114 while (!repo->owner) {
119 if ((pwd = getpwuid(st.st_uid)) == NULL) { 115 if ((pwd = getpwuid(st.st_uid)) == NULL) {
120 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", 116 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
121 path, strerror(errno), errno); 117 path, strerror(errno), errno);
@@ -124,13 +120,10 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
124 if (pwd->pw_gecos) 120 if (pwd->pw_gecos)
125 if ((p = strchr(pwd->pw_gecos, ','))) 121 if ((p = strchr(pwd->pw_gecos, ',')))
126 *p = '\0'; 122 *p = '\0';
127 owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); 123 repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
128 } 124 }
129 repo->owner = owner;
130 125
131 if (desc) 126 if (repo->desc == cgit_default_repo_desc || !repo->desc) {
132 repo->desc = desc;
133 else {
134 p = fmt("%s/description", path); 127 p = fmt("%s/description", path);
135 if (!stat(p, &st)) 128 if (!stat(p, &st))
136 readfile(p, &repo->desc, &size); 129 readfile(p, &repo->desc, &size);
@@ -141,8 +134,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
141 if (!stat(p, &st)) 134 if (!stat(p, &st))
142 repo->readme = "README.html"; 135 repo->readme = "README.html";
143 } 136 }
144 if (section)
145 repo->section = section;
146 if (ctx.cfg.section_from_path) { 137 if (ctx.cfg.section_from_path) {
147 n = ctx.cfg.section_from_path; 138 n = ctx.cfg.section_from_path;
148 if (n > 0) { 139 if (n > 0) {
@@ -167,10 +158,9 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
167 } 158 }
168 159
169 p = fmt("%s/cgitrc", path); 160 p = fmt("%s/cgitrc", path);
170 if (!stat(p, &st)) { 161 if (!stat(p, &st))
171 config_fn = fn;
172 parse_configfile(xstrdup(p), &repo_config); 162 parse_configfile(xstrdup(p), &repo_config);
173 } 163
174 164
175 free(rel); 165 free(rel);
176} 166}
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)
33 return result; 33 return result;
34} 34}
35 35
36char *cgit_default_repo_desc = "[no description]";
36struct cgit_repo *cgit_add_repo(const char *url) 37struct cgit_repo *cgit_add_repo(const char *url)
37{ 38{
38 struct cgit_repo *ret; 39 struct cgit_repo *ret;
@@ -52,7 +53,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
52 ret->url = trim_end(url, '/'); 53 ret->url = trim_end(url, '/');
53 ret->name = ret->url; 54 ret->name = ret->url;
54 ret->path = NULL; 55 ret->path = NULL;
55 ret->desc = "[no description]"; 56 ret->desc = cgit_default_repo_desc;
56 ret->owner = NULL; 57 ret->owner = NULL;
57 ret->section = ctx.cfg.section; 58 ret->section = ctx.cfg.section;
58 ret->snapshots = ctx.cfg.snapshots; 59 ret->snapshots = ctx.cfg.snapshots;