author | Lars Hjemli <hjemli@gmail.com> | 2008-03-23 23:51:19 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-03-23 23:51:19 (UTC) |
commit | f3c1a187fe2bc33f8423cd535d5045899699995b (patch) (unidiff) | |
tree | b5c553da7b108900535fcfcd24b78bdd0ac62387 /cgit.c | |
parent | b1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (diff) | |
download | cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.zip cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.gz cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.bz2 |
Add struct cgit_page to cgit_context
This struct is used when generating http headers, and as such is another
small step towards the goal of the whole cleanup series; to invoke each
page/view function with a function pointer.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 50 |
1 files changed, 33 insertions, 17 deletions
@@ -1,316 +1,332 @@ | |||
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 "cmd.h" | ||
10 | 11 | ||
11 | static int cgit_prepare_cache(struct cacheitem *item) | 12 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 13 | { |
13 | if (!ctx.repo && ctx.qry.repo) { | 14 | if (!ctx.repo && ctx.qry.repo) { |
14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 15 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
15 | cgit_print_docstart(title, item); | 16 | "Bad request"); |
16 | cgit_print_pageheader(title, 0); | 17 | cgit_print_http_headers(&ctx); |
18 | cgit_print_docstart(&ctx); | ||
19 | cgit_print_pageheader(&ctx); | ||
17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | 20 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
18 | cgit_print_docend(); | 21 | cgit_print_docend(); |
19 | return 0; | 22 | return 0; |
20 | } | 23 | } |
21 | 24 | ||
22 | if (!ctx.repo) { | 25 | if (!ctx.repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); | 26 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
24 | item->ttl = ctx.cfg.cache_root_ttl; | 27 | item->ttl = ctx.cfg.cache_root_ttl; |
25 | return 1; | 28 | return 1; |
26 | } | 29 | } |
27 | 30 | ||
28 | if (!cgit_cmd) { | 31 | if (!cgit_cmd) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, | 32 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
30 | cache_safe_filename(ctx.repo->url), | 33 | cache_safe_filename(ctx.repo->url), |
31 | cache_safe_filename(ctx.qry.raw))); | 34 | cache_safe_filename(ctx.qry.raw))); |
32 | item->ttl = ctx.cfg.cache_repo_ttl; | 35 | item->ttl = ctx.cfg.cache_repo_ttl; |
33 | } else { | 36 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, | 37 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
35 | cache_safe_filename(ctx.repo->url), | 38 | cache_safe_filename(ctx.repo->url), |
36 | ctx.qry.page, | 39 | ctx.qry.page, |
37 | cache_safe_filename(ctx.qry.raw))); | 40 | cache_safe_filename(ctx.qry.raw))); |
38 | if (ctx.qry.has_symref) | 41 | if (ctx.qry.has_symref) |
39 | item->ttl = ctx.cfg.cache_dynamic_ttl; | 42 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
40 | else if (ctx.qry.has_sha1) | 43 | else if (ctx.qry.has_sha1) |
41 | item->ttl = ctx.cfg.cache_static_ttl; | 44 | item->ttl = ctx.cfg.cache_static_ttl; |
42 | else | 45 | else |
43 | item->ttl = ctx.cfg.cache_repo_ttl; | 46 | item->ttl = ctx.cfg.cache_repo_ttl; |
44 | } | 47 | } |
45 | return 1; | 48 | return 1; |
46 | } | 49 | } |
47 | 50 | ||
48 | struct refmatch { | 51 | struct refmatch { |
49 | char *req_ref; | 52 | char *req_ref; |
50 | char *first_ref; | 53 | char *first_ref; |
51 | int match; | 54 | int match; |
52 | }; | 55 | }; |
53 | 56 | ||
54 | int find_current_ref(const char *refname, const unsigned char *sha1, | 57 | int find_current_ref(const char *refname, const unsigned char *sha1, |
55 | int flags, void *cb_data) | 58 | int flags, void *cb_data) |
56 | { | 59 | { |
57 | struct refmatch *info; | 60 | struct refmatch *info; |
58 | 61 | ||
59 | info = (struct refmatch *)cb_data; | 62 | info = (struct refmatch *)cb_data; |
60 | if (!strcmp(refname, info->req_ref)) | 63 | if (!strcmp(refname, info->req_ref)) |
61 | info->match = 1; | 64 | info->match = 1; |
62 | if (!info->first_ref) | 65 | if (!info->first_ref) |
63 | info->first_ref = xstrdup(refname); | 66 | info->first_ref = xstrdup(refname); |
64 | return info->match; | 67 | return info->match; |
65 | } | 68 | } |
66 | 69 | ||
67 | char *find_default_branch(struct cgit_repo *repo) | 70 | char *find_default_branch(struct cgit_repo *repo) |
68 | { | 71 | { |
69 | struct refmatch info; | 72 | struct refmatch info; |
70 | 73 | ||
71 | info.req_ref = repo->defbranch; | 74 | info.req_ref = repo->defbranch; |
72 | info.first_ref = NULL; | 75 | info.first_ref = NULL; |
73 | info.match = 0; | 76 | info.match = 0; |
74 | for_each_branch_ref(find_current_ref, &info); | 77 | for_each_branch_ref(find_current_ref, &info); |
75 | if (info.match) | 78 | if (info.match) |
76 | return info.req_ref; | 79 | return info.req_ref; |
77 | else | 80 | else |
78 | return info.first_ref; | 81 | return info.first_ref; |
79 | } | 82 | } |
80 | 83 | ||
81 | static void cgit_print_repo_page(struct cacheitem *item) | 84 | static void cgit_print_repo_page(struct cacheitem *item) |
82 | { | 85 | { |
83 | char *title, *tmp; | 86 | char *tmp; |
84 | int show_search; | 87 | int show_search; |
85 | unsigned char sha1[20]; | 88 | unsigned char sha1[20]; |
86 | int nongit = 0; | 89 | int nongit = 0; |
87 | 90 | ||
88 | setenv("GIT_DIR", ctx.repo->path, 1); | 91 | setenv("GIT_DIR", ctx.repo->path, 1); |
89 | setup_git_directory_gently(&nongit); | 92 | setup_git_directory_gently(&nongit); |
90 | if (nongit) { | 93 | if (nongit) { |
91 | title = fmt("%s - %s", ctx.cfg.root_title, "config error"); | 94 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
95 | "config error"); | ||
92 | tmp = fmt("Not a git repository: '%s'", ctx.repo->path); | 96 | tmp = fmt("Not a git repository: '%s'", ctx.repo->path); |
93 | ctx.repo = NULL; | 97 | ctx.repo = NULL; |
94 | cgit_print_docstart(title, item); | 98 | cgit_print_http_headers(&ctx); |
95 | cgit_print_pageheader(title, 0); | 99 | cgit_print_docstart(&ctx); |
100 | cgit_print_pageheader(&ctx); | ||
96 | cgit_print_error(tmp); | 101 | cgit_print_error(tmp); |
97 | cgit_print_docend(); | 102 | cgit_print_docend(); |
98 | return; | 103 | return; |
99 | } | 104 | } |
100 | 105 | ||
101 | title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); | 106 | ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); |
102 | show_search = 0; | 107 | show_search = 0; |
103 | 108 | ||
104 | if (!ctx.qry.head) { | 109 | if (!ctx.qry.head) { |
105 | ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); | 110 | ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); |
106 | ctx.repo->defbranch = ctx.qry.head; | 111 | ctx.repo->defbranch = ctx.qry.head; |
107 | } | 112 | } |
108 | 113 | ||
109 | if (!ctx.qry.head) { | 114 | if (!ctx.qry.head) { |
110 | cgit_print_docstart(title, item); | 115 | cgit_print_http_headers(&ctx); |
111 | cgit_print_pageheader(title, 0); | 116 | cgit_print_docstart(&ctx); |
117 | cgit_print_pageheader(&ctx); | ||
112 | cgit_print_error("Repository seems to be empty"); | 118 | cgit_print_error("Repository seems to be empty"); |
113 | cgit_print_docend(); | 119 | cgit_print_docend(); |
114 | return; | 120 | return; |
115 | } | 121 | } |
116 | 122 | ||
117 | if (get_sha1(ctx.qry.head, sha1)) { | 123 | if (get_sha1(ctx.qry.head, sha1)) { |
118 | tmp = xstrdup(ctx.qry.head); | 124 | tmp = xstrdup(ctx.qry.head); |
119 | ctx.qry.head = ctx.repo->defbranch; | 125 | ctx.qry.head = ctx.repo->defbranch; |
120 | cgit_print_docstart(title, item); | 126 | cgit_print_http_headers(&ctx); |
121 | cgit_print_pageheader(title, 0); | 127 | cgit_print_docstart(&ctx); |
128 | cgit_print_pageheader(&ctx); | ||
122 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 129 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
123 | cgit_print_docend(); | 130 | cgit_print_docend(); |
124 | return; | 131 | return; |
125 | } | 132 | } |
126 | 133 | ||
127 | if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { | 134 | if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { |
128 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, | 135 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, |
129 | cgit_repobasename(ctx.repo->url), | 136 | cgit_repobasename(ctx.repo->url), |
130 | ctx.qry.path, | 137 | ctx.qry.path, |
131 | ctx.repo->snapshots ); | 138 | ctx.repo->snapshots ); |
132 | return; | 139 | return; |
133 | } | 140 | } |
134 | 141 | ||
135 | if (cgit_cmd == CMD_PATCH) { | 142 | if (cgit_cmd == CMD_PATCH) { |
136 | cgit_print_patch(ctx.qry.sha1, item); | 143 | cgit_print_patch(ctx.qry.sha1, item); |
137 | return; | 144 | return; |
138 | } | 145 | } |
139 | 146 | ||
140 | if (cgit_cmd == CMD_BLOB) { | 147 | if (cgit_cmd == CMD_BLOB) { |
141 | cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); | 148 | cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); |
142 | return; | 149 | return; |
143 | } | 150 | } |
144 | 151 | ||
145 | show_search = (cgit_cmd == CMD_LOG); | 152 | show_search = (cgit_cmd == CMD_LOG); |
146 | cgit_print_docstart(title, item); | 153 | cgit_print_http_headers(&ctx); |
154 | cgit_print_docstart(&ctx); | ||
147 | if (!cgit_cmd) { | 155 | if (!cgit_cmd) { |
148 | cgit_print_pageheader("summary", show_search); | 156 | cgit_print_pageheader(&ctx); |
149 | cgit_print_summary(); | 157 | cgit_print_summary(); |
150 | cgit_print_docend(); | 158 | cgit_print_docend(); |
151 | return; | 159 | return; |
152 | } | 160 | } |
153 | 161 | ||
154 | cgit_print_pageheader(ctx.qry.page, show_search); | 162 | cgit_print_pageheader(&ctx); |
155 | 163 | ||
156 | switch(cgit_cmd) { | 164 | switch(cgit_cmd) { |
157 | case CMD_LOG: | 165 | case CMD_LOG: |
158 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, | 166 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, |
159 | ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, | 167 | ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, |
160 | ctx.qry.path, 1); | 168 | ctx.qry.path, 1); |
161 | break; | 169 | break; |
162 | case CMD_TREE: | 170 | case CMD_TREE: |
163 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); | 171 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); |
164 | break; | 172 | break; |
165 | case CMD_COMMIT: | 173 | case CMD_COMMIT: |
166 | cgit_print_commit(ctx.qry.sha1); | 174 | cgit_print_commit(ctx.qry.sha1); |
167 | break; | 175 | break; |
168 | case CMD_REFS: | 176 | case CMD_REFS: |
169 | cgit_print_refs(); | 177 | cgit_print_refs(); |
170 | break; | 178 | break; |
171 | case CMD_TAG: | 179 | case CMD_TAG: |
172 | cgit_print_tag(ctx.qry.sha1); | 180 | cgit_print_tag(ctx.qry.sha1); |
173 | break; | 181 | break; |
174 | case CMD_DIFF: | 182 | case CMD_DIFF: |
175 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); | 183 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); |
176 | break; | 184 | break; |
177 | default: | 185 | default: |
178 | cgit_print_error("Invalid request"); | 186 | cgit_print_error("Invalid request"); |
179 | } | 187 | } |
180 | cgit_print_docend(); | 188 | cgit_print_docend(); |
181 | } | 189 | } |
182 | 190 | ||
191 | static long ttl_seconds(long ttl) | ||
192 | { | ||
193 | if (ttl<0) | ||
194 | return 60 * 60 * 24 * 365; | ||
195 | else | ||
196 | return ttl * 60; | ||
197 | } | ||
198 | |||
183 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 199 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
184 | { | 200 | { |
185 | int stdout2; | 201 | int stdout2; |
186 | 202 | ||
187 | item->st.st_mtime = time(NULL); | ||
188 | |||
189 | if (use_cache) { | 203 | if (use_cache) { |
190 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 204 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
191 | "Preserving STDOUT"); | 205 | "Preserving STDOUT"); |
192 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 206 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
193 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 207 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
194 | } | 208 | } |
195 | 209 | ||
210 | ctx.page.modified = time(NULL); | ||
211 | ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); | ||
196 | if (ctx.repo) | 212 | if (ctx.repo) |
197 | cgit_print_repo_page(item); | 213 | cgit_print_repo_page(item); |
198 | else | 214 | else |
199 | cgit_print_repolist(item); | 215 | cgit_print_repolist(item); |
200 | 216 | ||
201 | if (use_cache) { | 217 | if (use_cache) { |
202 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 218 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
203 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 219 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
204 | "Restoring original STDOUT"); | 220 | "Restoring original STDOUT"); |
205 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 221 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
206 | } | 222 | } |
207 | } | 223 | } |
208 | 224 | ||
209 | static void cgit_check_cache(struct cacheitem *item) | 225 | static void cgit_check_cache(struct cacheitem *item) |
210 | { | 226 | { |
211 | int i = 0; | 227 | int i = 0; |
212 | 228 | ||
213 | top: | 229 | top: |
214 | if (++i > ctx.cfg.max_lock_attempts) { | 230 | if (++i > ctx.cfg.max_lock_attempts) { |
215 | die("cgit_refresh_cache: unable to lock %s: %s", | 231 | die("cgit_refresh_cache: unable to lock %s: %s", |
216 | item->name, strerror(errno)); | 232 | item->name, strerror(errno)); |
217 | } | 233 | } |
218 | if (!cache_exist(item)) { | 234 | if (!cache_exist(item)) { |
219 | if (!cache_lock(item)) { | 235 | if (!cache_lock(item)) { |
220 | sleep(1); | 236 | sleep(1); |
221 | goto top; | 237 | goto top; |
222 | } | 238 | } |
223 | if (!cache_exist(item)) { | 239 | if (!cache_exist(item)) { |
224 | cgit_fill_cache(item, 1); | 240 | cgit_fill_cache(item, 1); |
225 | cache_unlock(item); | 241 | cache_unlock(item); |
226 | } else { | 242 | } else { |
227 | cache_cancel_lock(item); | 243 | cache_cancel_lock(item); |
228 | } | 244 | } |
229 | } else if (cache_expired(item) && cache_lock(item)) { | 245 | } else if (cache_expired(item) && cache_lock(item)) { |
230 | if (cache_expired(item)) { | 246 | if (cache_expired(item)) { |
231 | cgit_fill_cache(item, 1); | 247 | cgit_fill_cache(item, 1); |
232 | cache_unlock(item); | 248 | cache_unlock(item); |
233 | } else { | 249 | } else { |
234 | cache_cancel_lock(item); | 250 | cache_cancel_lock(item); |
235 | } | 251 | } |
236 | } | 252 | } |
237 | } | 253 | } |
238 | 254 | ||
239 | static void cgit_print_cache(struct cacheitem *item) | 255 | static void cgit_print_cache(struct cacheitem *item) |
240 | { | 256 | { |
241 | static char buf[4096]; | 257 | static char buf[4096]; |
242 | ssize_t i; | 258 | ssize_t i; |
243 | 259 | ||
244 | int fd = open(item->name, O_RDONLY); | 260 | int fd = open(item->name, O_RDONLY); |
245 | if (fd<0) | 261 | if (fd<0) |
246 | die("Unable to open cached file %s", item->name); | 262 | die("Unable to open cached file %s", item->name); |
247 | 263 | ||
248 | while((i=read(fd, buf, sizeof(buf))) > 0) | 264 | while((i=read(fd, buf, sizeof(buf))) > 0) |
249 | write(STDOUT_FILENO, buf, i); | 265 | write(STDOUT_FILENO, buf, i); |
250 | 266 | ||
251 | close(fd); | 267 | close(fd); |
252 | } | 268 | } |
253 | 269 | ||
254 | static void cgit_parse_args(int argc, const char **argv) | 270 | static void cgit_parse_args(int argc, const char **argv) |
255 | { | 271 | { |
256 | int i; | 272 | int i; |
257 | 273 | ||
258 | for (i = 1; i < argc; i++) { | 274 | for (i = 1; i < argc; i++) { |
259 | if (!strncmp(argv[i], "--cache=", 8)) { | 275 | if (!strncmp(argv[i], "--cache=", 8)) { |
260 | ctx.cfg.cache_root = xstrdup(argv[i]+8); | 276 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
261 | } | 277 | } |
262 | if (!strcmp(argv[i], "--nocache")) { | 278 | if (!strcmp(argv[i], "--nocache")) { |
263 | ctx.cfg.nocache = 1; | 279 | ctx.cfg.nocache = 1; |
264 | } | 280 | } |
265 | if (!strncmp(argv[i], "--query=", 8)) { | 281 | if (!strncmp(argv[i], "--query=", 8)) { |
266 | ctx.qry.raw = xstrdup(argv[i]+8); | 282 | ctx.qry.raw = xstrdup(argv[i]+8); |
267 | } | 283 | } |
268 | if (!strncmp(argv[i], "--repo=", 7)) { | 284 | if (!strncmp(argv[i], "--repo=", 7)) { |
269 | ctx.qry.repo = xstrdup(argv[i]+7); | 285 | ctx.qry.repo = xstrdup(argv[i]+7); |
270 | } | 286 | } |
271 | if (!strncmp(argv[i], "--page=", 7)) { | 287 | if (!strncmp(argv[i], "--page=", 7)) { |
272 | ctx.qry.page = xstrdup(argv[i]+7); | 288 | ctx.qry.page = xstrdup(argv[i]+7); |
273 | } | 289 | } |
274 | if (!strncmp(argv[i], "--head=", 7)) { | 290 | if (!strncmp(argv[i], "--head=", 7)) { |
275 | ctx.qry.head = xstrdup(argv[i]+7); | 291 | ctx.qry.head = xstrdup(argv[i]+7); |
276 | ctx.qry.has_symref = 1; | 292 | ctx.qry.has_symref = 1; |
277 | } | 293 | } |
278 | if (!strncmp(argv[i], "--sha1=", 7)) { | 294 | if (!strncmp(argv[i], "--sha1=", 7)) { |
279 | ctx.qry.sha1 = xstrdup(argv[i]+7); | 295 | ctx.qry.sha1 = xstrdup(argv[i]+7); |
280 | ctx.qry.has_sha1 = 1; | 296 | ctx.qry.has_sha1 = 1; |
281 | } | 297 | } |
282 | if (!strncmp(argv[i], "--ofs=", 6)) { | 298 | if (!strncmp(argv[i], "--ofs=", 6)) { |
283 | ctx.qry.ofs = atoi(argv[i]+6); | 299 | ctx.qry.ofs = atoi(argv[i]+6); |
284 | } | 300 | } |
285 | } | 301 | } |
286 | } | 302 | } |
287 | 303 | ||
288 | int main(int argc, const char **argv) | 304 | int main(int argc, const char **argv) |
289 | { | 305 | { |
290 | struct cacheitem item; | 306 | struct cacheitem item; |
291 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 307 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
292 | 308 | ||
293 | cgit_prepare_context(&ctx); | 309 | cgit_prepare_context(&ctx); |
294 | item.st.st_mtime = time(NULL); | 310 | item.st.st_mtime = time(NULL); |
295 | cgit_repolist.length = 0; | 311 | cgit_repolist.length = 0; |
296 | cgit_repolist.count = 0; | 312 | cgit_repolist.count = 0; |
297 | cgit_repolist.repos = NULL; | 313 | cgit_repolist.repos = NULL; |
298 | 314 | ||
299 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 315 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
300 | cgit_global_config_cb); | 316 | cgit_global_config_cb); |
301 | if (getenv("SCRIPT_NAME")) | 317 | if (getenv("SCRIPT_NAME")) |
302 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); | 318 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
303 | if (getenv("QUERY_STRING")) | 319 | if (getenv("QUERY_STRING")) |
304 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 320 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
305 | cgit_parse_args(argc, argv); | 321 | cgit_parse_args(argc, argv); |
306 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 322 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
307 | if (!cgit_prepare_cache(&item)) | 323 | if (!cgit_prepare_cache(&item)) |
308 | return 0; | 324 | return 0; |
309 | if (ctx.cfg.nocache) { | 325 | if (ctx.cfg.nocache) { |
310 | cgit_fill_cache(&item, 0); | 326 | cgit_fill_cache(&item, 0); |
311 | } else { | 327 | } else { |
312 | cgit_check_cache(&item); | 328 | cgit_check_cache(&item); |
313 | cgit_print_cache(&item); | 329 | cgit_print_cache(&item); |
314 | } | 330 | } |
315 | return 0; | 331 | return 0; |
316 | } | 332 | } |