summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/cgit.c b/cgit.c
index 3943a0f..f749b6b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -136,97 +136,97 @@ static void querystring_cb(const char *name, const char *value)
136 } 136 }
137} 137}
138 138
139static void prepare_context(struct cgit_context *ctx) 139static void prepare_context(struct cgit_context *ctx)
140{ 140{
141 memset(ctx, 0, sizeof(ctx)); 141 memset(ctx, 0, sizeof(ctx));
142 ctx->cfg.agefile = "info/web/last-modified"; 142 ctx->cfg.agefile = "info/web/last-modified";
143 ctx->cfg.cache_dynamic_ttl = 5; 143 ctx->cfg.cache_dynamic_ttl = 5;
144 ctx->cfg.cache_max_create_time = 5; 144 ctx->cfg.cache_max_create_time = 5;
145 ctx->cfg.cache_repo_ttl = 5; 145 ctx->cfg.cache_repo_ttl = 5;
146 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 146 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
147 ctx->cfg.cache_root_ttl = 5; 147 ctx->cfg.cache_root_ttl = 5;
148 ctx->cfg.cache_static_ttl = -1; 148 ctx->cfg.cache_static_ttl = -1;
149 ctx->cfg.css = "/cgit.css"; 149 ctx->cfg.css = "/cgit.css";
150 ctx->cfg.logo = "/git-logo.png"; 150 ctx->cfg.logo = "/git-logo.png";
151 ctx->cfg.max_commit_count = 50; 151 ctx->cfg.max_commit_count = 50;
152 ctx->cfg.max_lock_attempts = 5; 152 ctx->cfg.max_lock_attempts = 5;
153 ctx->cfg.max_msg_len = 60; 153 ctx->cfg.max_msg_len = 60;
154 ctx->cfg.max_repodesc_len = 60; 154 ctx->cfg.max_repodesc_len = 60;
155 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 155 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
156 ctx->cfg.renamelimit = -1; 156 ctx->cfg.renamelimit = -1;
157 ctx->cfg.robots = "index, nofollow"; 157 ctx->cfg.robots = "index, nofollow";
158 ctx->cfg.root_title = "Git repository browser"; 158 ctx->cfg.root_title = "Git repository browser";
159 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 159 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
160 ctx->page.mimetype = "text/html"; 160 ctx->page.mimetype = "text/html";
161 ctx->page.charset = PAGE_ENCODING; 161 ctx->page.charset = PAGE_ENCODING;
162 ctx->page.filename = NULL; 162 ctx->page.filename = NULL;
163} 163}
164 164
165static int cgit_prepare_cache(struct cacheitem *item) 165static int cgit_prepare_cache(struct cacheitem *item)
166{ 166{
167 if (!ctx.repo && ctx.qry.repo) { 167 if (!ctx.repo && ctx.qry.repo) {
168 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, 168 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
169 "Bad request"); 169 "Bad request");
170 cgit_print_http_headers(&ctx); 170 cgit_print_http_headers(&ctx);
171 cgit_print_docstart(&ctx); 171 cgit_print_docstart(&ctx);
172 cgit_print_pageheader(&ctx); 172 cgit_print_pageheader(&ctx);
173 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); 173 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo));
174 cgit_print_docend(); 174 cgit_print_docend();
175 return 0; 175 return 0;
176 } 176 }
177 177
178 if (!ctx.repo) { 178 if (!ctx.repo) {
179 item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); 179 item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root));
180 item->ttl = ctx.cfg.cache_root_ttl; 180 item->ttl = ctx.cfg.cache_root_ttl;
181 return 1; 181 return 1;
182 } 182 }
183 183
184 if (!cgit_cmd) { 184 if (!ctx.qry.page) {
185 item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, 185 item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root,
186 cache_safe_filename(ctx.repo->url), 186 cache_safe_filename(ctx.repo->url),
187 cache_safe_filename(ctx.qry.raw))); 187 cache_safe_filename(ctx.qry.raw)));
188 item->ttl = ctx.cfg.cache_repo_ttl; 188 item->ttl = ctx.cfg.cache_repo_ttl;
189 } else { 189 } else {
190 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, 190 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root,
191 cache_safe_filename(ctx.repo->url), 191 cache_safe_filename(ctx.repo->url),
192 ctx.qry.page, 192 ctx.qry.page,
193 cache_safe_filename(ctx.qry.raw))); 193 cache_safe_filename(ctx.qry.raw)));
194 if (ctx.qry.has_symref) 194 if (ctx.qry.has_symref)
195 item->ttl = ctx.cfg.cache_dynamic_ttl; 195 item->ttl = ctx.cfg.cache_dynamic_ttl;
196 else if (ctx.qry.has_sha1) 196 else if (ctx.qry.has_sha1)
197 item->ttl = ctx.cfg.cache_static_ttl; 197 item->ttl = ctx.cfg.cache_static_ttl;
198 else 198 else
199 item->ttl = ctx.cfg.cache_repo_ttl; 199 item->ttl = ctx.cfg.cache_repo_ttl;
200 } 200 }
201 return 1; 201 return 1;
202} 202}
203 203
204struct refmatch { 204struct refmatch {
205 char *req_ref; 205 char *req_ref;
206 char *first_ref; 206 char *first_ref;
207 int match; 207 int match;
208}; 208};
209 209
210int find_current_ref(const char *refname, const unsigned char *sha1, 210int find_current_ref(const char *refname, const unsigned char *sha1,
211 int flags, void *cb_data) 211 int flags, void *cb_data)
212{ 212{
213 struct refmatch *info; 213 struct refmatch *info;
214 214
215 info = (struct refmatch *)cb_data; 215 info = (struct refmatch *)cb_data;
216 if (!strcmp(refname, info->req_ref)) 216 if (!strcmp(refname, info->req_ref))
217 info->match = 1; 217 info->match = 1;
218 if (!info->first_ref) 218 if (!info->first_ref)
219 info->first_ref = xstrdup(refname); 219 info->first_ref = xstrdup(refname);
220 return info->match; 220 return info->match;
221} 221}
222 222
223char *find_default_branch(struct cgit_repo *repo) 223char *find_default_branch(struct cgit_repo *repo)
224{ 224{
225 struct refmatch info; 225 struct refmatch info;
226 226
227 info.req_ref = repo->defbranch; 227 info.req_ref = repo->defbranch;
228 info.first_ref = NULL; 228 info.first_ref = NULL;
229 info.match = 0; 229 info.match = 0;
230 for_each_branch_ref(find_current_ref, &info); 230 for_each_branch_ref(find_current_ref, &info);
231 if (info.match) 231 if (info.match)
232 return info.req_ref; 232 return info.req_ref;