2006-12-10 21:41:14 +00:00
|
|
|
/* cgit.c: cgi for the git scm
|
|
|
|
*
|
2014-01-08 14:10:49 +00:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-10 21:41:14 +00:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
2006-12-09 14:18:17 +00:00
|
|
|
#include "cgit.h"
|
2008-03-27 08:22:13 +00:00
|
|
|
#include "cache.h"
|
2008-03-23 23:51:19 +00:00
|
|
|
#include "cmd.h"
|
2008-03-27 23:09:11 +00:00
|
|
|
#include "configfile.h"
|
2008-04-08 19:11:36 +00:00
|
|
|
#include "html.h"
|
2008-03-24 15:50:57 +00:00
|
|
|
#include "ui-shared.h"
|
2008-12-07 12:17:21 +00:00
|
|
|
#include "ui-stats.h"
|
2013-05-25 14:32:37 +00:00
|
|
|
#include "ui-blob.h"
|
|
|
|
#include "ui-summary.h"
|
2008-09-14 22:07:12 +00:00
|
|
|
#include "scan-tree.h"
|
2006-12-09 14:18:17 +00:00
|
|
|
|
2008-03-24 22:10:59 +00:00
|
|
|
const char *cgit_version = CGIT_VERSION;
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void add_mimetype(const char *name, const char *value)
|
2009-02-13 19:43:30 +00:00
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
2010-08-22 11:29:57 +00:00
|
|
|
item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
|
2009-02-13 19:43:30 +00:00
|
|
|
item->util = xstrdup(value);
|
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
|
2009-07-31 15:38:38 +00:00
|
|
|
{
|
|
|
|
struct cgit_filter *f;
|
2011-03-09 07:16:59 +00:00
|
|
|
int args_size = 0;
|
2011-03-23 10:57:41 +00:00
|
|
|
int extra_args;
|
2009-07-31 15:38:38 +00:00
|
|
|
|
2009-08-09 11:39:44 +00:00
|
|
|
if (!cmd || !cmd[0])
|
2009-07-31 15:38:38 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-23 10:57:41 +00:00
|
|
|
switch (filtertype) {
|
|
|
|
case SOURCE:
|
2013-05-25 12:50:19 +00:00
|
|
|
case ABOUT:
|
2011-03-23 10:57:41 +00:00
|
|
|
extra_args = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMIT:
|
|
|
|
default:
|
|
|
|
extra_args = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-31 15:38:38 +00:00
|
|
|
f = xmalloc(sizeof(struct cgit_filter));
|
|
|
|
f->cmd = xstrdup(cmd);
|
2011-03-09 07:16:59 +00:00
|
|
|
args_size = (2 + extra_args) * sizeof(char *);
|
|
|
|
f->argv = xmalloc(args_size);
|
|
|
|
memset(f->argv, 0, args_size);
|
2009-07-31 15:38:38 +00:00
|
|
|
f->argv[0] = f->cmd;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2009-08-20 15:41:54 +00:00
|
|
|
static void process_cached_repolist(const char *path);
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void repo_config(struct cgit_repo *repo, const char *name, const char *value)
|
2009-08-23 21:23:20 +00:00
|
|
|
{
|
2011-06-15 08:04:13 +00:00
|
|
|
struct string_list_item *item;
|
|
|
|
|
2009-08-23 21:23:20 +00:00
|
|
|
if (!strcmp(name, "name"))
|
|
|
|
repo->name = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "clone-url"))
|
|
|
|
repo->clone_url = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "desc"))
|
|
|
|
repo->desc = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "owner"))
|
|
|
|
repo->owner = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "defbranch"))
|
|
|
|
repo->defbranch = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "snapshots"))
|
|
|
|
repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
|
2010-11-15 17:39:50 +00:00
|
|
|
else if (!strcmp(name, "enable-commit-graph"))
|
2012-04-18 10:32:13 +00:00
|
|
|
repo->enable_commit_graph = atoi(value);
|
2009-08-23 21:23:20 +00:00
|
|
|
else if (!strcmp(name, "enable-log-filecount"))
|
2012-04-18 10:32:13 +00:00
|
|
|
repo->enable_log_filecount = atoi(value);
|
2009-08-23 21:23:20 +00:00
|
|
|
else if (!strcmp(name, "enable-log-linecount"))
|
2012-04-18 10:32:13 +00:00
|
|
|
repo->enable_log_linecount = atoi(value);
|
2009-11-07 18:10:58 +00:00
|
|
|
else if (!strcmp(name, "enable-remote-branches"))
|
|
|
|
repo->enable_remote_branches = atoi(value);
|
2010-02-27 12:12:55 +00:00
|
|
|
else if (!strcmp(name, "enable-subject-links"))
|
|
|
|
repo->enable_subject_links = atoi(value);
|
2013-04-08 14:57:12 +00:00
|
|
|
else if (!strcmp(name, "branch-sort")) {
|
|
|
|
if (!strcmp(value, "age"))
|
|
|
|
repo->branch_sort = 1;
|
|
|
|
if (!strcmp(value, "name"))
|
|
|
|
repo->branch_sort = 0;
|
|
|
|
} else if (!strcmp(name, "commit-sort")) {
|
2012-10-13 14:10:30 +00:00
|
|
|
if (!strcmp(value, "date"))
|
|
|
|
repo->commit_sort = 1;
|
|
|
|
if (!strcmp(value, "topo"))
|
|
|
|
repo->commit_sort = 2;
|
|
|
|
} else if (!strcmp(name, "max-stats"))
|
2009-08-23 21:23:20 +00:00
|
|
|
repo->max_stats = cgit_find_stats_period(value, NULL);
|
|
|
|
else if (!strcmp(name, "module-link"))
|
|
|
|
repo->module_link= xstrdup(value);
|
2011-06-15 08:04:13 +00:00
|
|
|
else if (!prefixcmp(name, "module-link.")) {
|
2013-05-26 13:20:02 +00:00
|
|
|
item = string_list_append(&repo->submodules, xstrdup(name + 12));
|
2011-06-15 08:04:13 +00:00
|
|
|
item->util = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "section"))
|
2009-08-23 21:23:20 +00:00
|
|
|
repo->section = xstrdup(value);
|
2013-05-26 13:20:02 +00:00
|
|
|
else if (!strcmp(name, "readme") && value != NULL) {
|
|
|
|
if (repo->readme.items == ctx.cfg.readme.items)
|
|
|
|
memset(&repo->readme, 0, sizeof(repo->readme));
|
|
|
|
string_list_append(&repo->readme, xstrdup(value));
|
|
|
|
} else if (!strcmp(name, "logo") && value != NULL)
|
2010-12-23 11:47:54 +00:00
|
|
|
repo->logo = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "logo-link") && value != NULL)
|
|
|
|
repo->logo_link = xstrdup(value);
|
|
|
|
else if (ctx.cfg.enable_filter_overrides) {
|
2009-08-24 06:53:21 +00:00
|
|
|
if (!strcmp(name, "about-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
repo->about_filter = new_filter(value, ABOUT);
|
2009-08-24 06:53:21 +00:00
|
|
|
else if (!strcmp(name, "commit-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
repo->commit_filter = new_filter(value, COMMIT);
|
2009-08-24 06:53:21 +00:00
|
|
|
else if (!strcmp(name, "source-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
repo->source_filter = new_filter(value, SOURCE);
|
2009-08-23 21:23:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void config_cb(const char *name, const char *value)
|
2008-03-24 16:26:08 +00:00
|
|
|
{
|
2009-08-23 21:23:20 +00:00
|
|
|
if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
|
|
|
|
ctx.cfg.section = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "repo.url"))
|
|
|
|
ctx.repo = cgit_add_repo(value);
|
|
|
|
else if (ctx.repo && !strcmp(name, "repo.path"))
|
|
|
|
ctx.repo->path = trim_end(value, '/');
|
|
|
|
else if (ctx.repo && !prefixcmp(name, "repo."))
|
|
|
|
repo_config(ctx.repo, name + 5, value);
|
2013-05-26 13:20:02 +00:00
|
|
|
else if (!strcmp(name, "readme") && value != NULL)
|
|
|
|
string_list_append(&ctx.cfg.readme, xstrdup(value));
|
2009-08-23 21:23:20 +00:00
|
|
|
else if (!strcmp(name, "root-title"))
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx.cfg.root_title = xstrdup(value);
|
2008-04-28 22:55:34 +00:00
|
|
|
else if (!strcmp(name, "root-desc"))
|
|
|
|
ctx.cfg.root_desc = xstrdup(value);
|
2008-04-28 23:06:30 +00:00
|
|
|
else if (!strcmp(name, "root-readme"))
|
|
|
|
ctx.cfg.root_readme = xstrdup(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "css"))
|
|
|
|
ctx.cfg.css = xstrdup(value);
|
2008-07-19 18:40:30 +00:00
|
|
|
else if (!strcmp(name, "favicon"))
|
|
|
|
ctx.cfg.favicon = xstrdup(value);
|
2008-06-26 11:53:30 +00:00
|
|
|
else if (!strcmp(name, "footer"))
|
|
|
|
ctx.cfg.footer = xstrdup(value);
|
2009-03-15 04:11:54 +00:00
|
|
|
else if (!strcmp(name, "head-include"))
|
|
|
|
ctx.cfg.head_include = xstrdup(value);
|
2009-01-29 20:27:39 +00:00
|
|
|
else if (!strcmp(name, "header"))
|
|
|
|
ctx.cfg.header = xstrdup(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "logo"))
|
|
|
|
ctx.cfg.logo = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "index-header"))
|
|
|
|
ctx.cfg.index_header = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "index-info"))
|
|
|
|
ctx.cfg.index_info = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "logo-link"))
|
|
|
|
ctx.cfg.logo_link = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "module-link"))
|
|
|
|
ctx.cfg.module_link = xstrdup(value);
|
2010-11-08 18:41:13 +00:00
|
|
|
else if (!strcmp(name, "strict-export"))
|
|
|
|
ctx.cfg.strict_export = xstrdup(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "virtual-root")) {
|
2013-04-01 18:03:34 +00:00
|
|
|
ctx.cfg.virtual_root = ensure_end(value, '/');
|
2008-03-24 16:26:08 +00:00
|
|
|
} else if (!strcmp(name, "nocache"))
|
|
|
|
ctx.cfg.nocache = atoi(value);
|
2009-08-07 12:05:17 +00:00
|
|
|
else if (!strcmp(name, "noplainemail"))
|
|
|
|
ctx.cfg.noplainemail = atoi(value);
|
2009-07-25 10:19:31 +00:00
|
|
|
else if (!strcmp(name, "noheader"))
|
|
|
|
ctx.cfg.noheader = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "snapshots"))
|
|
|
|
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
|
2009-08-24 06:53:21 +00:00
|
|
|
else if (!strcmp(name, "enable-filter-overrides"))
|
|
|
|
ctx.cfg.enable_filter_overrides = atoi(value);
|
2011-01-12 18:06:07 +00:00
|
|
|
else if (!strcmp(name, "enable-http-clone"))
|
|
|
|
ctx.cfg.enable_http_clone = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "enable-index-links"))
|
|
|
|
ctx.cfg.enable_index_links = atoi(value);
|
2013-02-01 09:59:13 +00:00
|
|
|
else if (!strcmp(name, "enable-index-owner"))
|
|
|
|
ctx.cfg.enable_index_owner = atoi(value);
|
2010-11-15 17:39:50 +00:00
|
|
|
else if (!strcmp(name, "enable-commit-graph"))
|
|
|
|
ctx.cfg.enable_commit_graph = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "enable-log-filecount"))
|
|
|
|
ctx.cfg.enable_log_filecount = atoi(value);
|
|
|
|
else if (!strcmp(name, "enable-log-linecount"))
|
|
|
|
ctx.cfg.enable_log_linecount = atoi(value);
|
2009-11-07 18:10:58 +00:00
|
|
|
else if (!strcmp(name, "enable-remote-branches"))
|
|
|
|
ctx.cfg.enable_remote_branches = atoi(value);
|
2010-02-27 12:12:55 +00:00
|
|
|
else if (!strcmp(name, "enable-subject-links"))
|
|
|
|
ctx.cfg.enable_subject_links = atoi(value);
|
2009-08-21 12:26:52 +00:00
|
|
|
else if (!strcmp(name, "enable-tree-linenumbers"))
|
|
|
|
ctx.cfg.enable_tree_linenumbers = atoi(value);
|
2012-10-09 10:56:14 +00:00
|
|
|
else if (!strcmp(name, "enable-git-config"))
|
|
|
|
ctx.cfg.enable_git_config = atoi(value);
|
2008-12-07 12:17:21 +00:00
|
|
|
else if (!strcmp(name, "max-stats"))
|
|
|
|
ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
|
2008-04-28 09:32:42 +00:00
|
|
|
else if (!strcmp(name, "cache-size"))
|
|
|
|
ctx.cfg.cache_size = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "cache-root"))
|
2010-03-21 23:09:43 +00:00
|
|
|
ctx.cfg.cache_root = xstrdup(expand_macros(value));
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "cache-root-ttl"))
|
|
|
|
ctx.cfg.cache_root_ttl = atoi(value);
|
|
|
|
else if (!strcmp(name, "cache-repo-ttl"))
|
|
|
|
ctx.cfg.cache_repo_ttl = atoi(value);
|
2009-08-20 15:41:54 +00:00
|
|
|
else if (!strcmp(name, "cache-scanrc-ttl"))
|
|
|
|
ctx.cfg.cache_scanrc_ttl = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "cache-static-ttl"))
|
|
|
|
ctx.cfg.cache_static_ttl = atoi(value);
|
|
|
|
else if (!strcmp(name, "cache-dynamic-ttl"))
|
|
|
|
ctx.cfg.cache_dynamic_ttl = atoi(value);
|
2013-05-28 14:33:30 +00:00
|
|
|
else if (!strcmp(name, "cache-about-ttl"))
|
|
|
|
ctx.cfg.cache_about_ttl = atoi(value);
|
2012-07-12 17:13:39 +00:00
|
|
|
else if (!strcmp(name, "case-sensitive-sort"))
|
|
|
|
ctx.cfg.case_sensitive_sort = atoi(value);
|
2009-08-09 11:27:21 +00:00
|
|
|
else if (!strcmp(name, "about-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
ctx.cfg.about_filter = new_filter(value, ABOUT);
|
2009-07-31 15:42:57 +00:00
|
|
|
else if (!strcmp(name, "commit-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
ctx.cfg.commit_filter = new_filter(value, COMMIT);
|
2009-01-22 22:33:56 +00:00
|
|
|
else if (!strcmp(name, "embedded"))
|
|
|
|
ctx.cfg.embedded = atoi(value);
|
2010-02-05 00:08:16 +00:00
|
|
|
else if (!strcmp(name, "max-atom-items"))
|
|
|
|
ctx.cfg.max_atom_items = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "max-message-length"))
|
|
|
|
ctx.cfg.max_msg_len = atoi(value);
|
|
|
|
else if (!strcmp(name, "max-repodesc-length"))
|
|
|
|
ctx.cfg.max_repodesc_len = atoi(value);
|
2009-11-28 02:44:33 +00:00
|
|
|
else if (!strcmp(name, "max-blob-size"))
|
|
|
|
ctx.cfg.max_blob_size = atoi(value);
|
2008-05-03 08:54:39 +00:00
|
|
|
else if (!strcmp(name, "max-repo-count"))
|
|
|
|
ctx.cfg.max_repo_count = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "max-commit-count"))
|
|
|
|
ctx.cfg.max_commit_count = atoi(value);
|
2010-07-29 15:52:29 +00:00
|
|
|
else if (!strcmp(name, "project-list"))
|
|
|
|
ctx.cfg.project_list = xstrdup(expand_macros(value));
|
2009-08-23 17:35:56 +00:00
|
|
|
else if (!strcmp(name, "scan-path"))
|
|
|
|
if (!ctx.cfg.nocache && ctx.cfg.cache_size)
|
2010-03-21 23:09:43 +00:00
|
|
|
process_cached_repolist(expand_macros(value));
|
2010-07-29 15:52:29 +00:00
|
|
|
else if (ctx.cfg.project_list)
|
|
|
|
scan_projects(expand_macros(value),
|
|
|
|
ctx.cfg.project_list, repo_config);
|
2009-08-23 17:35:56 +00:00
|
|
|
else
|
2010-03-21 23:09:43 +00:00
|
|
|
scan_tree(expand_macros(value), repo_config);
|
2010-11-15 19:41:00 +00:00
|
|
|
else if (!strcmp(name, "scan-hidden-path"))
|
|
|
|
ctx.cfg.scan_hidden_path = atoi(value);
|
2010-08-21 13:44:09 +00:00
|
|
|
else if (!strcmp(name, "section-from-path"))
|
|
|
|
ctx.cfg.section_from_path = atoi(value);
|
2012-10-16 21:32:40 +00:00
|
|
|
else if (!strcmp(name, "repository-sort"))
|
|
|
|
ctx.cfg.repository_sort = xstrdup(value);
|
2012-10-09 18:53:29 +00:00
|
|
|
else if (!strcmp(name, "section-sort"))
|
|
|
|
ctx.cfg.section_sort = atoi(value);
|
2009-07-31 14:55:27 +00:00
|
|
|
else if (!strcmp(name, "source-filter"))
|
2011-03-23 10:57:41 +00:00
|
|
|
ctx.cfg.source_filter = new_filter(value, SOURCE);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "summary-log"))
|
|
|
|
ctx.cfg.summary_log = atoi(value);
|
|
|
|
else if (!strcmp(name, "summary-branches"))
|
|
|
|
ctx.cfg.summary_branches = atoi(value);
|
|
|
|
else if (!strcmp(name, "summary-tags"))
|
|
|
|
ctx.cfg.summary_tags = atoi(value);
|
2009-09-14 18:19:02 +00:00
|
|
|
else if (!strcmp(name, "side-by-side-diffs"))
|
|
|
|
ctx.cfg.ssdiff = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "agefile"))
|
|
|
|
ctx.cfg.agefile = xstrdup(value);
|
2011-07-19 08:51:58 +00:00
|
|
|
else if (!strcmp(name, "mimetype-file"))
|
|
|
|
ctx.cfg.mimetype_file = xstrdup(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "renamelimit"))
|
|
|
|
ctx.cfg.renamelimit = atoi(value);
|
2010-07-29 17:47:50 +00:00
|
|
|
else if (!strcmp(name, "remove-suffix"))
|
|
|
|
ctx.cfg.remove_suffix = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
else if (!strcmp(name, "robots"))
|
|
|
|
ctx.cfg.robots = xstrdup(value);
|
|
|
|
else if (!strcmp(name, "clone-prefix"))
|
|
|
|
ctx.cfg.clone_prefix = xstrdup(value);
|
2011-06-06 20:49:13 +00:00
|
|
|
else if (!strcmp(name, "clone-url"))
|
|
|
|
ctx.cfg.clone_url = xstrdup(value);
|
2008-08-01 12:54:38 +00:00
|
|
|
else if (!strcmp(name, "local-time"))
|
|
|
|
ctx.cfg.local_time = atoi(value);
|
2012-10-13 14:10:30 +00:00
|
|
|
else if (!strcmp(name, "commit-sort")) {
|
|
|
|
if (!strcmp(value, "date"))
|
|
|
|
ctx.cfg.commit_sort = 1;
|
|
|
|
if (!strcmp(value, "topo"))
|
|
|
|
ctx.cfg.commit_sort = 2;
|
2013-04-08 14:57:12 +00:00
|
|
|
} else if (!strcmp(name, "branch-sort")) {
|
|
|
|
if (!strcmp(value, "age"))
|
|
|
|
ctx.cfg.branch_sort = 1;
|
|
|
|
if (!strcmp(value, "name"))
|
|
|
|
ctx.cfg.branch_sort = 0;
|
2012-10-13 14:10:30 +00:00
|
|
|
} else if (!prefixcmp(name, "mimetype."))
|
2009-02-13 19:43:30 +00:00
|
|
|
add_mimetype(name + 9, value);
|
2009-08-23 21:23:20 +00:00
|
|
|
else if (!strcmp(name, "include"))
|
2010-03-21 23:09:43 +00:00
|
|
|
parse_configfile(expand_macros(value), config_cb);
|
2008-03-24 16:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void querystring_cb(const char *name, const char *value)
|
|
|
|
{
|
2009-08-17 07:05:13 +00:00
|
|
|
if (!value)
|
|
|
|
value = "";
|
|
|
|
|
2008-03-24 16:26:08 +00:00
|
|
|
if (!strcmp(name,"r")) {
|
|
|
|
ctx.qry.repo = xstrdup(value);
|
|
|
|
ctx.repo = cgit_get_repoinfo(value);
|
|
|
|
} else if (!strcmp(name, "p")) {
|
|
|
|
ctx.qry.page = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "url")) {
|
2009-09-14 21:37:13 +00:00
|
|
|
if (*value == '/')
|
|
|
|
value++;
|
2008-08-09 19:11:41 +00:00
|
|
|
ctx.qry.url = xstrdup(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
cgit_parse_url(value);
|
|
|
|
} else if (!strcmp(name, "qt")) {
|
|
|
|
ctx.qry.grep = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "q")) {
|
|
|
|
ctx.qry.search = xstrdup(value);
|
|
|
|
} else if (!strcmp(name, "h")) {
|
|
|
|
ctx.qry.head = xstrdup(value);
|
|
|
|
ctx.qry.has_symref = 1;
|
|
|
|
} else if (!strcmp(name, "id")) {
|
|
|
|
ctx.qry.sha1 = xstrdup(value);
|
|
|
|
ctx.qry.has_sha1 = 1;
|
|
|
|
} else if (!strcmp(name, "id2")) {
|
|
|
|
ctx.qry.sha2 = xstrdup(value);
|
|
|
|
ctx.qry.has_sha1 = 1;
|
|
|
|
} else if (!strcmp(name, "ofs")) {
|
|
|
|
ctx.qry.ofs = atoi(value);
|
|
|
|
} else if (!strcmp(name, "path")) {
|
|
|
|
ctx.qry.path = trim_end(value, '/');
|
|
|
|
} else if (!strcmp(name, "name")) {
|
|
|
|
ctx.qry.name = xstrdup(value);
|
2008-06-24 21:42:32 +00:00
|
|
|
} else if (!strcmp(name, "mimetype")) {
|
|
|
|
ctx.qry.mimetype = xstrdup(value);
|
2013-03-04 04:21:33 +00:00
|
|
|
} else if (!strcmp(name, "s")) {
|
2008-11-25 14:25:35 +00:00
|
|
|
ctx.qry.sort = xstrdup(value);
|
2008-11-29 17:39:41 +00:00
|
|
|
} else if (!strcmp(name, "showmsg")) {
|
|
|
|
ctx.qry.showmsg = atoi(value);
|
2008-12-06 16:38:19 +00:00
|
|
|
} else if (!strcmp(name, "period")) {
|
|
|
|
ctx.qry.period = xstrdup(value);
|
2009-09-14 18:19:02 +00:00
|
|
|
} else if (!strcmp(name, "ss")) {
|
|
|
|
ctx.qry.ssdiff = atoi(value);
|
2012-01-03 16:02:14 +00:00
|
|
|
ctx.qry.has_ssdiff = 1;
|
2010-02-04 00:31:17 +00:00
|
|
|
} else if (!strcmp(name, "all")) {
|
|
|
|
ctx.qry.show_all = atoi(value);
|
2010-06-10 18:15:27 +00:00
|
|
|
} else if (!strcmp(name, "context")) {
|
|
|
|
ctx.qry.context = atoi(value);
|
2010-06-24 15:52:57 +00:00
|
|
|
} else if (!strcmp(name, "ignorews")) {
|
|
|
|
ctx.qry.ignorews = atoi(value);
|
2008-03-24 16:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prepare_context(struct cgit_context *ctx)
|
|
|
|
{
|
2010-02-21 13:38:59 +00:00
|
|
|
memset(ctx, 0, sizeof(*ctx));
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.agefile = "info/web/last-modified";
|
2008-04-28 09:32:42 +00:00
|
|
|
ctx->cfg.nocache = 0;
|
|
|
|
ctx->cfg.cache_size = 0;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.cache_max_create_time = 5;
|
|
|
|
ctx->cfg.cache_root = CGIT_CACHE_ROOT;
|
2013-05-28 14:33:30 +00:00
|
|
|
ctx->cfg.cache_about_ttl = 15;
|
|
|
|
ctx->cfg.cache_repo_ttl = 5;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.cache_root_ttl = 5;
|
2009-08-20 15:41:54 +00:00
|
|
|
ctx->cfg.cache_scanrc_ttl = 15;
|
2013-05-28 14:33:30 +00:00
|
|
|
ctx->cfg.cache_dynamic_ttl = 5;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.cache_static_ttl = -1;
|
2012-07-12 17:13:39 +00:00
|
|
|
ctx->cfg.case_sensitive_sort = 1;
|
2013-04-08 14:57:12 +00:00
|
|
|
ctx->cfg.branch_sort = 0;
|
|
|
|
ctx->cfg.commit_sort = 0;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.css = "/cgit.css";
|
2009-08-10 16:14:12 +00:00
|
|
|
ctx->cfg.logo = "/cgit.png";
|
2013-07-22 06:56:50 +00:00
|
|
|
ctx->cfg.favicon = "/favicon.ico";
|
2008-08-01 12:54:38 +00:00
|
|
|
ctx->cfg.local_time = 0;
|
2011-01-12 18:06:07 +00:00
|
|
|
ctx->cfg.enable_http_clone = 1;
|
2013-02-01 09:59:13 +00:00
|
|
|
ctx->cfg.enable_index_owner = 1;
|
2009-08-21 12:26:52 +00:00
|
|
|
ctx->cfg.enable_tree_linenumbers = 1;
|
2012-10-09 10:56:14 +00:00
|
|
|
ctx->cfg.enable_git_config = 0;
|
2008-05-03 08:54:39 +00:00
|
|
|
ctx->cfg.max_repo_count = 50;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.max_commit_count = 50;
|
|
|
|
ctx->cfg.max_lock_attempts = 5;
|
2008-07-27 10:58:37 +00:00
|
|
|
ctx->cfg.max_msg_len = 80;
|
|
|
|
ctx->cfg.max_repodesc_len = 80;
|
2009-11-28 02:44:33 +00:00
|
|
|
ctx->cfg.max_blob_size = 0;
|
2008-12-07 12:17:21 +00:00
|
|
|
ctx->cfg.max_stats = 0;
|
2010-07-29 15:52:29 +00:00
|
|
|
ctx->cfg.project_list = NULL;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.renamelimit = -1;
|
2010-07-29 17:47:50 +00:00
|
|
|
ctx->cfg.remove_suffix = 0;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.robots = "index, nofollow";
|
|
|
|
ctx->cfg.root_title = "Git repository browser";
|
2008-04-28 22:55:34 +00:00
|
|
|
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
|
2010-11-15 19:41:00 +00:00
|
|
|
ctx->cfg.scan_hidden_path = 0;
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
|
2009-08-24 05:42:03 +00:00
|
|
|
ctx->cfg.section = "";
|
2012-10-16 21:32:40 +00:00
|
|
|
ctx->cfg.repository_sort = "name";
|
2012-10-09 18:53:29 +00:00
|
|
|
ctx->cfg.section_sort = 1;
|
2008-07-27 10:58:37 +00:00
|
|
|
ctx->cfg.summary_branches = 10;
|
|
|
|
ctx->cfg.summary_log = 10;
|
|
|
|
ctx->cfg.summary_tags = 10;
|
2010-02-05 00:08:16 +00:00
|
|
|
ctx->cfg.max_atom_items = 10;
|
2009-09-14 18:19:02 +00:00
|
|
|
ctx->cfg.ssdiff = 0;
|
2013-04-01 15:11:15 +00:00
|
|
|
ctx->env.cgit_config = getenv("CGIT_CONFIG");
|
|
|
|
ctx->env.http_host = getenv("HTTP_HOST");
|
|
|
|
ctx->env.https = getenv("HTTPS");
|
|
|
|
ctx->env.no_http = getenv("NO_HTTP");
|
|
|
|
ctx->env.path_info = getenv("PATH_INFO");
|
|
|
|
ctx->env.query_string = getenv("QUERY_STRING");
|
|
|
|
ctx->env.request_method = getenv("REQUEST_METHOD");
|
|
|
|
ctx->env.script_name = getenv("SCRIPT_NAME");
|
|
|
|
ctx->env.server_name = getenv("SERVER_NAME");
|
|
|
|
ctx->env.server_port = getenv("SERVER_PORT");
|
2008-03-24 16:26:08 +00:00
|
|
|
ctx->page.mimetype = "text/html";
|
|
|
|
ctx->page.charset = PAGE_ENCODING;
|
|
|
|
ctx->page.filename = NULL;
|
2008-08-06 08:53:50 +00:00
|
|
|
ctx->page.size = 0;
|
2008-04-28 09:32:42 +00:00
|
|
|
ctx->page.modified = time(NULL);
|
|
|
|
ctx->page.expires = ctx->page.modified;
|
2009-02-19 21:38:36 +00:00
|
|
|
ctx->page.etag = NULL;
|
2009-02-13 19:43:30 +00:00
|
|
|
memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
|
2009-08-10 06:21:09 +00:00
|
|
|
if (ctx->env.script_name)
|
2013-04-01 15:11:14 +00:00
|
|
|
ctx->cfg.script_name = xstrdup(ctx->env.script_name);
|
2009-08-10 06:21:09 +00:00
|
|
|
if (ctx->env.query_string)
|
2013-04-01 15:11:14 +00:00
|
|
|
ctx->qry.raw = xstrdup(ctx->env.query_string);
|
2009-08-10 06:21:09 +00:00
|
|
|
if (!ctx->env.cgit_config)
|
|
|
|
ctx->env.cgit_config = CGIT_CONFIG;
|
2007-01-11 23:00:15 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 12:43:40 +00:00
|
|
|
struct refmatch {
|
|
|
|
char *req_ref;
|
|
|
|
char *first_ref;
|
|
|
|
int match;
|
|
|
|
};
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static int find_current_ref(const char *refname, const unsigned char *sha1,
|
|
|
|
int flags, void *cb_data)
|
2008-01-04 12:43:40 +00:00
|
|
|
{
|
|
|
|
struct refmatch *info;
|
|
|
|
|
|
|
|
info = (struct refmatch *)cb_data;
|
|
|
|
if (!strcmp(refname, info->req_ref))
|
|
|
|
info->match = 1;
|
|
|
|
if (!info->first_ref)
|
|
|
|
info->first_ref = xstrdup(refname);
|
|
|
|
return info->match;
|
|
|
|
}
|
|
|
|
|
2013-03-04 12:25:35 +00:00
|
|
|
static void free_refmatch_inner(struct refmatch *info)
|
|
|
|
{
|
|
|
|
if (info->first_ref)
|
|
|
|
free(info->first_ref);
|
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static char *find_default_branch(struct cgit_repo *repo)
|
2008-01-04 12:43:40 +00:00
|
|
|
{
|
|
|
|
struct refmatch info;
|
2008-07-27 10:32:08 +00:00
|
|
|
char *ref;
|
2008-01-04 12:43:40 +00:00
|
|
|
|
|
|
|
info.req_ref = repo->defbranch;
|
|
|
|
info.first_ref = NULL;
|
|
|
|
info.match = 0;
|
|
|
|
for_each_branch_ref(find_current_ref, &info);
|
|
|
|
if (info.match)
|
2008-07-27 10:32:08 +00:00
|
|
|
ref = info.req_ref;
|
2008-01-04 12:43:40 +00:00
|
|
|
else
|
2008-07-27 10:32:08 +00:00
|
|
|
ref = info.first_ref;
|
|
|
|
if (ref)
|
|
|
|
ref = xstrdup(ref);
|
2013-03-04 12:25:35 +00:00
|
|
|
free_refmatch_inner(&info);
|
|
|
|
|
2008-07-27 10:32:08 +00:00
|
|
|
return ref;
|
2008-01-04 12:43:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 21:42:35 +00:00
|
|
|
static char *guess_defbranch(void)
|
2011-06-20 18:59:10 +00:00
|
|
|
{
|
2011-06-20 22:52:51 +00:00
|
|
|
const char *ref;
|
|
|
|
unsigned char sha1[20];
|
2011-06-20 18:59:10 +00:00
|
|
|
|
2013-03-02 12:32:14 +00:00
|
|
|
ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
|
2011-06-20 22:52:51 +00:00
|
|
|
if (!ref || prefixcmp(ref, "refs/heads/"))
|
|
|
|
return "master";
|
|
|
|
return xstrdup(ref + 11);
|
2011-06-20 18:59:10 +00:00
|
|
|
}
|
2013-05-26 13:20:02 +00:00
|
|
|
/* The caller must free filename and ref after calling this. */
|
|
|
|
static inline void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo)
|
|
|
|
{
|
|
|
|
const char *colon;
|
|
|
|
|
|
|
|
*filename = NULL;
|
|
|
|
*ref = NULL;
|
|
|
|
|
|
|
|
if (!readme || !readme[0])
|
|
|
|
return;
|
2011-06-20 18:59:10 +00:00
|
|
|
|
2013-05-26 13:20:02 +00:00
|
|
|
/* Check if the readme is tracked in the git repo. */
|
|
|
|
colon = strchr(readme, ':');
|
|
|
|
if (colon && strlen(colon) > 1) {
|
|
|
|
/* If it starts with a colon, we want to use
|
|
|
|
* the default branch */
|
|
|
|
if (colon == readme && repo->defbranch)
|
|
|
|
*ref = xstrdup(repo->defbranch);
|
|
|
|
else
|
|
|
|
*ref = xstrndup(readme, colon - readme);
|
|
|
|
readme = colon + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepend repo path to relative readme path unless tracked. */
|
|
|
|
if (!(*ref) && readme[0] != '/')
|
|
|
|
*filename = fmtalloc("%s/%s", repo->path, readme);
|
|
|
|
else
|
|
|
|
*filename = xstrdup(readme);
|
|
|
|
}
|
2013-05-25 14:32:37 +00:00
|
|
|
static void choose_readme(struct cgit_repo *repo)
|
|
|
|
{
|
2013-05-26 13:20:02 +00:00
|
|
|
int found;
|
|
|
|
char *filename, *ref;
|
|
|
|
struct string_list_item *entry;
|
2013-05-25 14:32:37 +00:00
|
|
|
|
2013-05-26 13:20:02 +00:00
|
|
|
if (!repo->readme.nr)
|
2013-05-25 14:32:37 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-26 13:20:02 +00:00
|
|
|
found = 0;
|
|
|
|
for_each_string_list_item(entry, &repo->readme) {
|
|
|
|
parse_readme(entry->string, &filename, &ref, repo);
|
|
|
|
if (!filename) {
|
2013-05-25 14:32:37 +00:00
|
|
|
free(filename);
|
|
|
|
free(ref);
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-26 13:20:02 +00:00
|
|
|
/* If there's only one item, we skip the possibly expensive
|
|
|
|
* selection process. */
|
|
|
|
if (repo->readme.nr == 1) {
|
|
|
|
found = 1;
|
2013-05-25 14:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-26 13:20:02 +00:00
|
|
|
if (ref) {
|
|
|
|
if (cgit_ref_path_exists(filename, ref, 1)) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!access(filename, R_OK)) {
|
|
|
|
found = 1;
|
2013-05-25 14:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(filename);
|
|
|
|
free(ref);
|
|
|
|
}
|
2013-05-26 13:20:02 +00:00
|
|
|
repo->readme.strdup_strings = 1;
|
|
|
|
string_list_clear(&repo->readme, 0);
|
|
|
|
repo->readme.strdup_strings = 0;
|
|
|
|
if (found)
|
|
|
|
string_list_append(&repo->readme, filename)->util = ref;
|
2013-05-25 14:32:37 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
static int prepare_repo_cmd(struct cgit_context *ctx)
|
2006-12-09 14:18:17 +00:00
|
|
|
{
|
2008-01-04 12:43:40 +00:00
|
|
|
unsigned char sha1[20];
|
2008-02-16 20:16:53 +00:00
|
|
|
int nongit = 0;
|
2011-06-18 12:32:43 +00:00
|
|
|
int rc;
|
2007-05-15 22:14:51 +00:00
|
|
|
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 19:12:19 +00:00
|
|
|
/* The path to the git repository. */
|
2008-03-24 00:09:39 +00:00
|
|
|
setenv("GIT_DIR", ctx->repo->path, 1);
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 19:12:19 +00:00
|
|
|
|
|
|
|
/* Do not look in /etc/ for gitconfig and gitattributes. */
|
|
|
|
setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
|
|
|
|
setenv("GIT_ATTR_NOSYSTEM", "1", 1);
|
|
|
|
unsetenv("HOME");
|
|
|
|
unsetenv("XDG_CONFIG_HOME");
|
|
|
|
|
|
|
|
/* Setup the git directory and initialize the notes system. Both of these
|
|
|
|
* load local configuration from the git repository, so we do them both while
|
|
|
|
* the HOME variables are unset. */
|
2008-02-16 20:16:53 +00:00
|
|
|
setup_git_directory_gently(&nongit);
|
Do not load user or system gitconfig and gitattributes
While doing any kind of git loading, unset HOME variables and set
NOSYSTEM variables so that cgit does not load any settings that a user
may have set for his own /usr/bin/git usage.
This fixes a fatal error introduced with git 1.8, whereupon git would
fatally exit when failing to access particular files.
The result of this is that only repo-local configuration files are
accessed:
zx2c4@thinkpad ~/Projects/cgit $ HOME=/root QUERY_STRING="url=foo/log"
CGIT_CONFIG=tests/trash/cgitrc strace -e access ./cgit >/dev/null
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
access("repos/foo/.git/objects", X_OK) = 0
access("repos/foo/.git/refs", X_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/config", R_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
access("repos/foo/.git/objects/b3/bafdbf0183f4897ef8b1319cb8c490ed54717e", F_OK) = 0
+++ exited with 0 +++
Reported-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2013-04-08 19:12:19 +00:00
|
|
|
init_display_notes(NULL);
|
|
|
|
|
2008-02-16 20:16:53 +00:00
|
|
|
if (nongit) {
|
2013-04-06 10:23:52 +00:00
|
|
|
const char *name = ctx->repo->name;
|
2011-06-18 12:32:43 +00:00
|
|
|
rc = errno;
|
2013-04-06 09:28:57 +00:00
|
|
|
ctx->page.title = fmtalloc("%s - %s", ctx->cfg.root_title,
|
|
|
|
"config error");
|
2008-03-24 00:09:39 +00:00
|
|
|
ctx->repo = NULL;
|
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
2013-04-06 10:23:52 +00:00
|
|
|
cgit_print_error("Failed to open %s: %s", name,
|
|
|
|
rc ? strerror(rc) : "Not a valid git repository");
|
2006-12-09 14:18:17 +00:00
|
|
|
cgit_print_docend();
|
2008-03-24 00:09:39 +00:00
|
|
|
return 1;
|
2006-12-09 14:18:17 +00:00
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
ctx->page.title = fmtalloc("%s - %s", ctx->repo->name, ctx->repo->desc);
|
2007-02-03 14:02:55 +00:00
|
|
|
|
2011-06-20 18:59:10 +00:00
|
|
|
if (!ctx->repo->defbranch)
|
2013-03-03 21:42:35 +00:00
|
|
|
ctx->repo->defbranch = guess_defbranch();
|
2011-06-20 18:59:10 +00:00
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
if (!ctx->qry.head) {
|
2008-10-11 17:05:50 +00:00
|
|
|
ctx->qry.nohead = 1;
|
2008-07-27 10:32:08 +00:00
|
|
|
ctx->qry.head = find_default_branch(ctx->repo);
|
2008-01-04 12:43:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
if (!ctx->qry.head) {
|
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
2008-01-04 12:43:40 +00:00
|
|
|
cgit_print_error("Repository seems to be empty");
|
|
|
|
cgit_print_docend();
|
2008-03-24 00:09:39 +00:00
|
|
|
return 1;
|
2008-01-04 12:43:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
if (get_sha1(ctx->qry.head, sha1)) {
|
2013-04-06 10:23:52 +00:00
|
|
|
char *tmp = xstrdup(ctx->qry.head);
|
2008-03-24 00:09:39 +00:00
|
|
|
ctx->qry.head = ctx->repo->defbranch;
|
2009-06-07 18:43:08 +00:00
|
|
|
ctx->page.status = 404;
|
2011-01-12 18:06:08 +00:00
|
|
|
ctx->page.statusmsg = "Not found";
|
2008-03-24 00:09:39 +00:00
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
2013-04-06 10:23:52 +00:00
|
|
|
cgit_print_error("Invalid branch: %s", tmp);
|
2008-01-04 12:43:40 +00:00
|
|
|
cgit_print_docend();
|
2008-03-24 00:09:39 +00:00
|
|
|
return 1;
|
2008-01-04 12:43:40 +00:00
|
|
|
}
|
2011-06-15 08:04:13 +00:00
|
|
|
sort_string_list(&ctx->repo->submodules);
|
2011-06-06 19:29:58 +00:00
|
|
|
cgit_prepare_repo_env(ctx->repo);
|
2013-05-25 14:32:37 +00:00
|
|
|
choose_readme(ctx->repo);
|
2008-03-24 00:09:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-04 12:43:40 +00:00
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
static void process_request(void *cbdata)
|
2008-03-24 00:09:39 +00:00
|
|
|
{
|
2008-04-28 09:32:42 +00:00
|
|
|
struct cgit_context *ctx = cbdata;
|
2008-03-24 00:09:39 +00:00
|
|
|
struct cgit_cmd *cmd;
|
|
|
|
|
|
|
|
cmd = cgit_get_cmd(ctx);
|
|
|
|
if (!cmd) {
|
|
|
|
ctx->page.title = "cgit error";
|
2011-01-12 18:06:08 +00:00
|
|
|
ctx->page.status = 404;
|
|
|
|
ctx->page.statusmsg = "Not found";
|
2008-03-24 00:09:39 +00:00
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
|
|
|
cgit_print_error("Invalid request");
|
|
|
|
cgit_print_docend();
|
2007-02-08 12:53:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-12 18:06:07 +00:00
|
|
|
if (!ctx->cfg.enable_http_clone && cmd->is_clone) {
|
|
|
|
html_status(404, "Not found", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:26 +00:00
|
|
|
/* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
|
|
|
|
* in-project path limit to be made available at ctx->qry.vpath.
|
|
|
|
* Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
|
|
|
|
*/
|
|
|
|
ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL;
|
|
|
|
|
2008-04-28 23:01:30 +00:00
|
|
|
if (cmd->want_repo && !ctx->repo) {
|
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
2013-04-06 10:23:52 +00:00
|
|
|
cgit_print_error("No repository selected");
|
2008-04-28 23:01:30 +00:00
|
|
|
cgit_print_docend();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->repo && prepare_repo_cmd(ctx))
|
2007-12-10 20:47:29 +00:00
|
|
|
return;
|
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
if (cmd->want_layout) {
|
|
|
|
cgit_print_http_headers(ctx);
|
|
|
|
cgit_print_docstart(ctx);
|
|
|
|
cgit_print_pageheader(ctx);
|
2007-05-18 01:00:54 +00:00
|
|
|
}
|
2007-02-17 12:46:18 +00:00
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
cmd->fn(ctx);
|
2007-02-17 12:46:18 +00:00
|
|
|
|
2008-03-24 00:09:39 +00:00
|
|
|
if (cmd->want_layout)
|
|
|
|
cgit_print_docend();
|
2006-12-09 14:18:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static int cmp_repos(const void *a, const void *b)
|
2008-09-14 22:07:12 +00:00
|
|
|
{
|
|
|
|
const struct cgit_repo *ra = a, *rb = b;
|
|
|
|
return strcmp(ra->url, rb->url);
|
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static char *build_snapshot_setting(int bitmap)
|
2009-08-24 08:55:01 +00:00
|
|
|
{
|
|
|
|
const struct cgit_snapshot_format *f;
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf result = STRBUF_INIT;
|
2009-08-24 08:55:01 +00:00
|
|
|
|
|
|
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
|
|
|
if (f->bit & bitmap) {
|
2013-04-06 09:28:57 +00:00
|
|
|
if (result.len)
|
|
|
|
strbuf_addch(&result, ' ');
|
|
|
|
strbuf_addstr(&result, f->suffix);
|
2009-08-24 08:55:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
return strbuf_detach(&result, NULL);
|
2009-08-24 08:55:01 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static char *get_first_line(char *txt)
|
2009-08-24 11:27:15 +00:00
|
|
|
{
|
|
|
|
char *t = xstrdup(txt);
|
|
|
|
char *p = strchr(t, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void print_repo(FILE *f, struct cgit_repo *repo)
|
2008-09-14 22:07:12 +00:00
|
|
|
{
|
2013-05-26 13:20:02 +00:00
|
|
|
struct string_list_item *item;
|
2009-08-19 15:47:24 +00:00
|
|
|
fprintf(f, "repo.url=%s\n", repo->url);
|
|
|
|
fprintf(f, "repo.name=%s\n", repo->name);
|
|
|
|
fprintf(f, "repo.path=%s\n", repo->path);
|
2008-09-14 22:07:12 +00:00
|
|
|
if (repo->owner)
|
2009-08-19 15:47:24 +00:00
|
|
|
fprintf(f, "repo.owner=%s\n", repo->owner);
|
2009-08-24 11:27:15 +00:00
|
|
|
if (repo->desc) {
|
|
|
|
char *tmp = get_first_line(repo->desc);
|
|
|
|
fprintf(f, "repo.desc=%s\n", tmp);
|
|
|
|
free(tmp);
|
|
|
|
}
|
2013-05-26 13:20:02 +00:00
|
|
|
for_each_string_list_item(item, &repo->readme) {
|
|
|
|
if (item->util)
|
|
|
|
fprintf(f, "repo.readme=%s:%s\n", (char *)item->util, item->string);
|
|
|
|
else
|
|
|
|
fprintf(f, "repo.readme=%s\n", item->string);
|
|
|
|
}
|
2009-08-24 08:22:21 +00:00
|
|
|
if (repo->defbranch)
|
|
|
|
fprintf(f, "repo.defbranch=%s\n", repo->defbranch);
|
|
|
|
if (repo->module_link)
|
|
|
|
fprintf(f, "repo.module-link=%s\n", repo->module_link);
|
|
|
|
if (repo->section)
|
|
|
|
fprintf(f, "repo.section=%s\n", repo->section);
|
|
|
|
if (repo->clone_url)
|
|
|
|
fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
|
2010-11-15 17:39:50 +00:00
|
|
|
fprintf(f, "repo.enable-commit-graph=%d\n",
|
|
|
|
repo->enable_commit_graph);
|
2009-08-24 08:22:21 +00:00
|
|
|
fprintf(f, "repo.enable-log-filecount=%d\n",
|
|
|
|
repo->enable_log_filecount);
|
|
|
|
fprintf(f, "repo.enable-log-linecount=%d\n",
|
|
|
|
repo->enable_log_linecount);
|
|
|
|
if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter)
|
|
|
|
fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd);
|
|
|
|
if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter)
|
|
|
|
fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd);
|
|
|
|
if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
|
|
|
|
fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd);
|
2009-08-24 08:55:01 +00:00
|
|
|
if (repo->snapshots != ctx.cfg.snapshots) {
|
|
|
|
char *tmp = build_snapshot_setting(repo->snapshots);
|
2013-04-06 09:28:57 +00:00
|
|
|
fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
|
2009-08-24 08:55:01 +00:00
|
|
|
free(tmp);
|
|
|
|
}
|
2009-08-24 09:02:48 +00:00
|
|
|
if (repo->max_stats != ctx.cfg.max_stats)
|
|
|
|
fprintf(f, "repo.max-stats=%s\n",
|
|
|
|
cgit_find_stats_periodname(repo->max_stats));
|
2013-05-25 12:05:06 +00:00
|
|
|
if (repo->logo)
|
|
|
|
fprintf(f, "repo.logo=%s\n", repo->logo);
|
|
|
|
if (repo->logo_link)
|
|
|
|
fprintf(f, "repo.logo-link=%s\n", repo->logo_link);
|
|
|
|
fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches);
|
|
|
|
fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links);
|
|
|
|
if (repo->branch_sort == 1)
|
|
|
|
fprintf(f, "repo.branch-sort=age\n");
|
|
|
|
if (repo->commit_sort) {
|
|
|
|
if (repo->commit_sort == 1)
|
|
|
|
fprintf(f, "repo.commit-sort=date\n");
|
|
|
|
else if (repo->commit_sort == 2)
|
|
|
|
fprintf(f, "repo.commit-sort=topo\n");
|
|
|
|
}
|
2009-08-19 15:47:24 +00:00
|
|
|
fprintf(f, "\n");
|
2008-09-14 22:07:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void print_repolist(FILE *f, struct cgit_repolist *list, int start)
|
2008-09-14 22:07:12 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-03-04 04:21:33 +00:00
|
|
|
for (i = start; i < list->count; i++)
|
2009-08-19 15:47:24 +00:00
|
|
|
print_repo(f, &list->repos[i]);
|
2008-09-14 22:07:12 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 15:41:54 +00:00
|
|
|
/* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc'
|
|
|
|
* and return 0 on success.
|
|
|
|
*/
|
|
|
|
static int generate_cached_repolist(const char *path, const char *cached_rc)
|
|
|
|
{
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf locked_rc = STRBUF_INIT;
|
|
|
|
int result = 0;
|
2009-08-20 15:41:54 +00:00
|
|
|
int idx;
|
|
|
|
FILE *f;
|
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&locked_rc, "%s.lock", cached_rc);
|
|
|
|
f = fopen(locked_rc.buf, "wx");
|
2009-08-20 15:41:54 +00:00
|
|
|
if (!f) {
|
|
|
|
/* Inform about the error unless the lockfile already existed,
|
|
|
|
* since that only means we've got concurrent requests.
|
|
|
|
*/
|
2013-04-06 09:28:57 +00:00
|
|
|
result = errno;
|
|
|
|
if (result != EEXIST)
|
2009-08-20 15:41:54 +00:00
|
|
|
fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
|
2013-04-06 09:28:57 +00:00
|
|
|
locked_rc.buf, strerror(result), result);
|
|
|
|
goto out;
|
2009-08-20 15:41:54 +00:00
|
|
|
}
|
|
|
|
idx = cgit_repolist.count;
|
2010-07-29 15:52:29 +00:00
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
scan_projects(path, ctx.cfg.project_list, repo_config);
|
|
|
|
else
|
|
|
|
scan_tree(path, repo_config);
|
2009-08-20 15:41:54 +00:00
|
|
|
print_repolist(f, &cgit_repolist, idx);
|
2013-04-06 09:28:57 +00:00
|
|
|
if (rename(locked_rc.buf, cached_rc))
|
2009-08-20 15:41:54 +00:00
|
|
|
fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
|
2013-04-06 09:28:57 +00:00
|
|
|
locked_rc.buf, cached_rc, strerror(errno), errno);
|
2009-08-20 15:41:54 +00:00
|
|
|
fclose(f);
|
2013-04-06 09:28:57 +00:00
|
|
|
out:
|
|
|
|
strbuf_release(&locked_rc);
|
|
|
|
return result;
|
2008-09-14 22:07:12 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 15:41:54 +00:00
|
|
|
static void process_cached_repolist(const char *path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf cached_rc = STRBUF_INIT;
|
2009-08-20 15:41:54 +00:00
|
|
|
time_t age;
|
2010-07-29 15:52:29 +00:00
|
|
|
unsigned long hash;
|
2009-08-20 15:41:54 +00:00
|
|
|
|
2010-07-29 15:52:29 +00:00
|
|
|
hash = hash_str(path);
|
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
hash += hash_str(ctx.cfg.project_list);
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&cached_rc, "%s/rc-%8lx", ctx.cfg.cache_root, hash);
|
2009-08-20 15:41:54 +00:00
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
if (stat(cached_rc.buf, &st)) {
|
2009-08-20 15:41:54 +00:00
|
|
|
/* Nothing is cached, we need to scan without forking. And
|
|
|
|
* if we fail to generate a cached repolist, we need to
|
|
|
|
* invoke scan_tree manually.
|
|
|
|
*/
|
2013-04-06 09:28:57 +00:00
|
|
|
if (generate_cached_repolist(path, cached_rc.buf)) {
|
2010-07-29 15:52:29 +00:00
|
|
|
if (ctx.cfg.project_list)
|
|
|
|
scan_projects(path, ctx.cfg.project_list,
|
|
|
|
repo_config);
|
|
|
|
else
|
|
|
|
scan_tree(path, repo_config);
|
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
goto out;
|
2009-08-20 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
parse_configfile(cached_rc.buf, config_cb);
|
2009-08-20 15:41:54 +00:00
|
|
|
|
|
|
|
/* If the cached configfile hasn't expired, lets exit now */
|
|
|
|
age = time(NULL) - st.st_mtime;
|
|
|
|
if (age <= (ctx.cfg.cache_scanrc_ttl * 60))
|
2013-04-06 09:28:57 +00:00
|
|
|
goto out;
|
2009-08-20 15:41:54 +00:00
|
|
|
|
|
|
|
/* The cached repolist has been parsed, but it was old. So lets
|
|
|
|
* rescan the specified path and generate a new cached repolist
|
|
|
|
* in a child-process to avoid latency for the current request.
|
|
|
|
*/
|
|
|
|
if (fork())
|
2013-04-06 09:28:57 +00:00
|
|
|
goto out;
|
2009-08-20 15:41:54 +00:00
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
exit(generate_cached_repolist(path, cached_rc.buf));
|
|
|
|
out:
|
|
|
|
strbuf_release(&cached_rc);
|
2009-08-20 15:41:54 +00:00
|
|
|
}
|
2008-09-14 22:07:12 +00:00
|
|
|
|
2006-12-16 12:33:32 +00:00
|
|
|
static void cgit_parse_args(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2008-09-14 22:07:12 +00:00
|
|
|
int scan = 0;
|
2006-12-16 12:33:32 +00:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!strncmp(argv[i], "--cache=", 8)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.cfg.cache_root = xstrdup(argv[i] + 8);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--nocache")) {
|
2008-02-16 12:07:13 +00:00
|
|
|
ctx.cfg.nocache = 1;
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
2009-08-10 07:20:17 +00:00
|
|
|
if (!strcmp(argv[i], "--nohttp")) {
|
|
|
|
ctx.env.no_http = "1";
|
|
|
|
}
|
2006-12-16 12:33:32 +00:00
|
|
|
if (!strncmp(argv[i], "--query=", 8)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.raw = xstrdup(argv[i] + 8);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strncmp(argv[i], "--repo=", 7)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.repo = xstrdup(argv[i] + 7);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strncmp(argv[i], "--page=", 7)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.page = xstrdup(argv[i] + 7);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strncmp(argv[i], "--head=", 7)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.head = xstrdup(argv[i] + 7);
|
2008-02-16 10:53:40 +00:00
|
|
|
ctx.qry.has_symref = 1;
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strncmp(argv[i], "--sha1=", 7)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.sha1 = xstrdup(argv[i] + 7);
|
2008-02-16 10:53:40 +00:00
|
|
|
ctx.qry.has_sha1 = 1;
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
if (!strncmp(argv[i], "--ofs=", 6)) {
|
2013-03-03 15:04:29 +00:00
|
|
|
ctx.qry.ofs = atoi(argv[i] + 6);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
2009-08-23 17:36:45 +00:00
|
|
|
if (!strncmp(argv[i], "--scan-tree=", 12) ||
|
|
|
|
!strncmp(argv[i], "--scan-path=", 12)) {
|
2009-08-24 11:31:49 +00:00
|
|
|
/* HACK: the global snapshot bitmask defines the
|
|
|
|
* set of allowed snapshot formats, but the config
|
|
|
|
* file hasn't been parsed yet so the mask is
|
|
|
|
* currently 0. By setting all bits high before
|
|
|
|
* scanning we make sure that any in-repo cgitrc
|
|
|
|
* snapshot setting is respected by scan_tree().
|
|
|
|
* BTW: we assume that there'll never be more than
|
|
|
|
* 255 different snapshot formats supported by cgit...
|
|
|
|
*/
|
|
|
|
ctx.cfg.snapshots = 0xFF;
|
2008-09-14 22:07:12 +00:00
|
|
|
scan++;
|
2009-08-23 22:04:58 +00:00
|
|
|
scan_tree(argv[i] + 12, repo_config);
|
2008-09-14 22:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scan) {
|
|
|
|
qsort(cgit_repolist.repos, cgit_repolist.count,
|
|
|
|
sizeof(struct cgit_repo), cmp_repos);
|
2009-08-19 15:47:24 +00:00
|
|
|
print_repolist(stdout, &cgit_repolist, 0);
|
2008-09-14 22:07:12 +00:00
|
|
|
exit(0);
|
2006-12-16 12:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
static int calc_ttl()
|
|
|
|
{
|
|
|
|
if (!ctx.repo)
|
|
|
|
return ctx.cfg.cache_root_ttl;
|
|
|
|
|
|
|
|
if (!ctx.qry.page)
|
|
|
|
return ctx.cfg.cache_repo_ttl;
|
|
|
|
|
2013-05-28 14:33:30 +00:00
|
|
|
if (!strcmp(ctx.qry.page, "about"))
|
|
|
|
return ctx.cfg.cache_about_ttl;
|
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
if (ctx.qry.has_sha1)
|
|
|
|
return ctx.cfg.cache_static_ttl;
|
|
|
|
|
2013-05-28 14:43:02 +00:00
|
|
|
if (ctx.qry.has_symref)
|
|
|
|
return ctx.cfg.cache_dynamic_ttl;
|
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
return ctx.cfg.cache_repo_ttl;
|
|
|
|
}
|
|
|
|
|
2006-12-10 21:31:36 +00:00
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
2008-08-09 19:11:41 +00:00
|
|
|
const char *path;
|
2008-04-28 09:32:42 +00:00
|
|
|
int err, ttl;
|
2006-12-11 16:25:41 +00:00
|
|
|
|
2008-03-24 16:26:08 +00:00
|
|
|
prepare_context(&ctx);
|
2007-02-03 14:02:55 +00:00
|
|
|
cgit_repolist.length = 0;
|
|
|
|
cgit_repolist.count = 0;
|
|
|
|
cgit_repolist.repos = NULL;
|
|
|
|
|
2006-12-16 12:33:32 +00:00
|
|
|
cgit_parse_args(argc, argv);
|
2010-03-21 23:09:43 +00:00
|
|
|
parse_configfile(expand_macros(ctx.env.cgit_config), config_cb);
|
2008-09-14 22:07:12 +00:00
|
|
|
ctx.repo = NULL;
|
2008-04-08 19:11:36 +00:00
|
|
|
http_parse_querystring(ctx.qry.raw, querystring_cb);
|
2008-04-28 09:32:42 +00:00
|
|
|
|
2008-12-26 09:33:01 +00:00
|
|
|
/* If virtual-root isn't specified in cgitrc, lets pretend
|
2011-03-05 12:47:04 +00:00
|
|
|
* that virtual-root equals SCRIPT_NAME, minus any possibly
|
|
|
|
* trailing slashes.
|
2008-08-09 19:11:41 +00:00
|
|
|
*/
|
2013-04-01 18:03:34 +00:00
|
|
|
if (!ctx.cfg.virtual_root && ctx.cfg.script_name)
|
|
|
|
ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/');
|
2008-12-26 09:33:01 +00:00
|
|
|
|
|
|
|
/* If no url parameter is specified on the querystring, lets
|
|
|
|
* use PATH_INFO as url. This allows cgit to work with virtual
|
|
|
|
* urls without the need for rewriterules in the webserver (as
|
|
|
|
* long as PATH_INFO is included in the cache lookup key).
|
|
|
|
*/
|
2009-08-10 06:21:09 +00:00
|
|
|
path = ctx.env.path_info;
|
2008-12-26 09:33:01 +00:00
|
|
|
if (!ctx.qry.url && path) {
|
|
|
|
if (path[0] == '/')
|
|
|
|
path++;
|
|
|
|
ctx.qry.url = xstrdup(path);
|
|
|
|
if (ctx.qry.raw) {
|
2013-04-06 09:28:57 +00:00
|
|
|
char *newqry = fmtalloc("%s?%s", path, ctx.qry.raw);
|
|
|
|
free(ctx.qry.raw);
|
|
|
|
ctx.qry.raw = newqry;
|
2008-12-26 09:33:01 +00:00
|
|
|
} else
|
2009-08-20 08:07:51 +00:00
|
|
|
ctx.qry.raw = xstrdup(ctx.qry.url);
|
2008-12-26 09:33:01 +00:00
|
|
|
cgit_parse_url(ctx.qry.url);
|
2008-08-09 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
ttl = calc_ttl();
|
2013-05-28 14:33:30 +00:00
|
|
|
if (ttl < 0)
|
|
|
|
ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */
|
|
|
|
else
|
|
|
|
ctx.page.expires += ttl * 60;
|
2009-08-10 06:21:09 +00:00
|
|
|
if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
|
2009-02-19 22:24:15 +00:00
|
|
|
ctx.cfg.nocache = 1;
|
2008-04-28 09:32:42 +00:00
|
|
|
if (ctx.cfg.nocache)
|
|
|
|
ctx.cfg.cache_size = 0;
|
|
|
|
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
|
|
|
|
ctx.qry.raw, ttl, process_request, &ctx);
|
|
|
|
if (err)
|
2013-04-06 10:23:52 +00:00
|
|
|
cgit_print_error("Error processing page: %s (%d)",
|
|
|
|
strerror(err), err);
|
2008-04-28 09:32:42 +00:00
|
|
|
return err;
|
2006-12-09 14:18:17 +00:00
|
|
|
}
|