-rw-r--r-- | cache.c | 10 | ||||
-rw-r--r-- | cgit.c | 33 | ||||
-rw-r--r-- | cgit.h | 72 | ||||
-rw-r--r-- | shared.c | 138 | ||||
-rw-r--r-- | ui-repolist.c | 18 | ||||
-rw-r--r-- | ui-shared.c | 60 | ||||
-rw-r--r-- | ui-summary.c | 10 |
7 files changed, 166 insertions, 175 deletions
@@ -44,21 +44,21 @@ int cache_create_dirs() | |||
44 | { | 44 | { |
45 | char *path; | 45 | char *path; |
46 | 46 | ||
47 | path = fmt("%s", cgit_cache_root); | 47 | path = fmt("%s", ctx.cfg.cache_root); |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | return 0; | 49 | return 0; |
50 | 50 | ||
51 | if (!cgit_repo) | 51 | if (!cgit_repo) |
52 | return 0; | 52 | return 0; |
53 | 53 | ||
54 | path = fmt("%s/%s", cgit_cache_root, | 54 | path = fmt("%s/%s", ctx.cfg.cache_root, |
55 | cache_safe_filename(cgit_repo->url)); | 55 | cache_safe_filename(cgit_repo->url)); |
56 | 56 | ||
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | return 0; | 58 | return 0; |
59 | 59 | ||
60 | if (ctx.qry.page) { | 60 | if (ctx.qry.page) { |
61 | path = fmt("%s/%s/%s", cgit_cache_root, | 61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
62 | cache_safe_filename(cgit_repo->url), | 62 | cache_safe_filename(cgit_repo->url), |
63 | ctx.qry.page); | 63 | ctx.qry.page); |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
@@ -74,7 +74,7 @@ int cache_refill_overdue(const char *lockfile) | |||
74 | if (stat(lockfile, &st)) | 74 | if (stat(lockfile, &st)) |
75 | return 0; | 75 | return 0; |
76 | else | 76 | else |
77 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); | 77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
78 | } | 78 | } |
79 | 79 | ||
80 | int cache_lock(struct cacheitem *item) | 80 | int cache_lock(struct cacheitem *item) |
@@ -83,7 +83,7 @@ int cache_lock(struct cacheitem *item) | |||
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); | 83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | 84 | ||
85 | top: | 85 | top: |
86 | if (++i > cgit_max_lock_attempts) | 86 | if (++i > ctx.cfg.max_lock_attempts) |
87 | die("cache_lock: unable to lock %s: %s", | 87 | die("cache_lock: unable to lock %s: %s", |
88 | item->name, strerror(errno)); | 88 | item->name, strerror(errno)); |
89 | 89 | ||
@@ -11,7 +11,7 @@ | |||
11 | static int cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 12 | { |
13 | if (!cgit_repo && ctx.qry.repo) { | 13 | if (!cgit_repo && ctx.qry.repo) { |
14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | 17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
@@ -20,27 +20,27 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
20 | } | 20 | } |
21 | 21 | ||
22 | if (!cgit_repo) { | 22 | if (!cgit_repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
24 | item->ttl = cgit_cache_root_ttl; | 24 | item->ttl = ctx.cfg.cache_root_ttl; |
25 | return 1; | 25 | return 1; |
26 | } | 26 | } |
27 | 27 | ||
28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(cgit_repo->url), |
31 | cache_safe_filename(ctx.qry.raw))); | 31 | cache_safe_filename(ctx.qry.raw))); |
32 | item->ttl = cgit_cache_repo_ttl; | 32 | item->ttl = ctx.cfg.cache_repo_ttl; |
33 | } else { | 33 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(cgit_repo->url), |
36 | ctx.qry.page, | 36 | ctx.qry.page, |
37 | cache_safe_filename(ctx.qry.raw))); | 37 | cache_safe_filename(ctx.qry.raw))); |
38 | if (ctx.qry.has_symref) | 38 | if (ctx.qry.has_symref) |
39 | item->ttl = cgit_cache_dynamic_ttl; | 39 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
40 | else if (ctx.qry.has_sha1) | 40 | else if (ctx.qry.has_sha1) |
41 | item->ttl = cgit_cache_static_ttl; | 41 | item->ttl = ctx.cfg.cache_static_ttl; |
42 | else | 42 | else |
43 | item->ttl = cgit_cache_repo_ttl; | 43 | item->ttl = ctx.cfg.cache_repo_ttl; |
44 | } | 44 | } |
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
@@ -85,7 +85,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
85 | unsigned char sha1[20]; | 85 | unsigned char sha1[20]; |
86 | 86 | ||
87 | if (chdir(cgit_repo->path)) { | 87 | if (chdir(cgit_repo->path)) { |
88 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
89 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
90 | cgit_print_pageheader(title, 0); | 90 | cgit_print_pageheader(title, 0); |
91 | cgit_print_error(fmt("Unable to scan repository: %s", | 91 | cgit_print_error(fmt("Unable to scan repository: %s", |
@@ -153,7 +153,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
153 | switch(cgit_cmd) { | 153 | switch(cgit_cmd) { |
154 | case CMD_LOG: | 154 | case CMD_LOG: |
155 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, | 155 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, |
156 | cgit_max_commit_count, ctx.qry.grep, ctx.qry.search, | 156 | ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, |
157 | ctx.qry.path, 1); | 157 | ctx.qry.path, 1); |
158 | break; | 158 | break; |
159 | case CMD_TREE: | 159 | case CMD_TREE: |
@@ -212,7 +212,7 @@ static void cgit_check_cache(struct cacheitem *item) | |||
212 | int i = 0; | 212 | int i = 0; |
213 | 213 | ||
214 | top: | 214 | top: |
215 | if (++i > cgit_max_lock_attempts) { | 215 | if (++i > ctx.cfg.max_lock_attempts) { |
216 | die("cgit_refresh_cache: unable to lock %s: %s", | 216 | die("cgit_refresh_cache: unable to lock %s: %s", |
217 | item->name, strerror(errno)); | 217 | item->name, strerror(errno)); |
218 | } | 218 | } |
@@ -258,10 +258,10 @@ static void cgit_parse_args(int argc, const char **argv) | |||
258 | 258 | ||
259 | for (i = 1; i < argc; i++) { | 259 | for (i = 1; i < argc; i++) { |
260 | if (!strncmp(argv[i], "--cache=", 8)) { | 260 | if (!strncmp(argv[i], "--cache=", 8)) { |
261 | cgit_cache_root = xstrdup(argv[i]+8); | 261 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
262 | } | 262 | } |
263 | if (!strcmp(argv[i], "--nocache")) { | 263 | if (!strcmp(argv[i], "--nocache")) { |
264 | cgit_nocache = 1; | 264 | ctx.cfg.nocache = 1; |
265 | } | 265 | } |
266 | if (!strncmp(argv[i], "--query=", 8)) { | 266 | if (!strncmp(argv[i], "--query=", 8)) { |
267 | ctx.qry.raw = xstrdup(argv[i]+8); | 267 | ctx.qry.raw = xstrdup(argv[i]+8); |
@@ -291,6 +291,7 @@ int main(int argc, const char **argv) | |||
291 | struct cacheitem item; | 291 | struct cacheitem item; |
292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
293 | 293 | ||
294 | cgit_prepare_context(&ctx); | ||
294 | htmlfd = STDOUT_FILENO; | 295 | htmlfd = STDOUT_FILENO; |
295 | item.st.st_mtime = time(NULL); | 296 | item.st.st_mtime = time(NULL); |
296 | cgit_repolist.length = 0; | 297 | cgit_repolist.length = 0; |
@@ -301,14 +302,14 @@ int main(int argc, const char **argv) | |||
301 | cgit_global_config_cb); | 302 | cgit_global_config_cb); |
302 | cgit_repo = NULL; | 303 | cgit_repo = NULL; |
303 | if (getenv("SCRIPT_NAME")) | 304 | if (getenv("SCRIPT_NAME")) |
304 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); | 305 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
305 | if (getenv("QUERY_STRING")) | 306 | if (getenv("QUERY_STRING")) |
306 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 307 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
307 | cgit_parse_args(argc, argv); | 308 | cgit_parse_args(argc, argv); |
308 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 309 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
309 | if (!cgit_prepare_cache(&item)) | 310 | if (!cgit_prepare_cache(&item)) |
310 | return 0; | 311 | return 0; |
311 | if (cgit_nocache) { | 312 | if (ctx.cfg.nocache) { |
312 | cgit_fill_cache(&item, 0); | 313 | cgit_fill_cache(&item, 0); |
313 | } else { | 314 | } else { |
314 | cgit_check_cache(&item); | 315 | cgit_check_cache(&item); |
@@ -139,8 +139,44 @@ struct cgit_query { | |||
139 | int ofs; | 139 | int ofs; |
140 | }; | 140 | }; |
141 | 141 | ||
142 | struct cgit_config { | ||
143 | char *agefile; | ||
144 | char *cache_root; | ||
145 | char *clone_prefix; | ||
146 | char *css; | ||
147 | char *index_header; | ||
148 | char *index_info; | ||
149 | char *logo; | ||
150 | char *logo_link; | ||
151 | char *module_link; | ||
152 | char *repo_group; | ||
153 | char *robots; | ||
154 | char *root_title; | ||
155 | char *script_name; | ||
156 | char *virtual_root; | ||
157 | int cache_dynamic_ttl; | ||
158 | int cache_max_create_time; | ||
159 | int cache_repo_ttl; | ||
160 | int cache_root_ttl; | ||
161 | int cache_static_ttl; | ||
162 | int enable_index_links; | ||
163 | int enable_log_filecount; | ||
164 | int enable_log_linecount; | ||
165 | int max_commit_count; | ||
166 | int max_lock_attempts; | ||
167 | int max_msg_len; | ||
168 | int max_repodesc_len; | ||
169 | int nocache; | ||
170 | int renamelimit; | ||
171 | int snapshots; | ||
172 | int summary_branches; | ||
173 | int summary_log; | ||
174 | int summary_tags; | ||
175 | }; | ||
176 | |||
142 | struct cgit_context { | 177 | struct cgit_context { |
143 | struct cgit_query qry; | 178 | struct cgit_query qry; |
179 | struct cgit_config cfg; | ||
144 | }; | 180 | }; |
145 | 181 | ||
146 | extern const char *cgit_version; | 182 | extern const char *cgit_version; |
@@ -150,43 +186,9 @@ extern struct repoinfo *cgit_repo; | |||
150 | extern struct cgit_context ctx; | 186 | extern struct cgit_context ctx; |
151 | extern int cgit_cmd; | 187 | extern int cgit_cmd; |
152 | 188 | ||
153 | extern char *cgit_root_title; | ||
154 | extern char *cgit_css; | ||
155 | extern char *cgit_logo; | ||
156 | extern char *cgit_index_header; | ||
157 | extern char *cgit_index_info; | ||
158 | extern char *cgit_logo_link; | ||
159 | extern char *cgit_module_link; | ||
160 | extern char *cgit_agefile; | ||
161 | extern char *cgit_virtual_root; | ||
162 | extern char *cgit_script_name; | ||
163 | extern char *cgit_cache_root; | ||
164 | extern char *cgit_repo_group; | ||
165 | extern char *cgit_robots; | ||
166 | extern char *cgit_clone_prefix; | ||
167 | |||
168 | extern int cgit_nocache; | ||
169 | extern int cgit_snapshots; | ||
170 | extern int cgit_enable_index_links; | ||
171 | extern int cgit_enable_log_filecount; | ||
172 | extern int cgit_enable_log_linecount; | ||
173 | extern int cgit_max_lock_attempts; | ||
174 | extern int cgit_cache_root_ttl; | ||
175 | extern int cgit_cache_repo_ttl; | ||
176 | extern int cgit_cache_dynamic_ttl; | ||
177 | extern int cgit_cache_static_ttl; | ||
178 | extern int cgit_cache_max_create_time; | ||
179 | extern int cgit_summary_log; | ||
180 | extern int cgit_summary_tags; | ||
181 | extern int cgit_summary_branches; | ||
182 | |||
183 | extern int cgit_max_msg_len; | ||
184 | extern int cgit_max_repodesc_len; | ||
185 | extern int cgit_max_commit_count; | ||
186 | |||
187 | |||
188 | extern int htmlfd; | 189 | extern int htmlfd; |
189 | 190 | ||
191 | extern void cgit_prepare_context(struct cgit_context *ctx); | ||
190 | extern int cgit_get_cmd_index(const char *cmd); | 192 | extern int cgit_get_cmd_index(const char *cmd); |
191 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 193 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
192 | extern void cgit_global_config_cb(const char *name, const char *value); | 194 | extern void cgit_global_config_cb(const char *name, const char *value); |
@@ -15,43 +15,31 @@ int cgit_cmd; | |||
15 | 15 | ||
16 | const char *cgit_version = CGIT_VERSION; | 16 | const char *cgit_version = CGIT_VERSION; |
17 | 17 | ||
18 | char *cgit_root_title = "Git repository browser"; | ||
19 | char *cgit_css = "/cgit.css"; | ||
20 | char *cgit_logo = "/git-logo.png"; | ||
21 | char *cgit_index_header = NULL; | ||
22 | char *cgit_index_info = NULL; | ||
23 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | ||
24 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | ||
25 | char *cgit_agefile = "info/web/last-modified"; | ||
26 | char *cgit_virtual_root = NULL; | ||
27 | char *cgit_script_name = CGIT_SCRIPT_NAME; | ||
28 | char *cgit_cache_root = CGIT_CACHE_ROOT; | ||
29 | char *cgit_repo_group = NULL; | ||
30 | char *cgit_robots = "index, nofollow"; | ||
31 | char *cgit_clone_prefix = NULL; | ||
32 | |||
33 | int cgit_nocache = 0; | ||
34 | int cgit_snapshots = 0; | ||
35 | int cgit_enable_index_links = 0; | ||
36 | int cgit_enable_log_filecount = 0; | ||
37 | int cgit_enable_log_linecount = 0; | ||
38 | int cgit_max_lock_attempts = 5; | ||
39 | int cgit_cache_root_ttl = 5; | ||
40 | int cgit_cache_repo_ttl = 5; | ||
41 | int cgit_cache_dynamic_ttl = 5; | ||
42 | int cgit_cache_static_ttl = -1; | ||
43 | int cgit_cache_max_create_time = 5; | ||
44 | int cgit_summary_log = 0; | ||
45 | int cgit_summary_tags = 0; | ||
46 | int cgit_summary_branches = 0; | ||
47 | int cgit_renamelimit = -1; | ||
48 | |||
49 | int cgit_max_msg_len = 60; | ||
50 | int cgit_max_repodesc_len = 60; | ||
51 | int cgit_max_commit_count = 50; | ||
52 | |||
53 | int htmlfd = 0; | 18 | int htmlfd = 0; |
54 | 19 | ||
20 | void 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 | |||
55 | int cgit_get_cmd_index(const char *cmd) | 43 | int 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) | |||
131 | void cgit_global_config_cb(const char *name, const char *value) | 119 | void 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; |
diff --git a/ui-repolist.c b/ui-repolist.c index 3e97ca9..a6cc2cc 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -30,7 +30,7 @@ static void print_modtime(struct repoinfo *repo) | |||
30 | char *path; | 30 | char *path; |
31 | struct stat s; | 31 | struct stat s; |
32 | 32 | ||
33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 33 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
34 | if (stat(path, &s) == 0) { | 34 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 35 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 36 | return; |
@@ -47,17 +47,17 @@ void cgit_print_repolist(struct cacheitem *item) | |||
47 | int i, columns = 4; | 47 | int i, columns = 4; |
48 | char *last_group = NULL; | 48 | char *last_group = NULL; |
49 | 49 | ||
50 | if (cgit_enable_index_links) | 50 | if (ctx.cfg.enable_index_links) |
51 | columns++; | 51 | columns++; |
52 | 52 | ||
53 | cgit_print_docstart(cgit_root_title, item); | 53 | cgit_print_docstart(ctx.cfg.root_title, item); |
54 | cgit_print_pageheader(cgit_root_title, 0); | 54 | cgit_print_pageheader(ctx.cfg.root_title, 0); |
55 | 55 | ||
56 | html("<table summary='repository list' class='list nowrap'>"); | 56 | html("<table summary='repository list' class='list nowrap'>"); |
57 | if (cgit_index_header) { | 57 | if (ctx.cfg.index_header) { |
58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
59 | columns); | 59 | columns); |
60 | html_include(cgit_index_header); | 60 | html_include(ctx.cfg.index_header); |
61 | html("</td></tr>"); | 61 | html("</td></tr>"); |
62 | } | 62 | } |
63 | html("<tr class='nohover'>" | 63 | html("<tr class='nohover'>" |
@@ -65,7 +65,7 @@ void cgit_print_repolist(struct cacheitem *item) | |||
65 | "<th class='left'>Description</th>" | 65 | "<th class='left'>Description</th>" |
66 | "<th class='left'>Owner</th>" | 66 | "<th class='left'>Owner</th>" |
67 | "<th class='left'>Idle</th>"); | 67 | "<th class='left'>Idle</th>"); |
68 | if (cgit_enable_index_links) | 68 | if (ctx.cfg.enable_index_links) |
69 | html("<th>Links</th>"); | 69 | html("<th>Links</th>"); |
70 | html("</tr>\n"); | 70 | html("</tr>\n"); |
71 | 71 | ||
@@ -87,13 +87,13 @@ void cgit_print_repolist(struct cacheitem *item) | |||
87 | html_txt(cgit_repo->name); | 87 | html_txt(cgit_repo->name); |
88 | html_link_close(); | 88 | html_link_close(); |
89 | html("</td><td>"); | 89 | html("</td><td>"); |
90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); | 90 | html_ntxt(ctx.cfg.max_repodesc_len, cgit_repo->desc); |
91 | html("</td><td>"); | 91 | html("</td><td>"); |
92 | html_txt(cgit_repo->owner); | 92 | html_txt(cgit_repo->owner); |
93 | html("</td><td>"); | 93 | html("</td><td>"); |
94 | print_modtime(cgit_repo); | 94 | print_modtime(cgit_repo); |
95 | html("</td>"); | 95 | html("</td>"); |
96 | if (cgit_enable_index_links) { | 96 | if (ctx.cfg.enable_index_links) { |
97 | html("<td>"); | 97 | html("<td>"); |
98 | html_link_open(cgit_repourl(cgit_repo->url), | 98 | html_link_open(cgit_repourl(cgit_repo->url), |
99 | NULL, "button"); | 99 | NULL, "button"); |
diff --git a/ui-shared.c b/ui-shared.c index 6a41fb0..b96237d 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -42,16 +42,16 @@ void cgit_print_error(char *msg) | |||
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (ctx.cfg.virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", ctx.cfg.virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return ctx.cfg.script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (ctx.cfg.virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
@@ -63,8 +63,8 @@ char *cgit_fileurl(const char *reponame, const char *pagename, | |||
63 | char *tmp; | 63 | char *tmp; |
64 | char *delim; | 64 | char *delim; |
65 | 65 | ||
66 | if (cgit_virtual_root) { | 66 | if (ctx.cfg.virtual_root) { |
67 | tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame, | 67 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
68 | pagename, (filename ? filename:"")); | 68 | pagename, (filename ? filename:"")); |
69 | delim = "?"; | 69 | delim = "?"; |
70 | } else { | 70 | } else { |
@@ -110,14 +110,14 @@ const char *cgit_repobasename(const char *reponame) | |||
110 | 110 | ||
111 | char *cgit_currurl() | 111 | char *cgit_currurl() |
112 | { | 112 | { |
113 | if (!cgit_virtual_root) | 113 | if (!ctx.cfg.virtual_root) |
114 | return cgit_script_name; | 114 | return ctx.cfg.script_name; |
115 | else if (ctx.qry.page) | 115 | else if (ctx.qry.page) |
116 | return fmt("%s/%s/%s/", cgit_virtual_root, ctx.qry.repo, ctx.qry.page); | 116 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
117 | else if (ctx.qry.repo) | 117 | else if (ctx.qry.repo) |
118 | return fmt("%s/%s/", cgit_virtual_root, ctx.qry.repo); | 118 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
119 | else | 119 | else |
120 | return fmt("%s/", cgit_virtual_root); | 120 | return fmt("%s/", ctx.cfg.virtual_root); |
121 | } | 121 | } |
122 | 122 | ||
123 | static char *repolink(char *title, char *class, char *page, char *head, | 123 | static char *repolink(char *title, char *class, char *page, char *head, |
@@ -137,9 +137,9 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
137 | html("'"); | 137 | html("'"); |
138 | } | 138 | } |
139 | html(" href='"); | 139 | html(" href='"); |
140 | if (cgit_virtual_root) { | 140 | if (ctx.cfg.virtual_root) { |
141 | html_attr(cgit_virtual_root); | 141 | html_attr(ctx.cfg.virtual_root); |
142 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 143 | html("/"); |
144 | html_attr(cgit_repo->url); | 144 | html_attr(cgit_repo->url); |
145 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 145 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
@@ -151,7 +151,7 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
151 | html_attr(path); | 151 | html_attr(path); |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | html(cgit_script_name); | 154 | html(ctx.cfg.script_name); |
155 | html("?url="); | 155 | html("?url="); |
156 | html_attr(cgit_repo->url); | 156 | html_attr(cgit_repo->url); |
157 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 157 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
@@ -229,11 +229,11 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
229 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 229 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
230 | char *rev) | 230 | char *rev) |
231 | { | 231 | { |
232 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 232 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
233 | name[cgit_max_msg_len] = '\0'; | 233 | name[ctx.cfg.max_msg_len] = '\0'; |
234 | name[cgit_max_msg_len - 1] = '.'; | 234 | name[ctx.cfg.max_msg_len - 1] = '.'; |
235 | name[cgit_max_msg_len - 2] = '.'; | 235 | name[ctx.cfg.max_msg_len - 2] = '.'; |
236 | name[cgit_max_msg_len - 3] = '.'; | 236 | name[ctx.cfg.max_msg_len - 3] = '.'; |
237 | } | 237 | } |
238 | reporevlink("commit", name, title, class, head, rev, NULL); | 238 | reporevlink("commit", name, title, class, head, rev, NULL); |
239 | } | 239 | } |
@@ -374,10 +374,10 @@ void cgit_print_docstart(char *title, struct cacheitem *item) | |||
374 | html_txt(title); | 374 | html_txt(title); |
375 | html("</title>\n"); | 375 | html("</title>\n"); |
376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
377 | if (cgit_robots && *cgit_robots) | 377 | if (ctx.cfg.robots && *ctx.cfg.robots) |
378 | htmlf("<meta name='robots' content='%s'/>\n", cgit_robots); | 378 | htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); |
379 | html("<link rel='stylesheet' type='text/css' href='"); | 379 | html("<link rel='stylesheet' type='text/css' href='"); |
380 | html_attr(cgit_css); | 380 | html_attr(ctx.cfg.css); |
381 | html("'/>\n"); | 381 | html("'/>\n"); |
382 | html("</head>\n"); | 382 | html("</head>\n"); |
383 | html("<body>\n"); | 383 | html("<body>\n"); |
@@ -439,7 +439,7 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page) | |||
439 | { | 439 | { |
440 | char *url; | 440 | char *url; |
441 | 441 | ||
442 | if (!cgit_virtual_root) { | 442 | if (!ctx.cfg.virtual_root) { |
443 | url = fmt("%s/%s", ctx.qry.repo, page); | 443 | url = fmt("%s/%s", ctx.qry.repo, page); |
444 | if (ctx.qry.path) | 444 | if (ctx.qry.path) |
445 | url = fmt("%s/%s", url, ctx.qry.path); | 445 | url = fmt("%s/%s", url, ctx.qry.path); |
@@ -474,7 +474,7 @@ void cgit_print_pageheader(char *title, int show_search) | |||
474 | html("<tr><td class='sidebar'>\n<a href='"); | 474 | html("<tr><td class='sidebar'>\n<a href='"); |
475 | html_attr(cgit_rooturl()); | 475 | html_attr(cgit_rooturl()); |
476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
477 | cgit_logo); | 477 | ctx.cfg.logo); |
478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
479 | if (ctx.qry.repo) { | 479 | if (ctx.qry.repo) { |
480 | html("<h1 class='first'>"); | 480 | html("<h1 class='first'>"); |
@@ -501,12 +501,12 @@ void cgit_print_pageheader(char *title, int show_search) | |||
501 | 501 | ||
502 | for_each_ref(print_archive_ref, &header); | 502 | for_each_ref(print_archive_ref, &header); |
503 | 503 | ||
504 | if (cgit_repo->clone_url || cgit_clone_prefix) { | 504 | if (cgit_repo->clone_url || ctx.cfg.clone_prefix) { |
505 | html("<h1>clone</h1>\n"); | 505 | html("<h1>clone</h1>\n"); |
506 | if (cgit_repo->clone_url) | 506 | if (cgit_repo->clone_url) |
507 | url = cgit_repo->clone_url; | 507 | url = cgit_repo->clone_url; |
508 | else | 508 | else |
509 | url = fmt("%s%s", cgit_clone_prefix, | 509 | url = fmt("%s%s", ctx.cfg.clone_prefix, |
510 | cgit_repo->url); | 510 | cgit_repo->url); |
511 | html("<a class='menu' href='"); | 511 | html("<a class='menu' href='"); |
512 | html_attr(url); | 512 | html_attr(url); |
@@ -531,7 +531,7 @@ void cgit_print_pageheader(char *title, int show_search) | |||
531 | 531 | ||
532 | html("<h1>search</h1>\n"); | 532 | html("<h1>search</h1>\n"); |
533 | html("<form method='get' action='"); | 533 | html("<form method='get' action='"); |
534 | if (cgit_virtual_root) | 534 | if (ctx.cfg.virtual_root) |
535 | html_attr(cgit_fileurl(ctx.qry.repo, "log", | 535 | html_attr(cgit_fileurl(ctx.qry.repo, "log", |
536 | ctx.qry.path, NULL)); | 536 | ctx.qry.path, NULL)); |
537 | html("'>\n"); | 537 | html("'>\n"); |
@@ -546,7 +546,7 @@ void cgit_print_pageheader(char *title, int show_search) | |||
546 | html("'/>\n"); | 546 | html("'/>\n"); |
547 | html("</form>\n"); | 547 | html("</form>\n"); |
548 | } else { | 548 | } else { |
549 | if (!cgit_index_info || html_include(cgit_index_info)) | 549 | if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) |
550 | html(default_info); | 550 | html(default_info); |
551 | } | 551 | } |
552 | 552 | ||
diff --git a/ui-summary.c b/ui-summary.c index bbd4464..0a44994 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -187,14 +187,14 @@ void cgit_print_summary() | |||
187 | html_include(cgit_repo->readme); | 187 | html_include(cgit_repo->readme); |
188 | html("</div>"); | 188 | html("</div>"); |
189 | } | 189 | } |
190 | if (cgit_summary_log > 0) | 190 | if (ctx.cfg.summary_log > 0) |
191 | cgit_print_log(ctx.qry.head, 0, cgit_summary_log, NULL, | 191 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, |
192 | NULL, NULL, 0); | 192 | NULL, NULL, 0); |
193 | html("<table summary='repository info' class='list nowrap'>"); | 193 | html("<table summary='repository info' class='list nowrap'>"); |
194 | if (cgit_summary_log > 0) | 194 | if (ctx.cfg.summary_log > 0) |
195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
196 | cgit_print_branches(cgit_summary_branches); | 196 | cgit_print_branches(ctx.cfg.summary_branches); |
197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
198 | cgit_print_tags(cgit_summary_tags); | 198 | cgit_print_tags(ctx.cfg.summary_tags); |
199 | html("</table>"); | 199 | html("</table>"); |
200 | } | 200 | } |