aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2008-02-16 21:07:13 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2008-02-16 21:10:50 (JST)
commitb228d4ff82a65fdcd4a7364759fe36a0bdda5978 (patch)
tree33b8cc2ff48113f8d7ad3ba88c7ea19a7cac570a /shared.c
parentd14d77fe95c3b6224b40df9b101dded0deea913c (diff)
downloadcgit-b228d4ff82a65fdcd4a7364759fe36a0bdda5978.zip
cgit-b228d4ff82a65fdcd4a7364759fe36a0bdda5978.tar.gz
Add all config variables into struct cgit_context
This removes another big set of global variables, and introduces the cgit_prepare_context() function which populates a context-variable with compile-time default values. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c138
1 files changed, 63 insertions, 75 deletions
diff --git a/shared.c b/shared.c
index 6c1a762..8dd2b00 100644
--- a/shared.c
+++ b/shared.c
@@ -15,43 +15,31 @@ int cgit_cmd;
15 15
16const char *cgit_version = CGIT_VERSION; 16const char *cgit_version = CGIT_VERSION;
17 17
18char *cgit_root_title = "Git repository browser";
19char *cgit_css = "/cgit.css";
20char *cgit_logo = "/git-logo.png";
21char *cgit_index_header = NULL;
22char *cgit_index_info = NULL;
23char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
24char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
25char *cgit_agefile = "info/web/last-modified";
26char *cgit_virtual_root = NULL;
27char *cgit_script_name = CGIT_SCRIPT_NAME;
28char *cgit_cache_root = CGIT_CACHE_ROOT;
29char *cgit_repo_group = NULL;
30char *cgit_robots = "index, nofollow";
31char *cgit_clone_prefix = NULL;
32
33int cgit_nocache = 0;
34int cgit_snapshots = 0;
35int cgit_enable_index_links = 0;
36int cgit_enable_log_filecount = 0;
37int cgit_enable_log_linecount = 0;
38int cgit_max_lock_attempts = 5;
39int cgit_cache_root_ttl = 5;
40int cgit_cache_repo_ttl = 5;
41int cgit_cache_dynamic_ttl = 5;
42int cgit_cache_static_ttl = -1;
43int cgit_cache_max_create_time = 5;
44int cgit_summary_log = 0;
45int cgit_summary_tags = 0;
46int cgit_summary_branches = 0;
47int cgit_renamelimit = -1;
48
49int cgit_max_msg_len = 60;
50int cgit_max_repodesc_len = 60;
51int cgit_max_commit_count = 50;
52
53int htmlfd = 0; 18int htmlfd = 0;
54 19
20void cgit_prepare_context(struct cgit_context *ctx)
21{
22 memset(ctx, 0, sizeof(ctx));
23 ctx->cfg.agefile = "info/web/last-modified";
24 ctx->cfg.cache_dynamic_ttl = 5;
25 ctx->cfg.cache_max_create_time = 5;
26 ctx->cfg.cache_repo_ttl = 5;
27 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
28 ctx->cfg.cache_root_ttl = 5;
29 ctx->cfg.cache_static_ttl = -1;
30 ctx->cfg.css = "/cgit.css";
31 ctx->cfg.logo = "/git-logo.png";
32 ctx->cfg.max_commit_count = 50;
33 ctx->cfg.max_lock_attempts = 5;
34 ctx->cfg.max_msg_len = 60;
35 ctx->cfg.max_repodesc_len = 60;
36 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
37 ctx->cfg.renamelimit = -1;
38 ctx->cfg.robots = "index, nofollow";
39 ctx->cfg.root_title = "Git repository browser";
40 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
41}
42
55int cgit_get_cmd_index(const char *cmd) 43int cgit_get_cmd_index(const char *cmd)
56{ 44{
57 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 45 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
@@ -105,12 +93,12 @@ struct repoinfo *add_repo(const char *url)
105 ret->path = NULL; 93 ret->path = NULL;
106 ret->desc = "[no description]"; 94 ret->desc = "[no description]";
107 ret->owner = NULL; 95 ret->owner = NULL;
108 ret->group = cgit_repo_group; 96 ret->group = ctx.cfg.repo_group;
109 ret->defbranch = "master"; 97 ret->defbranch = "master";
110 ret->snapshots = cgit_snapshots; 98 ret->snapshots = ctx.cfg.snapshots;
111 ret->enable_log_filecount = cgit_enable_log_filecount; 99 ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
112 ret->enable_log_linecount = cgit_enable_log_linecount; 100 ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
113 ret->module_link = cgit_module_link; 101 ret->module_link = ctx.cfg.module_link;
114 ret->readme = NULL; 102 ret->readme = NULL;
115 return ret; 103 return ret;
116} 104}
@@ -131,65 +119,65 @@ struct repoinfo *cgit_get_repoinfo(const char *url)
131void cgit_global_config_cb(const char *name, const char *value) 119void cgit_global_config_cb(const char *name, const char *value)
132{ 120{
133 if (!strcmp(name, "root-title")) 121 if (!strcmp(name, "root-title"))
134 cgit_root_title = xstrdup(value); 122 ctx.cfg.root_title = xstrdup(value);
135 else if (!strcmp(name, "css")) 123 else if (!strcmp(name, "css"))
136 cgit_css = xstrdup(value); 124 ctx.cfg.css = xstrdup(value);
137 else if (!strcmp(name, "logo")) 125 else if (!strcmp(name, "logo"))
138 cgit_logo = xstrdup(value); 126 ctx.cfg.logo = xstrdup(value);
139 else if (!strcmp(name, "index-header")) 127 else if (!strcmp(name, "index-header"))
140 cgit_index_header = xstrdup(value); 128 ctx.cfg.index_header = xstrdup(value);
141 else if (!strcmp(name, "index-info")) 129 else if (!strcmp(name, "index-info"))
142 cgit_index_info = xstrdup(value); 130 ctx.cfg.index_info = xstrdup(value);
143 else if (!strcmp(name, "logo-link")) 131 else if (!strcmp(name, "logo-link"))
144 cgit_logo_link = xstrdup(value); 132 ctx.cfg.logo_link = xstrdup(value);
145 else if (!strcmp(name, "module-link")) 133 else if (!strcmp(name, "module-link"))
146 cgit_module_link = xstrdup(value); 134 ctx.cfg.module_link = xstrdup(value);
147 else if (!strcmp(name, "virtual-root")) { 135 else if (!strcmp(name, "virtual-root")) {
148 cgit_virtual_root = trim_end(value, '/'); 136 ctx.cfg.virtual_root = trim_end(value, '/');
149 if (!cgit_virtual_root && (!strcmp(value, "/"))) 137 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
150 cgit_virtual_root = ""; 138 ctx.cfg.virtual_root = "";
151 } else if (!strcmp(name, "nocache")) 139 } else if (!strcmp(name, "nocache"))
152 cgit_nocache = atoi(value); 140 ctx.cfg.nocache = atoi(value);
153 else if (!strcmp(name, "snapshots")) 141 else if (!strcmp(name, "snapshots"))
154 cgit_snapshots = cgit_parse_snapshots_mask(value); 142 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
155 else if (!strcmp(name, "enable-index-links")) 143 else if (!strcmp(name, "enable-index-links"))
156 cgit_enable_index_links = atoi(value); 144 ctx.cfg.enable_index_links = atoi(value);
157 else if (!strcmp(name, "enable-log-filecount")) 145 else if (!strcmp(name, "enable-log-filecount"))
158 cgit_enable_log_filecount = atoi(value); 146 ctx.cfg.enable_log_filecount = atoi(value);
159 else if (!strcmp(name, "enable-log-linecount")) 147 else if (!strcmp(name, "enable-log-linecount"))
160 cgit_enable_log_linecount = atoi(value); 148 ctx.cfg.enable_log_linecount = atoi(value);
161 else if (!strcmp(name, "cache-root")) 149 else if (!strcmp(name, "cache-root"))
162 cgit_cache_root = xstrdup(value); 150 ctx.cfg.cache_root = xstrdup(value);
163 else if (!strcmp(name, "cache-root-ttl")) 151 else if (!strcmp(name, "cache-root-ttl"))
164 cgit_cache_root_ttl = atoi(value); 152 ctx.cfg.cache_root_ttl = atoi(value);
165 else if (!strcmp(name, "cache-repo-ttl")) 153 else if (!strcmp(name, "cache-repo-ttl"))
166 cgit_cache_repo_ttl = atoi(value); 154 ctx.cfg.cache_repo_ttl = atoi(value);
167 else if (!strcmp(name, "cache-static-ttl")) 155 else if (!strcmp(name, "cache-static-ttl"))
168 cgit_cache_static_ttl = atoi(value); 156 ctx.cfg.cache_static_ttl = atoi(value);
169 else if (!strcmp(name, "cache-dynamic-ttl")) 157 else if (!strcmp(name, "cache-dynamic-ttl"))
170 cgit_cache_dynamic_ttl = atoi(value); 158 ctx.cfg.cache_dynamic_ttl = atoi(value);
171 else if (!strcmp(name, "max-message-length")) 159 else if (!strcmp(name, "max-message-length"))
172 cgit_max_msg_len = atoi(value); 160 ctx.cfg.max_msg_len = atoi(value);
173 else if (!strcmp(name, "max-repodesc-length")) 161 else if (!strcmp(name, "max-repodesc-length"))
174 cgit_max_repodesc_len = atoi(value); 162 ctx.cfg.max_repodesc_len = atoi(value);
175 else if (!strcmp(name, "max-commit-count")) 163 else if (!strcmp(name, "max-commit-count"))
176 cgit_max_commit_count = atoi(value); 164 ctx.cfg.max_commit_count = atoi(value);
177 else if (!strcmp(name, "summary-log")) 165 else if (!strcmp(name, "summary-log"))
178 cgit_summary_log = atoi(value); 166 ctx.cfg.summary_log = atoi(value);
179 else if (!strcmp(name, "summary-branches")) 167 else if (!strcmp(name, "summary-branches"))
180 cgit_summary_branches = atoi(value); 168 ctx.cfg.summary_branches = atoi(value);
181 else if (!strcmp(name, "summary-tags")) 169 else if (!strcmp(name, "summary-tags"))
182 cgit_summary_tags = atoi(value); 170 ctx.cfg.summary_tags = atoi(value);
183 else if (!strcmp(name, "agefile")) 171 else if (!strcmp(name, "agefile"))
184 cgit_agefile = xstrdup(value); 172 ctx.cfg.agefile = xstrdup(value);
185 else if (!strcmp(name, "renamelimit")) 173 else if (!strcmp(name, "renamelimit"))
186 cgit_renamelimit = atoi(value); 174 ctx.cfg.renamelimit = atoi(value);
187 else if (!strcmp(name, "robots")) 175 else if (!strcmp(name, "robots"))
188 cgit_robots = xstrdup(value); 176 ctx.cfg.robots = xstrdup(value);
189 else if (!strcmp(name, "clone-prefix")) 177 else if (!strcmp(name, "clone-prefix"))
190 cgit_clone_prefix = xstrdup(value); 178 ctx.cfg.clone_prefix = xstrdup(value);
191 else if (!strcmp(name, "repo.group")) 179 else if (!strcmp(name, "repo.group"))
192 cgit_repo_group = xstrdup(value); 180 ctx.cfg.repo_group = xstrdup(value);
193 else if (!strcmp(name, "repo.url")) 181 else if (!strcmp(name, "repo.url"))
194 cgit_repo = add_repo(value); 182 cgit_repo = add_repo(value);
195 else if (!strcmp(name, "repo.name")) 183 else if (!strcmp(name, "repo.name"))
@@ -205,11 +193,11 @@ void cgit_global_config_cb(const char *name, const char *value)
205 else if (cgit_repo && !strcmp(name, "repo.defbranch")) 193 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
206 cgit_repo->defbranch = xstrdup(value); 194 cgit_repo->defbranch = xstrdup(value);
207 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 195 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
208 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 196 cgit_repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
209 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) 197 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount"))
210 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); 198 cgit_repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
211 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) 199 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
212 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); 200 cgit_repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
213 else if (cgit_repo && !strcmp(name, "repo.module-link")) 201 else if (cgit_repo && !strcmp(name, "repo.module-link"))
214 cgit_repo->module_link= xstrdup(value); 202 cgit_repo->module_link= xstrdup(value);
215 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { 203 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) {
@@ -476,7 +464,7 @@ void cgit_diff_tree(const unsigned char *old_sha1,
476 diff_setup(&opt); 464 diff_setup(&opt);
477 opt.output_format = DIFF_FORMAT_CALLBACK; 465 opt.output_format = DIFF_FORMAT_CALLBACK;
478 opt.detect_rename = 1; 466 opt.detect_rename = 1;
479 opt.rename_limit = cgit_renamelimit; 467 opt.rename_limit = ctx.cfg.renamelimit;
480 DIFF_OPT_SET(&opt, RECURSIVE); 468 DIFF_OPT_SET(&opt, RECURSIVE);
481 opt.format_callback = cgit_diff_tree_cb; 469 opt.format_callback = cgit_diff_tree_cb;
482 opt.format_callback_data = fn; 470 opt.format_callback_data = fn;