aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c105
1 files changed, 89 insertions, 16 deletions
diff --git a/cgit.c b/cgit.c
index af9832f..f4dd6ef 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,6 +1,7 @@
1/* cgit.c: cgi for the git scm 1/* cgit.c: cgi for the git scm
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
4 * 5 *
5 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 7 * (see COPYING for full license text)
@@ -56,22 +57,29 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
56 repo->defbranch = xstrdup(value); 57 repo->defbranch = xstrdup(value);
57 else if (!strcmp(name, "snapshots")) 58 else if (!strcmp(name, "snapshots"))
58 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); 59 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
60 else if (!strcmp(name, "enable-commit-graph"))
61 repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value);
59 else if (!strcmp(name, "enable-log-filecount")) 62 else if (!strcmp(name, "enable-log-filecount"))
60 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 63 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
61 else if (!strcmp(name, "enable-log-linecount")) 64 else if (!strcmp(name, "enable-log-linecount"))
62 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 65 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
66 else if (!strcmp(name, "enable-remote-branches"))
67 repo->enable_remote_branches = atoi(value);
68 else if (!strcmp(name, "enable-subject-links"))
69 repo->enable_subject_links = atoi(value);
63 else if (!strcmp(name, "max-stats")) 70 else if (!strcmp(name, "max-stats"))
64 repo->max_stats = cgit_find_stats_period(value, NULL); 71 repo->max_stats = cgit_find_stats_period(value, NULL);
65 else if (!strcmp(name, "module-link")) 72 else if (!strcmp(name, "module-link"))
66 repo->module_link= xstrdup(value); 73 repo->module_link= xstrdup(value);
67 else if (!strcmp(name, "section")) 74 else if (!strcmp(name, "section"))
68 repo->section = xstrdup(value); 75 repo->section = xstrdup(value);
69 else if (!strcmp(name, "readme") && value != NULL) { 76 else if (!strcmp(name, "readme") && value != NULL)
70 if (*value == '/') 77 repo->readme = xstrdup(value);
71 repo->readme = xstrdup(value); 78 else if (!strcmp(name, "logo") && value != NULL)
72 else 79 repo->logo = xstrdup(value);
73 repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); 80 else if (!strcmp(name, "logo-link") && value != NULL)
74 } else if (ctx.cfg.enable_filter_overrides) { 81 repo->logo_link = xstrdup(value);
82 else if (ctx.cfg.enable_filter_overrides) {
75 if (!strcmp(name, "about-filter")) 83 if (!strcmp(name, "about-filter"))
76 repo->about_filter = new_filter(value, 0); 84 repo->about_filter = new_filter(value, 0);
77 else if (!strcmp(name, "commit-filter")) 85 else if (!strcmp(name, "commit-filter"))
@@ -91,6 +99,8 @@ void config_cb(const char *name, const char *value)
91 ctx.repo->path = trim_end(value, '/'); 99 ctx.repo->path = trim_end(value, '/');
92 else if (ctx.repo && !prefixcmp(name, "repo.")) 100 else if (ctx.repo && !prefixcmp(name, "repo."))
93 repo_config(ctx.repo, name + 5, value); 101 repo_config(ctx.repo, name + 5, value);
102 else if (!strcmp(name, "readme"))
103 ctx.cfg.readme = xstrdup(value);
94 else if (!strcmp(name, "root-title")) 104 else if (!strcmp(name, "root-title"))
95 ctx.cfg.root_title = xstrdup(value); 105 ctx.cfg.root_title = xstrdup(value);
96 else if (!strcmp(name, "root-desc")) 106 else if (!strcmp(name, "root-desc"))
@@ -117,6 +127,8 @@ void config_cb(const char *name, const char *value)
117 ctx.cfg.logo_link = xstrdup(value); 127 ctx.cfg.logo_link = xstrdup(value);
118 else if (!strcmp(name, "module-link")) 128 else if (!strcmp(name, "module-link"))
119 ctx.cfg.module_link = xstrdup(value); 129 ctx.cfg.module_link = xstrdup(value);
130 else if (!strcmp(name, "strict-export"))
131 ctx.cfg.strict_export = xstrdup(value);
120 else if (!strcmp(name, "virtual-root")) { 132 else if (!strcmp(name, "virtual-root")) {
121 ctx.cfg.virtual_root = trim_end(value, '/'); 133 ctx.cfg.virtual_root = trim_end(value, '/');
122 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 134 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
@@ -131,12 +143,20 @@ void config_cb(const char *name, const char *value)
131 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 143 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
132 else if (!strcmp(name, "enable-filter-overrides")) 144 else if (!strcmp(name, "enable-filter-overrides"))
133 ctx.cfg.enable_filter_overrides = atoi(value); 145 ctx.cfg.enable_filter_overrides = atoi(value);
146 else if (!strcmp(name, "enable-gitweb-owner"))
147 ctx.cfg.enable_gitweb_owner = atoi(value);
134 else if (!strcmp(name, "enable-index-links")) 148 else if (!strcmp(name, "enable-index-links"))
135 ctx.cfg.enable_index_links = atoi(value); 149 ctx.cfg.enable_index_links = atoi(value);
150 else if (!strcmp(name, "enable-commit-graph"))
151 ctx.cfg.enable_commit_graph = atoi(value);
136 else if (!strcmp(name, "enable-log-filecount")) 152 else if (!strcmp(name, "enable-log-filecount"))
137 ctx.cfg.enable_log_filecount = atoi(value); 153 ctx.cfg.enable_log_filecount = atoi(value);
138 else if (!strcmp(name, "enable-log-linecount")) 154 else if (!strcmp(name, "enable-log-linecount"))
139 ctx.cfg.enable_log_linecount = atoi(value); 155 ctx.cfg.enable_log_linecount = atoi(value);
156 else if (!strcmp(name, "enable-remote-branches"))
157 ctx.cfg.enable_remote_branches = atoi(value);
158 else if (!strcmp(name, "enable-subject-links"))
159 ctx.cfg.enable_subject_links = atoi(value);
140 else if (!strcmp(name, "enable-tree-linenumbers")) 160 else if (!strcmp(name, "enable-tree-linenumbers"))
141 ctx.cfg.enable_tree_linenumbers = atoi(value); 161 ctx.cfg.enable_tree_linenumbers = atoi(value);
142 else if (!strcmp(name, "max-stats")) 162 else if (!strcmp(name, "max-stats"))
@@ -144,7 +164,7 @@ void config_cb(const char *name, const char *value)
144 else if (!strcmp(name, "cache-size")) 164 else if (!strcmp(name, "cache-size"))
145 ctx.cfg.cache_size = atoi(value); 165 ctx.cfg.cache_size = atoi(value);
146 else if (!strcmp(name, "cache-root")) 166 else if (!strcmp(name, "cache-root"))
147 ctx.cfg.cache_root = xstrdup(value); 167 ctx.cfg.cache_root = xstrdup(expand_macros(value));
148 else if (!strcmp(name, "cache-root-ttl")) 168 else if (!strcmp(name, "cache-root-ttl"))
149 ctx.cfg.cache_root_ttl = atoi(value); 169 ctx.cfg.cache_root_ttl = atoi(value);
150 else if (!strcmp(name, "cache-repo-ttl")) 170 else if (!strcmp(name, "cache-repo-ttl"))
@@ -161,19 +181,32 @@ void config_cb(const char *name, const char *value)
161 ctx.cfg.commit_filter = new_filter(value, 0); 181 ctx.cfg.commit_filter = new_filter(value, 0);
162 else if (!strcmp(name, "embedded")) 182 else if (!strcmp(name, "embedded"))
163 ctx.cfg.embedded = atoi(value); 183 ctx.cfg.embedded = atoi(value);
184 else if (!strcmp(name, "max-atom-items"))
185 ctx.cfg.max_atom_items = atoi(value);
164 else if (!strcmp(name, "max-message-length")) 186 else if (!strcmp(name, "max-message-length"))
165 ctx.cfg.max_msg_len = atoi(value); 187 ctx.cfg.max_msg_len = atoi(value);
166 else if (!strcmp(name, "max-repodesc-length")) 188 else if (!strcmp(name, "max-repodesc-length"))
167 ctx.cfg.max_repodesc_len = atoi(value); 189 ctx.cfg.max_repodesc_len = atoi(value);
190 else if (!strcmp(name, "max-blob-size"))
191 ctx.cfg.max_blob_size = atoi(value);
168 else if (!strcmp(name, "max-repo-count")) 192 else if (!strcmp(name, "max-repo-count"))
169 ctx.cfg.max_repo_count = atoi(value); 193 ctx.cfg.max_repo_count = atoi(value);
170 else if (!strcmp(name, "max-commit-count")) 194 else if (!strcmp(name, "max-commit-count"))
171 ctx.cfg.max_commit_count = atoi(value); 195 ctx.cfg.max_commit_count = atoi(value);
196 else if (!strcmp(name, "project-list"))
197 ctx.cfg.project_list = xstrdup(expand_macros(value));
172 else if (!strcmp(name, "scan-path")) 198 else if (!strcmp(name, "scan-path"))
173 if (!ctx.cfg.nocache && ctx.cfg.cache_size) 199 if (!ctx.cfg.nocache && ctx.cfg.cache_size)
174 process_cached_repolist(value); 200 process_cached_repolist(expand_macros(value));
201 else if (ctx.cfg.project_list)
202 scan_projects(expand_macros(value),
203 ctx.cfg.project_list, repo_config);
175 else 204 else
176 scan_tree(value, repo_config); 205 scan_tree(expand_macros(value), repo_config);
206 else if (!strcmp(name, "scan-hidden-path"))
207 ctx.cfg.scan_hidden_path = atoi(value);
208 else if (!strcmp(name, "section-from-path"))
209 ctx.cfg.section_from_path = atoi(value);
177 else if (!strcmp(name, "source-filter")) 210 else if (!strcmp(name, "source-filter"))
178 ctx.cfg.source_filter = new_filter(value, 1); 211 ctx.cfg.source_filter = new_filter(value, 1);
179 else if (!strcmp(name, "summary-log")) 212 else if (!strcmp(name, "summary-log"))
@@ -182,10 +215,14 @@ void config_cb(const char *name, const char *value)
182 ctx.cfg.summary_branches = atoi(value); 215 ctx.cfg.summary_branches = atoi(value);
183 else if (!strcmp(name, "summary-tags")) 216 else if (!strcmp(name, "summary-tags"))
184 ctx.cfg.summary_tags = atoi(value); 217 ctx.cfg.summary_tags = atoi(value);
218 else if (!strcmp(name, "side-by-side-diffs"))
219 ctx.cfg.ssdiff = atoi(value);
185 else if (!strcmp(name, "agefile")) 220 else if (!strcmp(name, "agefile"))
186 ctx.cfg.agefile = xstrdup(value); 221 ctx.cfg.agefile = xstrdup(value);
187 else if (!strcmp(name, "renamelimit")) 222 else if (!strcmp(name, "renamelimit"))
188 ctx.cfg.renamelimit = atoi(value); 223 ctx.cfg.renamelimit = atoi(value);
224 else if (!strcmp(name, "remove-suffix"))
225 ctx.cfg.remove_suffix = atoi(value);
189 else if (!strcmp(name, "robots")) 226 else if (!strcmp(name, "robots"))
190 ctx.cfg.robots = xstrdup(value); 227 ctx.cfg.robots = xstrdup(value);
191 else if (!strcmp(name, "clone-prefix")) 228 else if (!strcmp(name, "clone-prefix"))
@@ -195,7 +232,7 @@ void config_cb(const char *name, const char *value)
195 else if (!prefixcmp(name, "mimetype.")) 232 else if (!prefixcmp(name, "mimetype."))
196 add_mimetype(name + 9, value); 233 add_mimetype(name + 9, value);
197 else if (!strcmp(name, "include")) 234 else if (!strcmp(name, "include"))
198 parse_configfile(value, config_cb); 235 parse_configfile(expand_macros(value), config_cb);
199} 236}
200 237
201static void querystring_cb(const char *name, const char *value) 238static void querystring_cb(const char *name, const char *value)
@@ -209,6 +246,8 @@ static void querystring_cb(const char *name, const char *value)
209 } else if (!strcmp(name, "p")) { 246 } else if (!strcmp(name, "p")) {
210 ctx.qry.page = xstrdup(value); 247 ctx.qry.page = xstrdup(value);
211 } else if (!strcmp(name, "url")) { 248 } else if (!strcmp(name, "url")) {
249 if (*value == '/')
250 value++;
212 ctx.qry.url = xstrdup(value); 251 ctx.qry.url = xstrdup(value);
213 cgit_parse_url(value); 252 cgit_parse_url(value);
214 } else if (!strcmp(name, "qt")) { 253 } else if (!strcmp(name, "qt")) {
@@ -238,6 +277,14 @@ static void querystring_cb(const char *name, const char *value)
238 ctx.qry.showmsg = atoi(value); 277 ctx.qry.showmsg = atoi(value);
239 } else if (!strcmp(name, "period")) { 278 } else if (!strcmp(name, "period")) {
240 ctx.qry.period = xstrdup(value); 279 ctx.qry.period = xstrdup(value);
280 } else if (!strcmp(name, "ss")) {
281 ctx.qry.ssdiff = atoi(value);
282 } else if (!strcmp(name, "all")) {
283 ctx.qry.show_all = atoi(value);
284 } else if (!strcmp(name, "context")) {
285 ctx.qry.context = atoi(value);
286 } else if (!strcmp(name, "ignorews")) {
287 ctx.qry.ignorews = atoi(value);
241 } 288 }
242} 289}
243 290
@@ -262,23 +309,30 @@ static void prepare_context(struct cgit_context *ctx)
262 ctx->cfg.css = "/cgit.css"; 309 ctx->cfg.css = "/cgit.css";
263 ctx->cfg.logo = "/cgit.png"; 310 ctx->cfg.logo = "/cgit.png";
264 ctx->cfg.local_time = 0; 311 ctx->cfg.local_time = 0;
312 ctx->cfg.enable_gitweb_owner = 1;
265 ctx->cfg.enable_tree_linenumbers = 1; 313 ctx->cfg.enable_tree_linenumbers = 1;
266 ctx->cfg.max_repo_count = 50; 314 ctx->cfg.max_repo_count = 50;
267 ctx->cfg.max_commit_count = 50; 315 ctx->cfg.max_commit_count = 50;
268 ctx->cfg.max_lock_attempts = 5; 316 ctx->cfg.max_lock_attempts = 5;
269 ctx->cfg.max_msg_len = 80; 317 ctx->cfg.max_msg_len = 80;
270 ctx->cfg.max_repodesc_len = 80; 318 ctx->cfg.max_repodesc_len = 80;
319 ctx->cfg.max_blob_size = 0;
271 ctx->cfg.max_stats = 0; 320 ctx->cfg.max_stats = 0;
272 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 321 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
322 ctx->cfg.project_list = NULL;
273 ctx->cfg.renamelimit = -1; 323 ctx->cfg.renamelimit = -1;
324 ctx->cfg.remove_suffix = 0;
274 ctx->cfg.robots = "index, nofollow"; 325 ctx->cfg.robots = "index, nofollow";
275 ctx->cfg.root_title = "Git repository browser"; 326 ctx->cfg.root_title = "Git repository browser";
276 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 327 ctx->cfg.root_desc = "a fast webinterface for the git dscm";
328 ctx->cfg.scan_hidden_path = 0;
277 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 329 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
278 ctx->cfg.section = ""; 330 ctx->cfg.section = "";
279 ctx->cfg.summary_branches = 10; 331 ctx->cfg.summary_branches = 10;
280 ctx->cfg.summary_log = 10; 332 ctx->cfg.summary_log = 10;
281 ctx->cfg.summary_tags = 10; 333 ctx->cfg.summary_tags = 10;
334 ctx->cfg.max_atom_items = 10;
335 ctx->cfg.ssdiff = 0;
282 ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); 336 ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
283 ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); 337 ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
284 ctx->env.https = xstrdupn(getenv("HTTPS")); 338 ctx->env.https = xstrdupn(getenv("HTTPS"));
@@ -410,6 +464,12 @@ static void process_request(void *cbdata)
410 return; 464 return;
411 } 465 }
412 466
467 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
468 * in-project path limit to be made available at ctx->qry.vpath.
469 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
470 */
471 ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL;
472
413 if (cmd->want_repo && !ctx->repo) { 473 if (cmd->want_repo && !ctx->repo) {
414 cgit_print_http_headers(ctx); 474 cgit_print_http_headers(ctx);
415 cgit_print_docstart(ctx); 475 cgit_print_docstart(ctx);
@@ -491,6 +551,8 @@ void print_repo(FILE *f, struct cgit_repo *repo)
491 fprintf(f, "repo.section=%s\n", repo->section); 551 fprintf(f, "repo.section=%s\n", repo->section);
492 if (repo->clone_url) 552 if (repo->clone_url)
493 fprintf(f, "repo.clone-url=%s\n", repo->clone_url); 553 fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
554 fprintf(f, "repo.enable-commit-graph=%d\n",
555 repo->enable_commit_graph);
494 fprintf(f, "repo.enable-log-filecount=%d\n", 556 fprintf(f, "repo.enable-log-filecount=%d\n",
495 repo->enable_log_filecount); 557 repo->enable_log_filecount);
496 fprintf(f, "repo.enable-log-linecount=%d\n", 558 fprintf(f, "repo.enable-log-linecount=%d\n",
@@ -541,7 +603,10 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
541 return errno; 603 return errno;
542 } 604 }
543 idx = cgit_repolist.count; 605 idx = cgit_repolist.count;
544 scan_tree(path, repo_config); 606 if (ctx.cfg.project_list)
607 scan_projects(path, ctx.cfg.project_list, repo_config);
608 else
609 scan_tree(path, repo_config);
545 print_repolist(f, &cgit_repolist, idx); 610 print_repolist(f, &cgit_repolist, idx);
546 if (rename(locked_rc, cached_rc)) 611 if (rename(locked_rc, cached_rc))
547 fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", 612 fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
@@ -555,17 +620,25 @@ static void process_cached_repolist(const char *path)
555 struct stat st; 620 struct stat st;
556 char *cached_rc; 621 char *cached_rc;
557 time_t age; 622 time_t age;
623 unsigned long hash;
558 624
559 cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, 625 hash = hash_str(path);
560 hash_str(path))); 626 if (ctx.cfg.project_list)
627 hash += hash_str(ctx.cfg.project_list);
628 cached_rc = xstrdup(fmt("%s/rc-%8lx", ctx.cfg.cache_root, hash));
561 629
562 if (stat(cached_rc, &st)) { 630 if (stat(cached_rc, &st)) {
563 /* Nothing is cached, we need to scan without forking. And 631 /* Nothing is cached, we need to scan without forking. And
564 * if we fail to generate a cached repolist, we need to 632 * if we fail to generate a cached repolist, we need to
565 * invoke scan_tree manually. 633 * invoke scan_tree manually.
566 */ 634 */
567 if (generate_cached_repolist(path, cached_rc)) 635 if (generate_cached_repolist(path, cached_rc)) {
568 scan_tree(path, repo_config); 636 if (ctx.cfg.project_list)
637 scan_projects(path, ctx.cfg.project_list,
638 repo_config);
639 else
640 scan_tree(path, repo_config);
641 }
569 return; 642 return;
570 } 643 }
571 644
@@ -674,7 +747,7 @@ int main(int argc, const char **argv)
674 cgit_repolist.repos = NULL; 747 cgit_repolist.repos = NULL;
675 748
676 cgit_parse_args(argc, argv); 749 cgit_parse_args(argc, argv);
677 parse_configfile(ctx.env.cgit_config, config_cb); 750 parse_configfile(expand_macros(ctx.env.cgit_config), config_cb);
678 ctx.repo = NULL; 751 ctx.repo = NULL;
679 http_parse_querystring(ctx.qry.raw, querystring_cb); 752 http_parse_querystring(ctx.qry.raw, querystring_cb);
680 753