summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h2
-rw-r--r--ui-shared.c2
3 files changed, 6 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c
index 64d95f9..19adadd 100644
--- a/cgit.c
+++ b/cgit.c
@@ -264,48 +264,50 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
264 cgit_print_error(tmp); 264 cgit_print_error(tmp);
265 cgit_print_docend(); 265 cgit_print_docend();
266 return 1; 266 return 1;
267 } 267 }
268 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); 268 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
269 269
270 if (!ctx->qry.head) { 270 if (!ctx->qry.head) {
271 ctx->qry.nohead = 1; 271 ctx->qry.nohead = 1;
272 ctx->qry.head = find_default_branch(ctx->repo); 272 ctx->qry.head = find_default_branch(ctx->repo);
273 ctx->repo->defbranch = ctx->qry.head; 273 ctx->repo->defbranch = ctx->qry.head;
274 } 274 }
275 275
276 if (!ctx->qry.head) { 276 if (!ctx->qry.head) {
277 cgit_print_http_headers(ctx); 277 cgit_print_http_headers(ctx);
278 cgit_print_docstart(ctx); 278 cgit_print_docstart(ctx);
279 cgit_print_pageheader(ctx); 279 cgit_print_pageheader(ctx);
280 cgit_print_error("Repository seems to be empty"); 280 cgit_print_error("Repository seems to be empty");
281 cgit_print_docend(); 281 cgit_print_docend();
282 return 1; 282 return 1;
283 } 283 }
284 284
285 if (get_sha1(ctx->qry.head, sha1)) { 285 if (get_sha1(ctx->qry.head, sha1)) {
286 tmp = xstrdup(ctx->qry.head); 286 tmp = xstrdup(ctx->qry.head);
287 ctx->qry.head = ctx->repo->defbranch; 287 ctx->qry.head = ctx->repo->defbranch;
288 ctx->page.status = 404;
289 ctx->page.statusmsg = "not found";
288 cgit_print_http_headers(ctx); 290 cgit_print_http_headers(ctx);
289 cgit_print_docstart(ctx); 291 cgit_print_docstart(ctx);
290 cgit_print_pageheader(ctx); 292 cgit_print_pageheader(ctx);
291 cgit_print_error(fmt("Invalid branch: %s", tmp)); 293 cgit_print_error(fmt("Invalid branch: %s", tmp));
292 cgit_print_docend(); 294 cgit_print_docend();
293 return 1; 295 return 1;
294 } 296 }
295 return 0; 297 return 0;
296} 298}
297 299
298static void process_request(void *cbdata) 300static void process_request(void *cbdata)
299{ 301{
300 struct cgit_context *ctx = cbdata; 302 struct cgit_context *ctx = cbdata;
301 struct cgit_cmd *cmd; 303 struct cgit_cmd *cmd;
302 304
303 cmd = cgit_get_cmd(ctx); 305 cmd = cgit_get_cmd(ctx);
304 if (!cmd) { 306 if (!cmd) {
305 ctx->page.title = "cgit error"; 307 ctx->page.title = "cgit error";
306 cgit_print_http_headers(ctx); 308 cgit_print_http_headers(ctx);
307 cgit_print_docstart(ctx); 309 cgit_print_docstart(ctx);
308 cgit_print_pageheader(ctx); 310 cgit_print_pageheader(ctx);
309 cgit_print_error("Invalid request"); 311 cgit_print_error("Invalid request");
310 cgit_print_docend(); 312 cgit_print_docend();
311 return; 313 return;
diff --git a/cgit.h b/cgit.h
index 5f7af51..00aca4c 100644
--- a/cgit.h
+++ b/cgit.h
@@ -160,48 +160,50 @@ struct cgit_config {
160 int enable_log_linecount; 160 int enable_log_linecount;
161 int local_time; 161 int local_time;
162 int max_repo_count; 162 int max_repo_count;
163 int max_commit_count; 163 int max_commit_count;
164 int max_lock_attempts; 164 int max_lock_attempts;
165 int max_msg_len; 165 int max_msg_len;
166 int max_repodesc_len; 166 int max_repodesc_len;
167 int max_stats; 167 int max_stats;
168 int nocache; 168 int nocache;
169 int renamelimit; 169 int renamelimit;
170 int snapshots; 170 int snapshots;
171 int summary_branches; 171 int summary_branches;
172 int summary_log; 172 int summary_log;
173 int summary_tags; 173 int summary_tags;
174}; 174};
175 175
176struct cgit_page { 176struct cgit_page {
177 time_t modified; 177 time_t modified;
178 time_t expires; 178 time_t expires;
179 size_t size; 179 size_t size;
180 char *mimetype; 180 char *mimetype;
181 char *charset; 181 char *charset;
182 char *filename; 182 char *filename;
183 char *title; 183 char *title;
184 int status;
185 char *statusmsg;
184}; 186};
185 187
186struct cgit_context { 188struct cgit_context {
187 struct cgit_query qry; 189 struct cgit_query qry;
188 struct cgit_config cfg; 190 struct cgit_config cfg;
189 struct cgit_repo *repo; 191 struct cgit_repo *repo;
190 struct cgit_page page; 192 struct cgit_page page;
191}; 193};
192 194
193struct cgit_snapshot_format { 195struct cgit_snapshot_format {
194 const char *suffix; 196 const char *suffix;
195 const char *mimetype; 197 const char *mimetype;
196 write_archive_fn_t write_func; 198 write_archive_fn_t write_func;
197 int bit; 199 int bit;
198}; 200};
199 201
200extern const char *cgit_version; 202extern const char *cgit_version;
201 203
202extern struct cgit_repolist cgit_repolist; 204extern struct cgit_repolist cgit_repolist;
203extern struct cgit_context ctx; 205extern struct cgit_context ctx;
204extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 206extern const struct cgit_snapshot_format cgit_snapshot_formats[];
205 207
206extern struct cgit_repo *cgit_add_repo(const char *url); 208extern struct cgit_repo *cgit_add_repo(const char *url);
207extern struct cgit_repo *cgit_get_repoinfo(const char *url); 209extern struct cgit_repo *cgit_get_repoinfo(const char *url);
diff --git a/ui-shared.c b/ui-shared.c
index 5ce2bc5..29036d0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -446,48 +446,50 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
446 secs * 1.0 / TM_HOUR); 446 secs * 1.0 / TM_HOUR);
447 return; 447 return;
448 } 448 }
449 if (secs < TM_WEEK * 2) { 449 if (secs < TM_WEEK * 2) {
450 htmlf("<span class='age-days'>%.0f days</span>", 450 htmlf("<span class='age-days'>%.0f days</span>",
451 secs * 1.0 / TM_DAY); 451 secs * 1.0 / TM_DAY);
452 return; 452 return;
453 } 453 }
454 if (secs < TM_MONTH * 2) { 454 if (secs < TM_MONTH * 2) {
455 htmlf("<span class='age-weeks'>%.0f weeks</span>", 455 htmlf("<span class='age-weeks'>%.0f weeks</span>",
456 secs * 1.0 / TM_WEEK); 456 secs * 1.0 / TM_WEEK);
457 return; 457 return;
458 } 458 }
459 if (secs < TM_YEAR * 2) { 459 if (secs < TM_YEAR * 2) {
460 htmlf("<span class='age-months'>%.0f months</span>", 460 htmlf("<span class='age-months'>%.0f months</span>",
461 secs * 1.0 / TM_MONTH); 461 secs * 1.0 / TM_MONTH);
462 return; 462 return;
463 } 463 }
464 htmlf("<span class='age-years'>%.0f years</span>", 464 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 465 secs * 1.0 / TM_YEAR);
466} 466}
467 467
468void cgit_print_http_headers(struct cgit_context *ctx) 468void cgit_print_http_headers(struct cgit_context *ctx)
469{ 469{
470 if (ctx->page.status)
471 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
470 if (ctx->page.mimetype && ctx->page.charset) 472 if (ctx->page.mimetype && ctx->page.charset)
471 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 473 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
472 ctx->page.charset); 474 ctx->page.charset);
473 else if (ctx->page.mimetype) 475 else if (ctx->page.mimetype)
474 htmlf("Content-Type: %s\n", ctx->page.mimetype); 476 htmlf("Content-Type: %s\n", ctx->page.mimetype);
475 if (ctx->page.size) 477 if (ctx->page.size)
476 htmlf("Content-Length: %ld\n", ctx->page.size); 478 htmlf("Content-Length: %ld\n", ctx->page.size);
477 if (ctx->page.filename) 479 if (ctx->page.filename)
478 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 480 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
479 ctx->page.filename); 481 ctx->page.filename);
480 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 482 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
481 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 483 htmlf("Expires: %s\n", http_date(ctx->page.expires));
482 html("\n"); 484 html("\n");
483} 485}
484 486
485void cgit_print_docstart(struct cgit_context *ctx) 487void cgit_print_docstart(struct cgit_context *ctx)
486{ 488{
487 char *host = cgit_hosturl(); 489 char *host = cgit_hosturl();
488 html(cgit_doctype); 490 html(cgit_doctype);
489 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 491 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
490 html("<head>\n"); 492 html("<head>\n");
491 html("<title>"); 493 html("<title>");
492 html_txt(ctx->page.title); 494 html_txt(ctx->page.title);
493 html("</title>\n"); 495 html("</title>\n");