aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2008-04-09 04:29:21 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2008-04-09 04:29:21 (JST)
commit23296ad648c0e2a9e3cf40a3de322b10ad25cce3 (patch)
tree136493d8228b0ff4971feb06b0e8aee296367b00 /shared.c
parente2a44cf0923398396b7a321d5ce894ad3bf6f580 (diff)
parentc6f747649ace1a92ed5dfaae9cc1ea3affe0bf51 (diff)
downloadcgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.zip
cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.tar.gz
Merge branch 'lh/cleanup'
* lh/cleanup: (21 commits) Reset ctx.repo to NULL when the config parser is finished Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring() Move function for configfile parsing into configfile.[ch] Add cache.h Remove global and obsolete cgit_cmd Makefile: copy the QUIET constructs from the Makefile in git.git Move cgit_version from shared.c to cgit.c Makefile: autobuild dependency rules Initial Makefile cleanup Move non-generic functions from shared.c to cgit.c Add ui-shared.h Add separate header-files for each page/view Refactor snapshot support Add command dispatcher Remove obsolete cacheitem parameter to ui-functions Add struct cgit_page to cgit_context Introduce html.h Improve initialization of git directory Move cgit_repo into cgit_context Add all config variables into struct cgit_context ...
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c257
1 files changed, 40 insertions, 217 deletions
diff --git a/shared.c b/shared.c
index f063894..f5875e4 100644
--- a/shared.c
+++ b/shared.c
@@ -8,77 +8,10 @@
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct repolist cgit_repolist; 11struct cgit_repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct cgit_context ctx;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION;
16
17char *cgit_root_title = "Git repository browser";
18char *cgit_css = "/cgit.css";
19char *cgit_logo = "/git-logo.png";
20char *cgit_index_header = NULL;
21char *cgit_index_info = NULL;
22char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
23char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
24char *cgit_agefile = "info/web/last-modified";
25char *cgit_virtual_root = NULL;
26char *cgit_script_name = CGIT_SCRIPT_NAME;
27char *cgit_cache_root = CGIT_CACHE_ROOT;
28char *cgit_repo_group = NULL;
29char *cgit_robots = "index, nofollow";
30char *cgit_clone_prefix = NULL;
31
32int cgit_nocache = 0;
33int cgit_snapshots = 0;
34int cgit_enable_index_links = 0;
35int cgit_enable_log_filecount = 0;
36int cgit_enable_log_linecount = 0;
37int cgit_max_lock_attempts = 5;
38int cgit_cache_root_ttl = 5;
39int cgit_cache_repo_ttl = 5;
40int cgit_cache_dynamic_ttl = 5;
41int cgit_cache_static_ttl = -1;
42int cgit_cache_max_create_time = 5;
43int cgit_summary_log = 0;
44int cgit_summary_tags = 0;
45int cgit_summary_branches = 0;
46int cgit_renamelimit = -1;
47
48int cgit_max_msg_len = 60;
49int cgit_max_repodesc_len = 60;
50int cgit_max_commit_count = 50;
51
52int cgit_query_has_symref = 0;
53int cgit_query_has_sha1 = 0;
54
55char *cgit_querystring = NULL;
56char *cgit_query_repo = NULL;
57char *cgit_query_page = NULL;
58char *cgit_query_head = NULL;
59char *cgit_query_search = NULL;
60char *cgit_query_grep = NULL;
61char *cgit_query_sha1 = NULL;
62char *cgit_query_sha2 = NULL;
63char *cgit_query_path = NULL;
64char *cgit_query_name = NULL;
65int cgit_query_ofs = 0;
66
67int htmlfd = 0;
68
69
70int cgit_get_cmd_index(const char *cmd)
71{
72 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
73 "snapshot", "tag", "refs", "patch", NULL};
74 int i;
75
76 for(i = 0; cmds[i]; i++)
77 if (!strcmp(cmd, cmds[i]))
78 return i + 1;
79 return 0;
80}
81
82int chk_zero(int result, char *msg) 15int chk_zero(int result, char *msg)
83{ 16{
84 if (result != 0) 17 if (result != 0)
@@ -100,9 +33,9 @@ int chk_non_negative(int result, char *msg)
100 return result; 33 return result;
101} 34}
102 35
103struct repoinfo *add_repo(const char *url) 36struct cgit_repo *cgit_add_repo(const char *url)
104{ 37{
105 struct repoinfo *ret; 38 struct cgit_repo *ret;
106 39
107 if (++cgit_repolist.count > cgit_repolist.length) { 40 if (++cgit_repolist.count > cgit_repolist.length) {
108 if (cgit_repolist.length == 0) 41 if (cgit_repolist.length == 0)
@@ -111,7 +44,7 @@ struct repoinfo *add_repo(const char *url)
111 cgit_repolist.length *= 2; 44 cgit_repolist.length *= 2;
112 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 45 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
113 cgit_repolist.length * 46 cgit_repolist.length *
114 sizeof(struct repoinfo)); 47 sizeof(struct cgit_repo));
115 } 48 }
116 49
117 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 50 ret = &cgit_repolist.repos[cgit_repolist.count-1];
@@ -120,20 +53,20 @@ struct repoinfo *add_repo(const char *url)
120 ret->path = NULL; 53 ret->path = NULL;
121 ret->desc = "[no description]"; 54 ret->desc = "[no description]";
122 ret->owner = NULL; 55 ret->owner = NULL;
123 ret->group = cgit_repo_group; 56 ret->group = ctx.cfg.repo_group;
124 ret->defbranch = "master"; 57 ret->defbranch = "master";
125 ret->snapshots = cgit_snapshots; 58 ret->snapshots = ctx.cfg.snapshots;
126 ret->enable_log_filecount = cgit_enable_log_filecount; 59 ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
127 ret->enable_log_linecount = cgit_enable_log_linecount; 60 ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
128 ret->module_link = cgit_module_link; 61 ret->module_link = ctx.cfg.module_link;
129 ret->readme = NULL; 62 ret->readme = NULL;
130 return ret; 63 return ret;
131} 64}
132 65
133struct repoinfo *cgit_get_repoinfo(const char *url) 66struct cgit_repo *cgit_get_repoinfo(const char *url)
134{ 67{
135 int i; 68 int i;
136 struct repoinfo *repo; 69 struct cgit_repo *repo;
137 70
138 for (i=0; i<cgit_repolist.count; i++) { 71 for (i=0; i<cgit_repolist.count; i++) {
139 repo = &cgit_repolist.repos[i]; 72 repo = &cgit_repolist.repos[i];
@@ -143,131 +76,6 @@ struct repoinfo *cgit_get_repoinfo(const char *url)
143 return NULL; 76 return NULL;
144} 77}
145 78
146void cgit_global_config_cb(const char *name, const char *value)
147{
148 if (!strcmp(name, "root-title"))
149 cgit_root_title = xstrdup(value);
150 else if (!strcmp(name, "css"))
151 cgit_css = xstrdup(value);
152 else if (!strcmp(name, "logo"))
153 cgit_logo = xstrdup(value);
154 else if (!strcmp(name, "index-header"))
155 cgit_index_header = xstrdup(value);
156 else if (!strcmp(name, "index-info"))
157 cgit_index_info = xstrdup(value);
158 else if (!strcmp(name, "logo-link"))
159 cgit_logo_link = xstrdup(value);
160 else if (!strcmp(name, "module-link"))
161 cgit_module_link = xstrdup(value);
162 else if (!strcmp(name, "virtual-root")) {
163 cgit_virtual_root = trim_end(value, '/');
164 if (!cgit_virtual_root && (!strcmp(value, "/")))
165 cgit_virtual_root = "";
166 } else if (!strcmp(name, "nocache"))
167 cgit_nocache = atoi(value);
168 else if (!strcmp(name, "snapshots"))
169 cgit_snapshots = cgit_parse_snapshots_mask(value);
170 else if (!strcmp(name, "enable-index-links"))
171 cgit_enable_index_links = atoi(value);
172 else if (!strcmp(name, "enable-log-filecount"))
173 cgit_enable_log_filecount = atoi(value);
174 else if (!strcmp(name, "enable-log-linecount"))
175 cgit_enable_log_linecount = atoi(value);
176 else if (!strcmp(name, "cache-root"))
177 cgit_cache_root = xstrdup(value);
178 else if (!strcmp(name, "cache-root-ttl"))
179 cgit_cache_root_ttl = atoi(value);
180 else if (!strcmp(name, "cache-repo-ttl"))
181 cgit_cache_repo_ttl = atoi(value);
182 else if (!strcmp(name, "cache-static-ttl"))
183 cgit_cache_static_ttl = atoi(value);
184 else if (!strcmp(name, "cache-dynamic-ttl"))
185 cgit_cache_dynamic_ttl = atoi(value);
186 else if (!strcmp(name, "max-message-length"))
187 cgit_max_msg_len = atoi(value);
188 else if (!strcmp(name, "max-repodesc-length"))
189 cgit_max_repodesc_len = atoi(value);
190 else if (!strcmp(name, "max-commit-count"))
191 cgit_max_commit_count = atoi(value);
192 else if (!strcmp(name, "summary-log"))
193 cgit_summary_log = atoi(value);
194 else if (!strcmp(name, "summary-branches"))
195 cgit_summary_branches = atoi(value);
196 else if (!strcmp(name, "summary-tags"))
197 cgit_summary_tags = atoi(value);
198 else if (!strcmp(name, "agefile"))
199 cgit_agefile = xstrdup(value);
200 else if (!strcmp(name, "renamelimit"))
201 cgit_renamelimit = atoi(value);
202 else if (!strcmp(name, "robots"))
203 cgit_robots = xstrdup(value);
204 else if (!strcmp(name, "clone-prefix"))
205 cgit_clone_prefix = xstrdup(value);
206 else if (!strcmp(name, "repo.group"))
207 cgit_repo_group = xstrdup(value);
208 else if (!strcmp(name, "repo.url"))
209 cgit_repo = add_repo(value);
210 else if (!strcmp(name, "repo.name"))
211 cgit_repo->name = xstrdup(value);
212 else if (cgit_repo && !strcmp(name, "repo.path"))
213 cgit_repo->path = trim_end(value, '/');
214 else if (cgit_repo && !strcmp(name, "repo.clone-url"))
215 cgit_repo->clone_url = xstrdup(value);
216 else if (cgit_repo && !strcmp(name, "repo.desc"))
217 cgit_repo->desc = xstrdup(value);
218 else if (cgit_repo && !strcmp(name, "repo.owner"))
219 cgit_repo->owner = xstrdup(value);
220 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
221 cgit_repo->defbranch = xstrdup(value);
222 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
223 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
224 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount"))
225 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value);
226 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
227 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value);
228 else if (cgit_repo && !strcmp(name, "repo.module-link"))
229 cgit_repo->module_link= xstrdup(value);
230 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) {
231 if (*value == '/')
232 cgit_repo->readme = xstrdup(value);
233 else
234 cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value));
235 } else if (!strcmp(name, "include"))
236 cgit_read_config(value, cgit_global_config_cb);
237}
238
239void cgit_querystring_cb(const char *name, const char *value)
240{
241 if (!strcmp(name,"r")) {
242 cgit_query_repo = xstrdup(value);
243 cgit_repo = cgit_get_repoinfo(value);
244 } else if (!strcmp(name, "p")) {
245 cgit_query_page = xstrdup(value);
246 cgit_cmd = cgit_get_cmd_index(value);
247 } else if (!strcmp(name, "url")) {
248 cgit_parse_url(value);
249 } else if (!strcmp(name, "qt")) {
250 cgit_query_grep = xstrdup(value);
251 } else if (!strcmp(name, "q")) {
252 cgit_query_search = xstrdup(value);
253 } else if (!strcmp(name, "h")) {
254 cgit_query_head = xstrdup(value);
255 cgit_query_has_symref = 1;
256 } else if (!strcmp(name, "id")) {
257 cgit_query_sha1 = xstrdup(value);
258 cgit_query_has_sha1 = 1;
259 } else if (!strcmp(name, "id2")) {
260 cgit_query_sha2 = xstrdup(value);
261 cgit_query_has_sha1 = 1;
262 } else if (!strcmp(name, "ofs")) {
263 cgit_query_ofs = atoi(value);
264 } else if (!strcmp(name, "path")) {
265 cgit_query_path = trim_end(value, '/');
266 } else if (!strcmp(name, "name")) {
267 cgit_query_name = xstrdup(value);
268 }
269}
270
271void *cgit_free_commitinfo(struct commitinfo *info) 79void *cgit_free_commitinfo(struct commitinfo *info)
272{ 80{
273 free(info->author); 81 free(info->author);
@@ -281,18 +89,6 @@ void *cgit_free_commitinfo(struct commitinfo *info)
281 return NULL; 89 return NULL;
282} 90}
283 91
284int hextoint(char c)
285{
286 if (c >= 'a' && c <= 'f')
287 return 10 + c - 'a';
288 else if (c >= 'A' && c <= 'F')
289 return 10 + c - 'A';
290 else if (c >= '0' && c <= '9')
291 return c - '0';
292 else
293 return -1;
294}
295
296char *trim_end(const char *str, char c) 92char *trim_end(const char *str, char c)
297{ 93{
298 int len; 94 int len;
@@ -491,7 +287,7 @@ void cgit_diff_tree(const unsigned char *old_sha1,
491 diff_setup(&opt); 287 diff_setup(&opt);
492 opt.output_format = DIFF_FORMAT_CALLBACK; 288 opt.output_format = DIFF_FORMAT_CALLBACK;
493 opt.detect_rename = 1; 289 opt.detect_rename = 1;
494 opt.rename_limit = cgit_renamelimit; 290 opt.rename_limit = ctx.cfg.renamelimit;
495 DIFF_OPT_SET(&opt, RECURSIVE); 291 DIFF_OPT_SET(&opt, RECURSIVE);
496 opt.format_callback = cgit_diff_tree_cb; 292 opt.format_callback = cgit_diff_tree_cb;
497 opt.format_callback_data = fn; 293 opt.format_callback_data = fn;
@@ -519,3 +315,30 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn)
519 old_sha1 = commit->parents->item->object.sha1; 315 old_sha1 = commit->parents->item->object.sha1;
520 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); 316 cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
521} 317}
318
319int cgit_parse_snapshots_mask(const char *str)
320{
321 const struct cgit_snapshot_format *f;
322 static const char *delim = " \t,:/|;";
323 int tl, sl, rv = 0;
324
325 /* favor legacy setting */
326 if(atoi(str))
327 return 1;
328 for(;;) {
329 str += strspn(str,delim);
330 tl = strcspn(str,delim);
331 if (!tl)
332 break;
333 for (f = cgit_snapshot_formats; f->suffix; f++) {
334 sl = strlen(f->suffix);
335 if((tl == sl && !strncmp(f->suffix, str, tl)) ||
336 (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
337 rv |= f->bit;
338 break;
339 }
340 }
341 str += tl;
342 }
343 return rv;
344}