|
diff --git a/cgit.c b/cgit.c index aa1107a..dbec196 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -1,269 +1,292 @@ |
1 | /* cgit.c: cgi for the git scm |
1 | /* cgit.c: cgi for the git scm |
2 | * |
2 | * |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
4 | * |
4 | * |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | #include "cache.h" |
10 | #include "cache.h" |
11 | #include "cmd.h" |
11 | #include "cmd.h" |
12 | #include "configfile.h" |
12 | #include "configfile.h" |
13 | #include "html.h" |
13 | #include "html.h" |
14 | #include "ui-shared.h" |
14 | #include "ui-shared.h" |
15 | #include "ui-stats.h" |
15 | #include "ui-stats.h" |
16 | #include "scan-tree.h" |
16 | #include "scan-tree.h" |
17 | |
17 | |
18 | const char *cgit_version = CGIT_VERSION; |
18 | const char *cgit_version = CGIT_VERSION; |
19 | |
19 | |
20 | void add_mimetype(const char *name, const char *value) |
20 | void add_mimetype(const char *name, const char *value) |
21 | { |
21 | { |
22 | struct string_list_item *item; |
22 | struct string_list_item *item; |
23 | |
23 | |
24 | item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); |
24 | item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); |
25 | item->util = xstrdup(value); |
25 | item->util = xstrdup(value); |
26 | } |
26 | } |
27 | |
27 | |
| |
28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
| |
29 | { |
| |
30 | struct cgit_filter *f; |
| |
31 | |
| |
32 | if (!cmd || !cmd[0]) |
| |
33 | return NULL; |
| |
34 | |
| |
35 | f = xmalloc(sizeof(struct cgit_filter)); |
| |
36 | f->cmd = xstrdup(cmd); |
| |
37 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); |
| |
38 | f->argv[0] = f->cmd; |
| |
39 | f->argv[1] = NULL; |
| |
40 | return f; |
| |
41 | } |
| |
42 | |
28 | void config_cb(const char *name, const char *value) |
43 | void config_cb(const char *name, const char *value) |
29 | { |
44 | { |
30 | if (!strcmp(name, "root-title")) |
45 | if (!strcmp(name, "root-title")) |
31 | ctx.cfg.root_title = xstrdup(value); |
46 | ctx.cfg.root_title = xstrdup(value); |
32 | else if (!strcmp(name, "root-desc")) |
47 | else if (!strcmp(name, "root-desc")) |
33 | ctx.cfg.root_desc = xstrdup(value); |
48 | ctx.cfg.root_desc = xstrdup(value); |
34 | else if (!strcmp(name, "root-readme")) |
49 | else if (!strcmp(name, "root-readme")) |
35 | ctx.cfg.root_readme = xstrdup(value); |
50 | ctx.cfg.root_readme = xstrdup(value); |
36 | else if (!strcmp(name, "css")) |
51 | else if (!strcmp(name, "css")) |
37 | ctx.cfg.css = xstrdup(value); |
52 | ctx.cfg.css = xstrdup(value); |
38 | else if (!strcmp(name, "favicon")) |
53 | else if (!strcmp(name, "favicon")) |
39 | ctx.cfg.favicon = xstrdup(value); |
54 | ctx.cfg.favicon = xstrdup(value); |
40 | else if (!strcmp(name, "footer")) |
55 | else if (!strcmp(name, "footer")) |
41 | ctx.cfg.footer = xstrdup(value); |
56 | ctx.cfg.footer = xstrdup(value); |
42 | else if (!strcmp(name, "head-include")) |
57 | else if (!strcmp(name, "head-include")) |
43 | ctx.cfg.head_include = xstrdup(value); |
58 | ctx.cfg.head_include = xstrdup(value); |
44 | else if (!strcmp(name, "header")) |
59 | else if (!strcmp(name, "header")) |
45 | ctx.cfg.header = xstrdup(value); |
60 | ctx.cfg.header = xstrdup(value); |
46 | else if (!strcmp(name, "logo")) |
61 | else if (!strcmp(name, "logo")) |
47 | ctx.cfg.logo = xstrdup(value); |
62 | ctx.cfg.logo = xstrdup(value); |
48 | else if (!strcmp(name, "index-header")) |
63 | else if (!strcmp(name, "index-header")) |
49 | ctx.cfg.index_header = xstrdup(value); |
64 | ctx.cfg.index_header = xstrdup(value); |
50 | else if (!strcmp(name, "index-info")) |
65 | else if (!strcmp(name, "index-info")) |
51 | ctx.cfg.index_info = xstrdup(value); |
66 | ctx.cfg.index_info = xstrdup(value); |
52 | else if (!strcmp(name, "logo-link")) |
67 | else if (!strcmp(name, "logo-link")) |
53 | ctx.cfg.logo_link = xstrdup(value); |
68 | ctx.cfg.logo_link = xstrdup(value); |
54 | else if (!strcmp(name, "module-link")) |
69 | else if (!strcmp(name, "module-link")) |
55 | ctx.cfg.module_link = xstrdup(value); |
70 | ctx.cfg.module_link = xstrdup(value); |
56 | else if (!strcmp(name, "virtual-root")) { |
71 | else if (!strcmp(name, "virtual-root")) { |
57 | ctx.cfg.virtual_root = trim_end(value, '/'); |
72 | ctx.cfg.virtual_root = trim_end(value, '/'); |
58 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
73 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
59 | ctx.cfg.virtual_root = ""; |
74 | ctx.cfg.virtual_root = ""; |
60 | } else if (!strcmp(name, "nocache")) |
75 | } else if (!strcmp(name, "nocache")) |
61 | ctx.cfg.nocache = atoi(value); |
76 | ctx.cfg.nocache = atoi(value); |
62 | else if (!strcmp(name, "noplainemail")) |
77 | else if (!strcmp(name, "noplainemail")) |
63 | ctx.cfg.noplainemail = atoi(value); |
78 | ctx.cfg.noplainemail = atoi(value); |
64 | else if (!strcmp(name, "noheader")) |
79 | else if (!strcmp(name, "noheader")) |
65 | ctx.cfg.noheader = atoi(value); |
80 | ctx.cfg.noheader = atoi(value); |
66 | else if (!strcmp(name, "snapshots")) |
81 | else if (!strcmp(name, "snapshots")) |
67 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
82 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
68 | else if (!strcmp(name, "enable-index-links")) |
83 | else if (!strcmp(name, "enable-index-links")) |
69 | ctx.cfg.enable_index_links = atoi(value); |
84 | ctx.cfg.enable_index_links = atoi(value); |
70 | else if (!strcmp(name, "enable-log-filecount")) |
85 | else if (!strcmp(name, "enable-log-filecount")) |
71 | ctx.cfg.enable_log_filecount = atoi(value); |
86 | ctx.cfg.enable_log_filecount = atoi(value); |
72 | else if (!strcmp(name, "enable-log-linecount")) |
87 | else if (!strcmp(name, "enable-log-linecount")) |
73 | ctx.cfg.enable_log_linecount = atoi(value); |
88 | ctx.cfg.enable_log_linecount = atoi(value); |
74 | else if (!strcmp(name, "max-stats")) |
89 | else if (!strcmp(name, "max-stats")) |
75 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
90 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
76 | else if (!strcmp(name, "cache-size")) |
91 | else if (!strcmp(name, "cache-size")) |
77 | ctx.cfg.cache_size = atoi(value); |
92 | ctx.cfg.cache_size = atoi(value); |
78 | else if (!strcmp(name, "cache-root")) |
93 | else if (!strcmp(name, "cache-root")) |
79 | ctx.cfg.cache_root = xstrdup(value); |
94 | ctx.cfg.cache_root = xstrdup(value); |
80 | else if (!strcmp(name, "cache-root-ttl")) |
95 | else if (!strcmp(name, "cache-root-ttl")) |
81 | ctx.cfg.cache_root_ttl = atoi(value); |
96 | ctx.cfg.cache_root_ttl = atoi(value); |
82 | else if (!strcmp(name, "cache-repo-ttl")) |
97 | else if (!strcmp(name, "cache-repo-ttl")) |
83 | ctx.cfg.cache_repo_ttl = atoi(value); |
98 | ctx.cfg.cache_repo_ttl = atoi(value); |
84 | else if (!strcmp(name, "cache-static-ttl")) |
99 | else if (!strcmp(name, "cache-static-ttl")) |
85 | ctx.cfg.cache_static_ttl = atoi(value); |
100 | ctx.cfg.cache_static_ttl = atoi(value); |
86 | else if (!strcmp(name, "cache-dynamic-ttl")) |
101 | else if (!strcmp(name, "cache-dynamic-ttl")) |
87 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
102 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
| |
103 | else if (!strcmp(name, "commit-filter")) |
| |
104 | ctx.cfg.commit_filter = new_filter(value, 0); |
88 | else if (!strcmp(name, "embedded")) |
105 | else if (!strcmp(name, "embedded")) |
89 | ctx.cfg.embedded = atoi(value); |
106 | ctx.cfg.embedded = atoi(value); |
90 | else if (!strcmp(name, "max-message-length")) |
107 | else if (!strcmp(name, "max-message-length")) |
91 | ctx.cfg.max_msg_len = atoi(value); |
108 | ctx.cfg.max_msg_len = atoi(value); |
92 | else if (!strcmp(name, "max-repodesc-length")) |
109 | else if (!strcmp(name, "max-repodesc-length")) |
93 | ctx.cfg.max_repodesc_len = atoi(value); |
110 | ctx.cfg.max_repodesc_len = atoi(value); |
94 | else if (!strcmp(name, "max-repo-count")) |
111 | else if (!strcmp(name, "max-repo-count")) |
95 | ctx.cfg.max_repo_count = atoi(value); |
112 | ctx.cfg.max_repo_count = atoi(value); |
96 | else if (!strcmp(name, "max-commit-count")) |
113 | else if (!strcmp(name, "max-commit-count")) |
97 | ctx.cfg.max_commit_count = atoi(value); |
114 | ctx.cfg.max_commit_count = atoi(value); |
| |
115 | else if (!strcmp(name, "source-filter")) |
| |
116 | ctx.cfg.source_filter = new_filter(value, 1); |
98 | else if (!strcmp(name, "summary-log")) |
117 | else if (!strcmp(name, "summary-log")) |
99 | ctx.cfg.summary_log = atoi(value); |
118 | ctx.cfg.summary_log = atoi(value); |
100 | else if (!strcmp(name, "summary-branches")) |
119 | else if (!strcmp(name, "summary-branches")) |
101 | ctx.cfg.summary_branches = atoi(value); |
120 | ctx.cfg.summary_branches = atoi(value); |
102 | else if (!strcmp(name, "summary-tags")) |
121 | else if (!strcmp(name, "summary-tags")) |
103 | ctx.cfg.summary_tags = atoi(value); |
122 | ctx.cfg.summary_tags = atoi(value); |
104 | else if (!strcmp(name, "agefile")) |
123 | else if (!strcmp(name, "agefile")) |
105 | ctx.cfg.agefile = xstrdup(value); |
124 | ctx.cfg.agefile = xstrdup(value); |
106 | else if (!strcmp(name, "renamelimit")) |
125 | else if (!strcmp(name, "renamelimit")) |
107 | ctx.cfg.renamelimit = atoi(value); |
126 | ctx.cfg.renamelimit = atoi(value); |
108 | else if (!strcmp(name, "robots")) |
127 | else if (!strcmp(name, "robots")) |
109 | ctx.cfg.robots = xstrdup(value); |
128 | ctx.cfg.robots = xstrdup(value); |
110 | else if (!strcmp(name, "clone-prefix")) |
129 | else if (!strcmp(name, "clone-prefix")) |
111 | ctx.cfg.clone_prefix = xstrdup(value); |
130 | ctx.cfg.clone_prefix = xstrdup(value); |
112 | else if (!strcmp(name, "local-time")) |
131 | else if (!strcmp(name, "local-time")) |
113 | ctx.cfg.local_time = atoi(value); |
132 | ctx.cfg.local_time = atoi(value); |
114 | else if (!prefixcmp(name, "mimetype.")) |
133 | else if (!prefixcmp(name, "mimetype.")) |
115 | add_mimetype(name + 9, value); |
134 | add_mimetype(name + 9, value); |
116 | else if (!strcmp(name, "repo.group")) |
135 | else if (!strcmp(name, "repo.group")) |
117 | ctx.cfg.repo_group = xstrdup(value); |
136 | ctx.cfg.repo_group = xstrdup(value); |
118 | else if (!strcmp(name, "repo.url")) |
137 | else if (!strcmp(name, "repo.url")) |
119 | ctx.repo = cgit_add_repo(value); |
138 | ctx.repo = cgit_add_repo(value); |
120 | else if (!strcmp(name, "repo.name")) |
139 | else if (!strcmp(name, "repo.name")) |
121 | ctx.repo->name = xstrdup(value); |
140 | ctx.repo->name = xstrdup(value); |
122 | else if (ctx.repo && !strcmp(name, "repo.path")) |
141 | else if (ctx.repo && !strcmp(name, "repo.path")) |
123 | ctx.repo->path = trim_end(value, '/'); |
142 | ctx.repo->path = trim_end(value, '/'); |
124 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) |
143 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) |
125 | ctx.repo->clone_url = xstrdup(value); |
144 | ctx.repo->clone_url = xstrdup(value); |
126 | else if (ctx.repo && !strcmp(name, "repo.desc")) |
145 | else if (ctx.repo && !strcmp(name, "repo.desc")) |
127 | ctx.repo->desc = xstrdup(value); |
146 | ctx.repo->desc = xstrdup(value); |
128 | else if (ctx.repo && !strcmp(name, "repo.owner")) |
147 | else if (ctx.repo && !strcmp(name, "repo.owner")) |
129 | ctx.repo->owner = xstrdup(value); |
148 | ctx.repo->owner = xstrdup(value); |
130 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) |
149 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) |
131 | ctx.repo->defbranch = xstrdup(value); |
150 | ctx.repo->defbranch = xstrdup(value); |
132 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
151 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
133 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
152 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
134 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
153 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
135 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
154 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
136 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
155 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
137 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
156 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
138 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) |
157 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) |
139 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); |
158 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); |
140 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
159 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
141 | ctx.repo->module_link= xstrdup(value); |
160 | ctx.repo->module_link= xstrdup(value); |
| |
161 | else if (ctx.repo && !strcmp(name, "repo.commit-filter")) |
| |
162 | ctx.repo->commit_filter = new_filter(value, 0); |
| |
163 | else if (ctx.repo && !strcmp(name, "repo.source-filter")) |
| |
164 | ctx.repo->source_filter = new_filter(value, 1); |
142 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
165 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
143 | if (*value == '/') |
166 | if (*value == '/') |
144 | ctx.repo->readme = xstrdup(value); |
167 | ctx.repo->readme = xstrdup(value); |
145 | else |
168 | else |
146 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
169 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
147 | } else if (!strcmp(name, "include")) |
170 | } else if (!strcmp(name, "include")) |
148 | parse_configfile(value, config_cb); |
171 | parse_configfile(value, config_cb); |
149 | } |
172 | } |
150 | |
173 | |
151 | static void querystring_cb(const char *name, const char *value) |
174 | static void querystring_cb(const char *name, const char *value) |
152 | { |
175 | { |
153 | if (!strcmp(name,"r")) { |
176 | if (!strcmp(name,"r")) { |
154 | ctx.qry.repo = xstrdup(value); |
177 | ctx.qry.repo = xstrdup(value); |
155 | ctx.repo = cgit_get_repoinfo(value); |
178 | ctx.repo = cgit_get_repoinfo(value); |
156 | } else if (!strcmp(name, "p")) { |
179 | } else if (!strcmp(name, "p")) { |
157 | ctx.qry.page = xstrdup(value); |
180 | ctx.qry.page = xstrdup(value); |
158 | } else if (!strcmp(name, "url")) { |
181 | } else if (!strcmp(name, "url")) { |
159 | ctx.qry.url = xstrdup(value); |
182 | ctx.qry.url = xstrdup(value); |
160 | cgit_parse_url(value); |
183 | cgit_parse_url(value); |
161 | } else if (!strcmp(name, "qt")) { |
184 | } else if (!strcmp(name, "qt")) { |
162 | ctx.qry.grep = xstrdup(value); |
185 | ctx.qry.grep = xstrdup(value); |
163 | } else if (!strcmp(name, "q")) { |
186 | } else if (!strcmp(name, "q")) { |
164 | ctx.qry.search = xstrdup(value); |
187 | ctx.qry.search = xstrdup(value); |
165 | } else if (!strcmp(name, "h")) { |
188 | } else if (!strcmp(name, "h")) { |
166 | ctx.qry.head = xstrdup(value); |
189 | ctx.qry.head = xstrdup(value); |
167 | ctx.qry.has_symref = 1; |
190 | ctx.qry.has_symref = 1; |
168 | } else if (!strcmp(name, "id")) { |
191 | } else if (!strcmp(name, "id")) { |
169 | ctx.qry.sha1 = xstrdup(value); |
192 | ctx.qry.sha1 = xstrdup(value); |
170 | ctx.qry.has_sha1 = 1; |
193 | ctx.qry.has_sha1 = 1; |
171 | } else if (!strcmp(name, "id2")) { |
194 | } else if (!strcmp(name, "id2")) { |
172 | ctx.qry.sha2 = xstrdup(value); |
195 | ctx.qry.sha2 = xstrdup(value); |
173 | ctx.qry.has_sha1 = 1; |
196 | ctx.qry.has_sha1 = 1; |
174 | } else if (!strcmp(name, "ofs")) { |
197 | } else if (!strcmp(name, "ofs")) { |
175 | ctx.qry.ofs = atoi(value); |
198 | ctx.qry.ofs = atoi(value); |
176 | } else if (!strcmp(name, "path")) { |
199 | } else if (!strcmp(name, "path")) { |
177 | ctx.qry.path = trim_end(value, '/'); |
200 | ctx.qry.path = trim_end(value, '/'); |
178 | } else if (!strcmp(name, "name")) { |
201 | } else if (!strcmp(name, "name")) { |
179 | ctx.qry.name = xstrdup(value); |
202 | ctx.qry.name = xstrdup(value); |
180 | } else if (!strcmp(name, "mimetype")) { |
203 | } else if (!strcmp(name, "mimetype")) { |
181 | ctx.qry.mimetype = xstrdup(value); |
204 | ctx.qry.mimetype = xstrdup(value); |
182 | } else if (!strcmp(name, "s")){ |
205 | } else if (!strcmp(name, "s")){ |
183 | ctx.qry.sort = xstrdup(value); |
206 | ctx.qry.sort = xstrdup(value); |
184 | } else if (!strcmp(name, "showmsg")) { |
207 | } else if (!strcmp(name, "showmsg")) { |
185 | ctx.qry.showmsg = atoi(value); |
208 | ctx.qry.showmsg = atoi(value); |
186 | } else if (!strcmp(name, "period")) { |
209 | } else if (!strcmp(name, "period")) { |
187 | ctx.qry.period = xstrdup(value); |
210 | ctx.qry.period = xstrdup(value); |
188 | } |
211 | } |
189 | } |
212 | } |
190 | |
213 | |
191 | static void prepare_context(struct cgit_context *ctx) |
214 | static void prepare_context(struct cgit_context *ctx) |
192 | { |
215 | { |
193 | memset(ctx, 0, sizeof(ctx)); |
216 | memset(ctx, 0, sizeof(ctx)); |
194 | ctx->cfg.agefile = "info/web/last-modified"; |
217 | ctx->cfg.agefile = "info/web/last-modified"; |
195 | ctx->cfg.nocache = 0; |
218 | ctx->cfg.nocache = 0; |
196 | ctx->cfg.cache_size = 0; |
219 | ctx->cfg.cache_size = 0; |
197 | ctx->cfg.cache_dynamic_ttl = 5; |
220 | ctx->cfg.cache_dynamic_ttl = 5; |
198 | ctx->cfg.cache_max_create_time = 5; |
221 | ctx->cfg.cache_max_create_time = 5; |
199 | ctx->cfg.cache_repo_ttl = 5; |
222 | ctx->cfg.cache_repo_ttl = 5; |
200 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
223 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
201 | ctx->cfg.cache_root_ttl = 5; |
224 | ctx->cfg.cache_root_ttl = 5; |
202 | ctx->cfg.cache_static_ttl = -1; |
225 | ctx->cfg.cache_static_ttl = -1; |
203 | ctx->cfg.css = "/cgit.css"; |
226 | ctx->cfg.css = "/cgit.css"; |
204 | ctx->cfg.logo = "/git-logo.png"; |
227 | ctx->cfg.logo = "/git-logo.png"; |
205 | ctx->cfg.local_time = 0; |
228 | ctx->cfg.local_time = 0; |
206 | ctx->cfg.max_repo_count = 50; |
229 | ctx->cfg.max_repo_count = 50; |
207 | ctx->cfg.max_commit_count = 50; |
230 | ctx->cfg.max_commit_count = 50; |
208 | ctx->cfg.max_lock_attempts = 5; |
231 | ctx->cfg.max_lock_attempts = 5; |
209 | ctx->cfg.max_msg_len = 80; |
232 | ctx->cfg.max_msg_len = 80; |
210 | ctx->cfg.max_repodesc_len = 80; |
233 | ctx->cfg.max_repodesc_len = 80; |
211 | ctx->cfg.max_stats = 0; |
234 | ctx->cfg.max_stats = 0; |
212 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
235 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
213 | ctx->cfg.renamelimit = -1; |
236 | ctx->cfg.renamelimit = -1; |
214 | ctx->cfg.robots = "index, nofollow"; |
237 | ctx->cfg.robots = "index, nofollow"; |
215 | ctx->cfg.root_title = "Git repository browser"; |
238 | ctx->cfg.root_title = "Git repository browser"; |
216 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
239 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
217 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
240 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
218 | ctx->cfg.summary_branches = 10; |
241 | ctx->cfg.summary_branches = 10; |
219 | ctx->cfg.summary_log = 10; |
242 | ctx->cfg.summary_log = 10; |
220 | ctx->cfg.summary_tags = 10; |
243 | ctx->cfg.summary_tags = 10; |
221 | ctx->page.mimetype = "text/html"; |
244 | ctx->page.mimetype = "text/html"; |
222 | ctx->page.charset = PAGE_ENCODING; |
245 | ctx->page.charset = PAGE_ENCODING; |
223 | ctx->page.filename = NULL; |
246 | ctx->page.filename = NULL; |
224 | ctx->page.size = 0; |
247 | ctx->page.size = 0; |
225 | ctx->page.modified = time(NULL); |
248 | ctx->page.modified = time(NULL); |
226 | ctx->page.expires = ctx->page.modified; |
249 | ctx->page.expires = ctx->page.modified; |
227 | ctx->page.etag = NULL; |
250 | ctx->page.etag = NULL; |
228 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
251 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
229 | } |
252 | } |
230 | |
253 | |
231 | struct refmatch { |
254 | struct refmatch { |
232 | char *req_ref; |
255 | char *req_ref; |
233 | char *first_ref; |
256 | char *first_ref; |
234 | int match; |
257 | int match; |
235 | }; |
258 | }; |
236 | |
259 | |
237 | int find_current_ref(const char *refname, const unsigned char *sha1, |
260 | int find_current_ref(const char *refname, const unsigned char *sha1, |
238 | int flags, void *cb_data) |
261 | int flags, void *cb_data) |
239 | { |
262 | { |
240 | struct refmatch *info; |
263 | struct refmatch *info; |
241 | |
264 | |
242 | info = (struct refmatch *)cb_data; |
265 | info = (struct refmatch *)cb_data; |
243 | if (!strcmp(refname, info->req_ref)) |
266 | if (!strcmp(refname, info->req_ref)) |
244 | info->match = 1; |
267 | info->match = 1; |
245 | if (!info->first_ref) |
268 | if (!info->first_ref) |
246 | info->first_ref = xstrdup(refname); |
269 | info->first_ref = xstrdup(refname); |
247 | return info->match; |
270 | return info->match; |
248 | } |
271 | } |
249 | |
272 | |
250 | char *find_default_branch(struct cgit_repo *repo) |
273 | char *find_default_branch(struct cgit_repo *repo) |
251 | { |
274 | { |
252 | struct refmatch info; |
275 | struct refmatch info; |
253 | char *ref; |
276 | char *ref; |
254 | |
277 | |
255 | info.req_ref = repo->defbranch; |
278 | info.req_ref = repo->defbranch; |
256 | info.first_ref = NULL; |
279 | info.first_ref = NULL; |
257 | info.match = 0; |
280 | info.match = 0; |
258 | for_each_branch_ref(find_current_ref, &info); |
281 | for_each_branch_ref(find_current_ref, &info); |
259 | if (info.match) |
282 | if (info.match) |
260 | ref = info.req_ref; |
283 | ref = info.req_ref; |
261 | else |
284 | else |
262 | ref = info.first_ref; |
285 | ref = info.first_ref; |
263 | if (ref) |
286 | if (ref) |
264 | ref = xstrdup(ref); |
287 | ref = xstrdup(ref); |
265 | return ref; |
288 | return ref; |
266 | } |
289 | } |
267 | |
290 | |
268 | static int prepare_repo_cmd(struct cgit_context *ctx) |
291 | static int prepare_repo_cmd(struct cgit_context *ctx) |
269 | { |
292 | { |
|