|
diff --git a/cgit.c b/cgit.c index e8acc03..8a30c3c 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -9,13 +9,13 @@ |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | |
10 | |
11 | static int cgit_prepare_cache(struct cacheitem *item) |
11 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { |
12 | { |
13 | if (!cgit_repo && cgit_query_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", cgit_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", cgit_query_repo)); |
17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
18 | cgit_print_docend(); |
18 | cgit_print_docend(); |
19 | return 0; |
19 | return 0; |
20 | } |
20 | } |
21 | |
21 | |
@@ -27,18 +27,18 @@ static int cgit_prepare_cache(struct cacheitem *item) |
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", cgit_cache_root, |
30 | cache_safe_filename(cgit_repo->url), |
30 | cache_safe_filename(cgit_repo->url), |
31 | cache_safe_filename(cgit_querystring))); |
31 | cache_safe_filename(ctx.qry.raw))); |
32 | item->ttl = cgit_cache_repo_ttl; |
32 | item->ttl = cgit_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", cgit_cache_root, |
35 | cache_safe_filename(cgit_repo->url), |
35 | cache_safe_filename(cgit_repo->url), |
36 | cgit_query_page, |
36 | ctx.qry.page, |
37 | cache_safe_filename(cgit_querystring))); |
37 | cache_safe_filename(ctx.qry.raw))); |
38 | if (cgit_query_has_symref) |
38 | if (ctx.qry.has_symref) |
39 | item->ttl = cgit_cache_dynamic_ttl; |
39 | item->ttl = cgit_cache_dynamic_ttl; |
40 | else if (cgit_query_has_sha1) |
40 | else if (ctx.qry.has_sha1) |
41 | item->ttl = cgit_cache_static_ttl; |
41 | item->ttl = cgit_cache_static_ttl; |
42 | else |
42 | else |
43 | item->ttl = cgit_cache_repo_ttl; |
43 | item->ttl = cgit_cache_repo_ttl; |
44 | } |
44 | } |
@@ -97,46 +97,46 @@ static void cgit_print_repo_page(struct cacheitem *item) |
97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
98 | show_search = 0; |
98 | show_search = 0; |
99 | setenv("GIT_DIR", cgit_repo->path, 1); |
99 | setenv("GIT_DIR", cgit_repo->path, 1); |
100 | |
100 | |
101 | if (!cgit_query_head) { |
101 | if (!ctx.qry.head) { |
102 | cgit_query_head = xstrdup(find_default_branch(cgit_repo)); |
102 | ctx.qry.head = xstrdup(find_default_branch(cgit_repo)); |
103 | cgit_repo->defbranch = cgit_query_head; |
103 | cgit_repo->defbranch = ctx.qry.head; |
104 | } |
104 | } |
105 | |
105 | |
106 | if (!cgit_query_head) { |
106 | if (!ctx.qry.head) { |
107 | cgit_print_docstart(title, item); |
107 | cgit_print_docstart(title, item); |
108 | cgit_print_pageheader(title, 0); |
108 | cgit_print_pageheader(title, 0); |
109 | cgit_print_error("Repository seems to be empty"); |
109 | cgit_print_error("Repository seems to be empty"); |
110 | cgit_print_docend(); |
110 | cgit_print_docend(); |
111 | return; |
111 | return; |
112 | } |
112 | } |
113 | |
113 | |
114 | if (get_sha1(cgit_query_head, sha1)) { |
114 | if (get_sha1(ctx.qry.head, sha1)) { |
115 | tmp = xstrdup(cgit_query_head); |
115 | tmp = xstrdup(ctx.qry.head); |
116 | cgit_query_head = cgit_repo->defbranch; |
116 | ctx.qry.head = cgit_repo->defbranch; |
117 | cgit_print_docstart(title, item); |
117 | cgit_print_docstart(title, item); |
118 | cgit_print_pageheader(title, 0); |
118 | cgit_print_pageheader(title, 0); |
119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
120 | cgit_print_docend(); |
120 | cgit_print_docend(); |
121 | return; |
121 | return; |
122 | } |
122 | } |
123 | |
123 | |
124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
125 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, |
125 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, |
126 | cgit_repobasename(cgit_repo->url), |
126 | cgit_repobasename(cgit_repo->url), |
127 | cgit_query_path, |
127 | ctx.qry.path, |
128 | cgit_repo->snapshots ); |
128 | cgit_repo->snapshots ); |
129 | return; |
129 | return; |
130 | } |
130 | } |
131 | |
131 | |
132 | if (cgit_cmd == CMD_PATCH) { |
132 | if (cgit_cmd == CMD_PATCH) { |
133 | cgit_print_patch(cgit_query_sha1, item); |
133 | cgit_print_patch(ctx.qry.sha1, item); |
134 | return; |
134 | return; |
135 | } |
135 | } |
136 | |
136 | |
137 | if (cgit_cmd == CMD_BLOB) { |
137 | if (cgit_cmd == CMD_BLOB) { |
138 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
138 | cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); |
139 | return; |
139 | return; |
140 | } |
140 | } |
141 | |
141 | |
142 | show_search = (cgit_cmd == CMD_LOG); |
142 | show_search = (cgit_cmd == CMD_LOG); |
@@ -147,30 +147,30 @@ static void cgit_print_repo_page(struct cacheitem *item) |
147 | cgit_print_docend(); |
147 | cgit_print_docend(); |
148 | return; |
148 | return; |
149 | } |
149 | } |
150 | |
150 | |
151 | cgit_print_pageheader(cgit_query_page, show_search); |
151 | cgit_print_pageheader(ctx.qry.page, show_search); |
152 | |
152 | |
153 | switch(cgit_cmd) { |
153 | switch(cgit_cmd) { |
154 | case CMD_LOG: |
154 | case CMD_LOG: |
155 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
155 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, |
156 | cgit_max_commit_count, cgit_query_grep, cgit_query_search, |
156 | cgit_max_commit_count, ctx.qry.grep, ctx.qry.search, |
157 | cgit_query_path, 1); |
157 | ctx.qry.path, 1); |
158 | break; |
158 | break; |
159 | case CMD_TREE: |
159 | case CMD_TREE: |
160 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
160 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); |
161 | break; |
161 | break; |
162 | case CMD_COMMIT: |
162 | case CMD_COMMIT: |
163 | cgit_print_commit(cgit_query_sha1); |
163 | cgit_print_commit(ctx.qry.sha1); |
164 | break; |
164 | break; |
165 | case CMD_REFS: |
165 | case CMD_REFS: |
166 | cgit_print_refs(); |
166 | cgit_print_refs(); |
167 | break; |
167 | break; |
168 | case CMD_TAG: |
168 | case CMD_TAG: |
169 | cgit_print_tag(cgit_query_sha1); |
169 | cgit_print_tag(ctx.qry.sha1); |
170 | break; |
170 | break; |
171 | case CMD_DIFF: |
171 | case CMD_DIFF: |
172 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
172 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); |
173 | break; |
173 | break; |
174 | default: |
174 | default: |
175 | cgit_print_error("Invalid request"); |
175 | cgit_print_error("Invalid request"); |
176 | } |
176 | } |
@@ -263,26 +263,26 @@ static void cgit_parse_args(int argc, const char **argv) |
263 | if (!strcmp(argv[i], "--nocache")) { |
263 | if (!strcmp(argv[i], "--nocache")) { |
264 | cgit_nocache = 1; |
264 | cgit_nocache = 1; |
265 | } |
265 | } |
266 | if (!strncmp(argv[i], "--query=", 8)) { |
266 | if (!strncmp(argv[i], "--query=", 8)) { |
267 | cgit_querystring = xstrdup(argv[i]+8); |
267 | ctx.qry.raw = xstrdup(argv[i]+8); |
268 | } |
268 | } |
269 | if (!strncmp(argv[i], "--repo=", 7)) { |
269 | if (!strncmp(argv[i], "--repo=", 7)) { |
270 | cgit_query_repo = xstrdup(argv[i]+7); |
270 | ctx.qry.repo = xstrdup(argv[i]+7); |
271 | } |
271 | } |
272 | if (!strncmp(argv[i], "--page=", 7)) { |
272 | if (!strncmp(argv[i], "--page=", 7)) { |
273 | cgit_query_page = xstrdup(argv[i]+7); |
273 | ctx.qry.page = xstrdup(argv[i]+7); |
274 | } |
274 | } |
275 | if (!strncmp(argv[i], "--head=", 7)) { |
275 | if (!strncmp(argv[i], "--head=", 7)) { |
276 | cgit_query_head = xstrdup(argv[i]+7); |
276 | ctx.qry.head = xstrdup(argv[i]+7); |
277 | cgit_query_has_symref = 1; |
277 | ctx.qry.has_symref = 1; |
278 | } |
278 | } |
279 | if (!strncmp(argv[i], "--sha1=", 7)) { |
279 | if (!strncmp(argv[i], "--sha1=", 7)) { |
280 | cgit_query_sha1 = xstrdup(argv[i]+7); |
280 | ctx.qry.sha1 = xstrdup(argv[i]+7); |
281 | cgit_query_has_sha1 = 1; |
281 | ctx.qry.has_sha1 = 1; |
282 | } |
282 | } |
283 | if (!strncmp(argv[i], "--ofs=", 6)) { |
283 | if (!strncmp(argv[i], "--ofs=", 6)) { |
284 | cgit_query_ofs = atoi(argv[i]+6); |
284 | ctx.qry.ofs = atoi(argv[i]+6); |
285 | } |
285 | } |
286 | } |
286 | } |
287 | } |
287 | } |
288 | |
288 | |
@@ -302,11 +302,11 @@ int main(int argc, const char **argv) |
302 | cgit_repo = NULL; |
302 | cgit_repo = NULL; |
303 | if (getenv("SCRIPT_NAME")) |
303 | if (getenv("SCRIPT_NAME")) |
304 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); |
304 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); |
305 | if (getenv("QUERY_STRING")) |
305 | if (getenv("QUERY_STRING")) |
306 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
306 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
307 | cgit_parse_args(argc, argv); |
307 | cgit_parse_args(argc, argv); |
308 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
308 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
309 | if (!cgit_prepare_cache(&item)) |
309 | if (!cgit_prepare_cache(&item)) |
310 | return 0; |
310 | return 0; |
311 | if (cgit_nocache) { |
311 | if (cgit_nocache) { |
312 | cgit_fill_cache(&item, 0); |
312 | cgit_fill_cache(&item, 0); |
|