aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lukas Fleischer <cgit@cryptocrack.de>2014-01-16 05:53:15 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2014-01-17 08:44:54 (JST)
commitf60ffa143cca61e9729ac71033e1a556cf422871 (patch)
treeff9122fef2779ddea8e37806cc66dc67b63df99f
parenta431326e8fab8153905fbde036dd3c9fb4cc8eaa (diff)
downloadcgit-f60ffa143cca61e9729ac71033e1a556cf422871.zip
cgit-f60ffa143cca61e9729ac71033e1a556cf422871.tar.gz
Switch to exclusively using global ctx
Drop the context parameter from the following functions (and all static helpers used by them) and use the global context instead: * cgit_print_http_headers() * cgit_print_docstart() * cgit_print_pageheader() Remove context parameter from all commands Drop the context parameter from the following functions (and all static helpers used by them) and use the global context instead: * cgit_get_cmd() * All cgit command functions. * cgit_clone_info() * cgit_clone_objects() * cgit_clone_head() * cgit_print_plain() * cgit_show_stats() In initialization routines, use the global context variable instead of passing a pointer around locally. Remove callback data parameter for cache slots This is no longer needed since the context is always read from the global context variable. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r--cache.c14
-rw-r--r--cache.h5
-rw-r--r--cgit.c322
-rw-r--r--cmd.c102
-rw-r--r--cmd.h4
-rw-r--r--ui-atom.c2
-rw-r--r--ui-blob.c2
-rw-r--r--ui-clone.c48
-rw-r--r--ui-clone.h6
-rw-r--r--ui-diff.c2
-rw-r--r--ui-patch.c2
-rw-r--r--ui-plain.c14
-rw-r--r--ui-plain.h2
-rw-r--r--ui-repolist.c6
-rw-r--r--ui-shared.c303
-rw-r--r--ui-shared.h6
-rw-r--r--ui-snapshot.c8
-rw-r--r--ui-stats.c29
-rw-r--r--ui-stats.h2
19 files changed, 437 insertions, 442 deletions
diff --git a/cache.c b/cache.c
index fa83ddc..fcd461f 100644
--- a/cache.c
+++ b/cache.c
@@ -24,7 +24,6 @@ struct cache_slot {
24 int keylen; 24 int keylen;
25 int ttl; 25 int ttl;
26 cache_fill_fn fn; 26 cache_fill_fn fn;
27 void *cbdata;
28 int cache_fd; 27 int cache_fd;
29 int lock_fd; 28 int lock_fd;
30 const char *cache_name; 29 const char *cache_name;
@@ -187,7 +186,7 @@ static int fill_slot(struct cache_slot *slot)
187 return errno; 186 return errno;
188 187
189 /* Generate cache content */ 188 /* Generate cache content */
190 slot->fn(slot->cbdata); 189 slot->fn();
191 190
192 /* Restore stdout */ 191 /* Restore stdout */
193 if (dup2(tmp, STDOUT_FILENO) == -1) 192 if (dup2(tmp, STDOUT_FILENO) == -1)
@@ -277,7 +276,7 @@ static int process_slot(struct cache_slot *slot)
277 if ((err = lock_slot(slot)) != 0) { 276 if ((err = lock_slot(slot)) != 0) {
278 cache_log("[cgit] Unable to lock slot %s: %s (%d)\n", 277 cache_log("[cgit] Unable to lock slot %s: %s (%d)\n",
279 slot->lock_name, strerror(err), err); 278 slot->lock_name, strerror(err), err);
280 slot->fn(slot->cbdata); 279 slot->fn();
281 return 0; 280 return 0;
282 } 281 }
283 282
@@ -286,7 +285,7 @@ static int process_slot(struct cache_slot *slot)
286 slot->lock_name, strerror(err), err); 285 slot->lock_name, strerror(err), err);
287 unlock_slot(slot, 0); 286 unlock_slot(slot, 0);
288 close_lock(slot); 287 close_lock(slot);
289 slot->fn(slot->cbdata); 288 slot->fn();
290 return 0; 289 return 0;
291 } 290 }
292 // We've got a valid cache slot in the lock file, which 291 // We've got a valid cache slot in the lock file, which
@@ -310,7 +309,7 @@ static int process_slot(struct cache_slot *slot)
310 309
311/* Print cached content to stdout, generate the content if necessary. */ 310/* Print cached content to stdout, generate the content if necessary. */
312int cache_process(int size, const char *path, const char *key, int ttl, 311int cache_process(int size, const char *path, const char *key, int ttl,
313 cache_fill_fn fn, void *cbdata) 312 cache_fill_fn fn)
314{ 313{
315 unsigned long hash; 314 unsigned long hash;
316 int i; 315 int i;
@@ -321,14 +320,14 @@ int cache_process(int size, const char *path, const char *key, int ttl,
321 320
322 /* If the cache is disabled, just generate the content */ 321 /* If the cache is disabled, just generate the content */
323 if (size <= 0) { 322 if (size <= 0) {
324 fn(cbdata); 323 fn();
325 return 0; 324 return 0;
326 } 325 }
327 326
328 /* Verify input, calculate filenames */ 327 /* Verify input, calculate filenames */
329 if (!path) { 328 if (!path) {
330 cache_log("[cgit] Cache path not specified, caching is disabled\n"); 329 cache_log("[cgit] Cache path not specified, caching is disabled\n");
331 fn(cbdata); 330 fn();
332 return 0; 331 return 0;
333 } 332 }
334 if (!key) 333 if (!key)
@@ -343,7 +342,6 @@ int cache_process(int size, const char *path, const char *key, int ttl,
343 strbuf_addbuf(&lockname, &filename); 342 strbuf_addbuf(&lockname, &filename);
344 strbuf_addstr(&lockname, ".lock"); 343 strbuf_addstr(&lockname, ".lock");
345 slot.fn = fn; 344 slot.fn = fn;
346 slot.cbdata = cbdata;
347 slot.ttl = ttl; 345 slot.ttl = ttl;
348 slot.cache_name = filename.buf; 346 slot.cache_name = filename.buf;
349 slot.lock_name = lockname.buf; 347 slot.lock_name = lockname.buf;
diff --git a/cache.h b/cache.h
index 5cfdb4f..9392836 100644
--- a/cache.h
+++ b/cache.h
@@ -6,7 +6,7 @@
6#ifndef CGIT_CACHE_H 6#ifndef CGIT_CACHE_H
7#define CGIT_CACHE_H 7#define CGIT_CACHE_H
8 8
9typedef void (*cache_fill_fn)(void *cbdata); 9typedef void (*cache_fill_fn)(void);
10 10
11 11
12/* Print cached content to stdout, generate the content if necessary. 12/* Print cached content to stdout, generate the content if necessary.
@@ -17,13 +17,12 @@ typedef void (*cache_fill_fn)(void *cbdata);
17 * key the key used to lookup cache files 17 * key the key used to lookup cache files
18 * ttl max cache time in seconds for this key 18 * ttl max cache time in seconds for this key
19 * fn content generator function for this key 19 * fn content generator function for this key
20 * cbdata user-supplied data to the content generator function
21 * 20 *
22 * Return value 21 * Return value
23 * 0 indicates success, everyting else is an error 22 * 0 indicates success, everyting else is an error
24 */ 23 */
25extern int cache_process(int size, const char *path, const char *key, int ttl, 24extern int cache_process(int size, const char *path, const char *key, int ttl,
26 cache_fill_fn fn, void *cbdata); 25 cache_fill_fn fn);
27 26
28 27
29/* List info about all cache entries on stdout */ 28/* List info about all cache entries on stdout */
diff --git a/cgit.c b/cgit.c
index 994957f..ec8f69c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -322,82 +322,82 @@ static void querystring_cb(const char *name, const char *value)
322 } 322 }
323} 323}
324 324
325static void prepare_context(struct cgit_context *ctx) 325static void prepare_context(void)
326{ 326{
327 memset(ctx, 0, sizeof(*ctx)); 327 memset(&ctx, 0, sizeof(ctx));
328 ctx->cfg.agefile = "info/web/last-modified"; 328 ctx.cfg.agefile = "info/web/last-modified";
329 ctx->cfg.nocache = 0; 329 ctx.cfg.nocache = 0;
330 ctx->cfg.cache_size = 0; 330 ctx.cfg.cache_size = 0;
331 ctx->cfg.cache_max_create_time = 5; 331 ctx.cfg.cache_max_create_time = 5;
332 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 332 ctx.cfg.cache_root = CGIT_CACHE_ROOT;
333 ctx->cfg.cache_about_ttl = 15; 333 ctx.cfg.cache_about_ttl = 15;
334 ctx->cfg.cache_repo_ttl = 5; 334 ctx.cfg.cache_repo_ttl = 5;
335 ctx->cfg.cache_root_ttl = 5; 335 ctx.cfg.cache_root_ttl = 5;
336 ctx->cfg.cache_scanrc_ttl = 15; 336 ctx.cfg.cache_scanrc_ttl = 15;
337 ctx->cfg.cache_dynamic_ttl = 5; 337 ctx.cfg.cache_dynamic_ttl = 5;
338 ctx->cfg.cache_static_ttl = -1; 338 ctx.cfg.cache_static_ttl = -1;
339 ctx->cfg.case_sensitive_sort = 1; 339 ctx.cfg.case_sensitive_sort = 1;
340 ctx->cfg.branch_sort = 0; 340 ctx.cfg.branch_sort = 0;
341 ctx->cfg.commit_sort = 0; 341 ctx.cfg.commit_sort = 0;
342 ctx->cfg.css = "/cgit.css"; 342 ctx.cfg.css = "/cgit.css";
343 ctx->cfg.logo = "/cgit.png"; 343 ctx.cfg.logo = "/cgit.png";
344 ctx->cfg.favicon = "/favicon.ico"; 344 ctx.cfg.favicon = "/favicon.ico";
345 ctx->cfg.local_time = 0; 345 ctx.cfg.local_time = 0;
346 ctx->cfg.enable_http_clone = 1; 346 ctx.cfg.enable_http_clone = 1;
347 ctx->cfg.enable_index_owner = 1; 347 ctx.cfg.enable_index_owner = 1;
348 ctx->cfg.enable_tree_linenumbers = 1; 348 ctx.cfg.enable_tree_linenumbers = 1;
349 ctx->cfg.enable_git_config = 0; 349 ctx.cfg.enable_git_config = 0;
350 ctx->cfg.max_repo_count = 50; 350 ctx.cfg.max_repo_count = 50;
351 ctx->cfg.max_commit_count = 50; 351 ctx.cfg.max_commit_count = 50;
352 ctx->cfg.max_lock_attempts = 5; 352 ctx.cfg.max_lock_attempts = 5;
353 ctx->cfg.max_msg_len = 80; 353 ctx.cfg.max_msg_len = 80;
354 ctx->cfg.max_repodesc_len = 80; 354 ctx.cfg.max_repodesc_len = 80;
355 ctx->cfg.max_blob_size = 0; 355 ctx.cfg.max_blob_size = 0;
356 ctx->cfg.max_stats = 0; 356 ctx.cfg.max_stats = 0;
357 ctx->cfg.project_list = NULL; 357 ctx.cfg.project_list = NULL;
358 ctx->cfg.renamelimit = -1; 358 ctx.cfg.renamelimit = -1;
359 ctx->cfg.remove_suffix = 0; 359 ctx.cfg.remove_suffix = 0;
360 ctx->cfg.robots = "index, nofollow"; 360 ctx.cfg.robots = "index, nofollow";
361 ctx->cfg.root_title = "Git repository browser"; 361 ctx.cfg.root_title = "Git repository browser";
362 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 362 ctx.cfg.root_desc = "a fast webinterface for the git dscm";
363 ctx->cfg.scan_hidden_path = 0; 363 ctx.cfg.scan_hidden_path = 0;
364 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 364 ctx.cfg.script_name = CGIT_SCRIPT_NAME;
365 ctx->cfg.section = ""; 365 ctx.cfg.section = "";
366 ctx->cfg.repository_sort = "name"; 366 ctx.cfg.repository_sort = "name";
367 ctx->cfg.section_sort = 1; 367 ctx.cfg.section_sort = 1;
368 ctx->cfg.summary_branches = 10; 368 ctx.cfg.summary_branches = 10;
369 ctx->cfg.summary_log = 10; 369 ctx.cfg.summary_log = 10;
370 ctx->cfg.summary_tags = 10; 370 ctx.cfg.summary_tags = 10;
371 ctx->cfg.max_atom_items = 10; 371 ctx.cfg.max_atom_items = 10;
372 ctx->cfg.ssdiff = 0; 372 ctx.cfg.ssdiff = 0;
373 ctx->env.cgit_config = getenv("CGIT_CONFIG"); 373 ctx.env.cgit_config = getenv("CGIT_CONFIG");
374 ctx->env.http_host = getenv("HTTP_HOST"); 374 ctx.env.http_host = getenv("HTTP_HOST");
375 ctx->env.https = getenv("HTTPS"); 375 ctx.env.https = getenv("HTTPS");
376 ctx->env.no_http = getenv("NO_HTTP"); 376 ctx.env.no_http = getenv("NO_HTTP");
377 ctx->env.path_info = getenv("PATH_INFO"); 377 ctx.env.path_info = getenv("PATH_INFO");
378 ctx->env.query_string = getenv("QUERY_STRING"); 378 ctx.env.query_string = getenv("QUERY_STRING");
379 ctx->env.request_method = getenv("REQUEST_METHOD"); 379 ctx.env.request_method = getenv("REQUEST_METHOD");
380 ctx->env.script_name = getenv("SCRIPT_NAME"); 380 ctx.env.script_name = getenv("SCRIPT_NAME");
381 ctx->env.server_name = getenv("SERVER_NAME"); 381 ctx.env.server_name = getenv("SERVER_NAME");
382 ctx->env.server_port = getenv("SERVER_PORT"); 382 ctx.env.server_port = getenv("SERVER_PORT");
383 ctx->env.http_cookie = getenv("HTTP_COOKIE"); 383 ctx.env.http_cookie = getenv("HTTP_COOKIE");
384 ctx->env.http_referer = getenv("HTTP_REFERER"); 384 ctx.env.http_referer = getenv("HTTP_REFERER");
385 ctx->env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; 385 ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0;
386 ctx->env.authenticated = 0; 386 ctx.env.authenticated = 0;
387 ctx->page.mimetype = "text/html"; 387 ctx.page.mimetype = "text/html";
388 ctx->page.charset = PAGE_ENCODING; 388 ctx.page.charset = PAGE_ENCODING;
389 ctx->page.filename = NULL; 389 ctx.page.filename = NULL;
390 ctx->page.size = 0; 390 ctx.page.size = 0;
391 ctx->page.modified = time(NULL); 391 ctx.page.modified = time(NULL);
392 ctx->page.expires = ctx->page.modified; 392 ctx.page.expires = ctx.page.modified;
393 ctx->page.etag = NULL; 393 ctx.page.etag = NULL;
394 memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); 394 memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list));
395 if (ctx->env.script_name) 395 if (ctx.env.script_name)
396 ctx->cfg.script_name = xstrdup(ctx->env.script_name); 396 ctx.cfg.script_name = xstrdup(ctx.env.script_name);
397 if (ctx->env.query_string) 397 if (ctx.env.query_string)
398 ctx->qry.raw = xstrdup(ctx->env.query_string); 398 ctx.qry.raw = xstrdup(ctx.env.query_string);
399 if (!ctx->env.cgit_config) 399 if (!ctx.env.cgit_config)
400 ctx->env.cgit_config = CGIT_CONFIG; 400 ctx.env.cgit_config = CGIT_CONFIG;
401} 401}
402 402
403struct refmatch { 403struct refmatch {
@@ -527,14 +527,14 @@ static void choose_readme(struct cgit_repo *repo)
527 string_list_append(&repo->readme, filename)->util = ref; 527 string_list_append(&repo->readme, filename)->util = ref;
528} 528}
529 529
530static int prepare_repo_cmd(struct cgit_context *ctx) 530static int prepare_repo_cmd(void)
531{ 531{
532 unsigned char sha1[20]; 532 unsigned char sha1[20];
533 int nongit = 0; 533 int nongit = 0;
534 int rc; 534 int rc;
535 535
536 /* The path to the git repository. */ 536 /* The path to the git repository. */
537 setenv("GIT_DIR", ctx->repo->path, 1); 537 setenv("GIT_DIR", ctx.repo->path, 1);
538 538
539 /* Do not look in /etc/ for gitconfig and gitattributes. */ 539 /* Do not look in /etc/ for gitconfig and gitattributes. */
540 setenv("GIT_CONFIG_NOSYSTEM", "1", 1); 540 setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
@@ -549,69 +549,69 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
549 init_display_notes(NULL); 549 init_display_notes(NULL);
550 550
551 if (nongit) { 551 if (nongit) {
552 const char *name = ctx->repo->name; 552 const char *name = ctx.repo->name;
553 rc = errno; 553 rc = errno;
554 ctx->page.title = fmtalloc("%s - %s", ctx->cfg.root_title, 554 ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title,
555 "config error"); 555 "config error");
556 ctx->repo = NULL; 556 ctx.repo = NULL;
557 cgit_print_http_headers(ctx); 557 cgit_print_http_headers();
558 cgit_print_docstart(ctx); 558 cgit_print_docstart();
559 cgit_print_pageheader(ctx); 559 cgit_print_pageheader();
560 cgit_print_error("Failed to open %s: %s", name, 560 cgit_print_error("Failed to open %s: %s", name,
561 rc ? strerror(rc) : "Not a valid git repository"); 561 rc ? strerror(rc) : "Not a valid git repository");
562 cgit_print_docend(); 562 cgit_print_docend();
563 return 1; 563 return 1;
564 } 564 }
565 ctx->page.title = fmtalloc("%s - %s", ctx->repo->name, ctx->repo->desc); 565 ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
566 566
567 if (!ctx->repo->defbranch) 567 if (!ctx.repo->defbranch)
568 ctx->repo->defbranch = guess_defbranch(); 568 ctx.repo->defbranch = guess_defbranch();
569 569
570 if (!ctx->qry.head) { 570 if (!ctx.qry.head) {
571 ctx->qry.nohead = 1; 571 ctx.qry.nohead = 1;
572 ctx->qry.head = find_default_branch(ctx->repo); 572 ctx.qry.head = find_default_branch(ctx.repo);
573 } 573 }
574 574
575 if (!ctx->qry.head) { 575 if (!ctx.qry.head) {
576 cgit_print_http_headers(ctx); 576 cgit_print_http_headers();
577 cgit_print_docstart(ctx); 577 cgit_print_docstart();
578 cgit_print_pageheader(ctx); 578 cgit_print_pageheader();
579 cgit_print_error("Repository seems to be empty"); 579 cgit_print_error("Repository seems to be empty");
580 cgit_print_docend(); 580 cgit_print_docend();
581 return 1; 581 return 1;
582 } 582 }
583 583
584 if (get_sha1(ctx->qry.head, sha1)) { 584 if (get_sha1(ctx.qry.head, sha1)) {
585 char *tmp = xstrdup(ctx->qry.head); 585 char *tmp = xstrdup(ctx.qry.head);
586 ctx->qry.head = ctx->repo->defbranch; 586 ctx.qry.head = ctx.repo->defbranch;
587 ctx->page.status = 404; 587 ctx.page.status = 404;
588 ctx->page.statusmsg = "Not found"; 588 ctx.page.statusmsg = "Not found";
589 cgit_print_http_headers(ctx); 589 cgit_print_http_headers();
590 cgit_print_docstart(ctx); 590 cgit_print_docstart();
591 cgit_print_pageheader(ctx); 591 cgit_print_pageheader();
592 cgit_print_error("Invalid branch: %s", tmp); 592 cgit_print_error("Invalid branch: %s", tmp);
593 cgit_print_docend(); 593 cgit_print_docend();
594 return 1; 594 return 1;
595 } 595 }
596 sort_string_list(&ctx->repo->submodules); 596 sort_string_list(&ctx.repo->submodules);
597 cgit_prepare_repo_env(ctx->repo); 597 cgit_prepare_repo_env(ctx.repo);
598 choose_readme(ctx->repo); 598 choose_readme(ctx.repo);
599 return 0; 599 return 0;
600} 600}
601 601
602static inline void open_auth_filter(struct cgit_context *ctx, const char *function) 602static inline void open_auth_filter(const char *function)
603{ 603{
604 cgit_open_filter(ctx->cfg.auth_filter, function, 604 cgit_open_filter(ctx.cfg.auth_filter, function,
605 ctx->env.http_cookie ? ctx->env.http_cookie : "", 605 ctx.env.http_cookie ? ctx.env.http_cookie : "",
606 ctx->env.request_method ? ctx->env.request_method : "", 606 ctx.env.request_method ? ctx.env.request_method : "",
607 ctx->env.query_string ? ctx->env.query_string : "", 607 ctx.env.query_string ? ctx.env.query_string : "",
608 ctx->env.http_referer ? ctx->env.http_referer : "", 608 ctx.env.http_referer ? ctx.env.http_referer : "",
609 ctx->env.path_info ? ctx->env.path_info : "", 609 ctx.env.path_info ? ctx.env.path_info : "",
610 ctx->env.http_host ? ctx->env.http_host : "", 610 ctx.env.http_host ? ctx.env.http_host : "",
611 ctx->env.https ? ctx->env.https : "", 611 ctx.env.https ? ctx.env.https : "",
612 ctx->qry.repo ? ctx->qry.repo : "", 612 ctx.qry.repo ? ctx.qry.repo : "",
613 ctx->qry.page ? ctx->qry.page : "", 613 ctx.qry.page ? ctx.qry.page : "",
614 ctx->qry.url ? ctx->qry.url : "", 614 ctx.qry.url ? ctx.qry.url : "",
615 cgit_loginurl()); 615 cgit_loginurl());
616} 616}
617 617
@@ -622,107 +622,106 @@ static inline void open_auth_filter(struct cgit_context *ctx, const char *functi
622 * will complain on the mailing list, and we'll increase it as needed. */ 622 * will complain on the mailing list, and we'll increase it as needed. */
623#define MAX_AUTHENTICATION_POST_BYTES 4096 623#define MAX_AUTHENTICATION_POST_BYTES 4096
624/* The filter is expected to spit out "Status: " and all headers. */ 624/* The filter is expected to spit out "Status: " and all headers. */
625static inline void authenticate_post(struct cgit_context *ctx) 625static inline void authenticate_post(void)
626{ 626{
627 char buffer[MAX_AUTHENTICATION_POST_BYTES]; 627 char buffer[MAX_AUTHENTICATION_POST_BYTES];
628 int len; 628 int len;
629 629
630 open_auth_filter(ctx, "authenticate-post"); 630 open_auth_filter("authenticate-post");
631 len = ctx->env.content_length; 631 len = ctx.env.content_length;
632 if (len > MAX_AUTHENTICATION_POST_BYTES) 632 if (len > MAX_AUTHENTICATION_POST_BYTES)
633 len = MAX_AUTHENTICATION_POST_BYTES; 633 len = MAX_AUTHENTICATION_POST_BYTES;
634 if (read(STDIN_FILENO, buffer, len) < 0) 634 if (read(STDIN_FILENO, buffer, len) < 0)
635 die_errno("Could not read POST from stdin"); 635 die_errno("Could not read POST from stdin");
636 if (write(STDOUT_FILENO, buffer, len) < 0) 636 if (write(STDOUT_FILENO, buffer, len) < 0)
637 die_errno("Could not write POST to stdout"); 637 die_errno("Could not write POST to stdout");
638 cgit_close_filter(ctx->cfg.auth_filter); 638 cgit_close_filter(ctx.cfg.auth_filter);
639 exit(0); 639 exit(0);
640} 640}
641 641
642static inline void authenticate_cookie(struct cgit_context *ctx) 642static inline void authenticate_cookie(void)
643{ 643{
644 /* If we don't have an auth_filter, consider all cookies valid, and thus return early. */ 644 /* If we don't have an auth_filter, consider all cookies valid, and thus return early. */
645 if (!ctx->cfg.auth_filter) { 645 if (!ctx.cfg.auth_filter) {
646 ctx->env.authenticated = 1; 646 ctx.env.authenticated = 1;
647 return; 647 return;
648 } 648 }
649 649
650 /* If we're having something POST'd to /login, we're authenticating POST, 650 /* If we're having something POST'd to /login, we're authenticating POST,
651 * instead of the cookie, so call authenticate_post and bail out early. 651 * instead of the cookie, so call authenticate_post and bail out early.
652 * This pattern here should match /?p=login with POST. */ 652 * This pattern here should match /?p=login with POST. */
653 if (ctx->env.request_method && ctx->qry.page && !ctx->repo && \ 653 if (ctx.env.request_method && ctx.qry.page && !ctx.repo && \
654 !strcmp(ctx->env.request_method, "POST") && !strcmp(ctx->qry.page, "login")) { 654 !strcmp(ctx.env.request_method, "POST") && !strcmp(ctx.qry.page, "login")) {
655 authenticate_post(ctx); 655 authenticate_post();
656 return; 656 return;
657 } 657 }
658 658
659 /* If we've made it this far, we're authenticating the cookie for real, so do that. */ 659 /* If we've made it this far, we're authenticating the cookie for real, so do that. */
660 open_auth_filter(ctx, "authenticate-cookie"); 660 open_auth_filter("authenticate-cookie");
661 ctx->env.authenticated = cgit_close_filter(ctx->cfg.auth_filter); 661 ctx.env.authenticated = cgit_close_filter(ctx.cfg.auth_filter);
662} 662}
663 663
664static void process_request(void *cbdata) 664static void process_request(void)
665{ 665{
666 struct cgit_context *ctx = cbdata;
667 struct cgit_cmd *cmd; 666 struct cgit_cmd *cmd;
668 667
669 /* If we're not yet authenticated, no matter what page we're on, 668 /* If we're not yet authenticated, no matter what page we're on,
670 * display the authentication body from the auth_filter. This should 669 * display the authentication body from the auth_filter. This should
671 * never be cached. */ 670 * never be cached. */
672 if (!ctx->env.authenticated) { 671 if (!ctx.env.authenticated) {
673 ctx->page.title = "Authentication Required"; 672 ctx.page.title = "Authentication Required";
674 cgit_print_http_headers(ctx); 673 cgit_print_http_headers();
675 cgit_print_docstart(ctx); 674 cgit_print_docstart();
676 cgit_print_pageheader(ctx); 675 cgit_print_pageheader();
677 open_auth_filter(ctx, "body"); 676 open_auth_filter("body");
678 cgit_close_filter(ctx->cfg.auth_filter); 677 cgit_close_filter(ctx.cfg.auth_filter);
679 cgit_print_docend(); 678 cgit_print_docend();
680 return; 679 return;
681 } 680 }
682 681
683 cmd = cgit_get_cmd(ctx); 682 cmd = cgit_get_cmd();
684 if (!cmd) { 683 if (!cmd) {
685 ctx->page.title = "cgit error"; 684 ctx.page.title = "cgit error";
686 ctx->page.status = 404; 685 ctx.page.status = 404;
687 ctx->page.statusmsg = "Not found"; 686 ctx.page.statusmsg = "Not found";
688 cgit_print_http_headers(ctx); 687 cgit_print_http_headers();
689 cgit_print_docstart(ctx); 688 cgit_print_docstart();
690 cgit_print_pageheader(ctx); 689 cgit_print_pageheader();
691 cgit_print_error("Invalid request"); 690 cgit_print_error("Invalid request");
692 cgit_print_docend(); 691 cgit_print_docend();
693 return; 692 return;
694 } 693 }
695 694
696 if (!ctx->cfg.enable_http_clone && cmd->is_clone) { 695 if (!ctx.cfg.enable_http_clone && cmd->is_clone) {
697 html_status(404, "Not found", 0); 696 html_status(404, "Not found", 0);
698 return; 697 return;
699 } 698 }
700 699
701 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" 700 /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
702 * in-project path limit to be made available at ctx->qry.vpath. 701 * in-project path limit to be made available at ctx.qry.vpath.
703 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). 702 * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
704 */ 703 */
705 ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; 704 ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
706 705
707 if (cmd->want_repo && !ctx->repo) { 706 if (cmd->want_repo && !ctx.repo) {
708 cgit_print_http_headers(ctx); 707 cgit_print_http_headers();
709 cgit_print_docstart(ctx); 708 cgit_print_docstart();
710 cgit_print_pageheader(ctx); 709 cgit_print_pageheader();
711 cgit_print_error("No repository selected"); 710 cgit_print_error("No repository selected");
712 cgit_print_docend(); 711 cgit_print_docend();
713 return; 712 return;
714 } 713 }
715 714
716 if (ctx->repo && prepare_repo_cmd(ctx)) 715 if (ctx.repo && prepare_repo_cmd())
717 return; 716 return;
718 717
719 if (cmd->want_layout) { 718 if (cmd->want_layout) {
720 cgit_print_http_headers(ctx); 719 cgit_print_http_headers();
721 cgit_print_docstart(ctx); 720 cgit_print_docstart();
722 cgit_print_pageheader(ctx); 721 cgit_print_pageheader();
723 } 722 }
724 723
725 cmd->fn(ctx); 724 cmd->fn();
726 725
727 if (cmd->want_layout) 726 if (cmd->want_layout)
728 cgit_print_docend(); 727 cgit_print_docend();
@@ -995,7 +994,7 @@ int main(int argc, const char **argv)
995 cgit_init_filters(); 994 cgit_init_filters();
996 atexit(cgit_cleanup_filters); 995 atexit(cgit_cleanup_filters);
997 996
998 prepare_context(&ctx); 997 prepare_context();
999 cgit_repolist.length = 0; 998 cgit_repolist.length = 0;
1000 cgit_repolist.count = 0; 999 cgit_repolist.count = 0;
1001 cgit_repolist.repos = NULL; 1000 cgit_repolist.repos = NULL;
@@ -1034,7 +1033,7 @@ int main(int argc, const char **argv)
1034 /* Before we go any further, we set ctx.env.authenticated by checking to see 1033 /* Before we go any further, we set ctx.env.authenticated by checking to see
1035 * if the supplied cookie is valid. All cookies are valid if there is no 1034 * if the supplied cookie is valid. All cookies are valid if there is no
1036 * auth_filter. If there is an auth_filter, the filter decides. */ 1035 * auth_filter. If there is an auth_filter, the filter decides. */
1037 authenticate_cookie(&ctx); 1036 authenticate_cookie();
1038 1037
1039 ttl = calc_ttl(); 1038 ttl = calc_ttl();
1040 if (ttl < 0) 1039 if (ttl < 0)
@@ -1046,7 +1045,8 @@ int main(int argc, const char **argv)
1046 if (ctx.cfg.nocache) 1045 if (ctx.cfg.nocache)
1047 ctx.cfg.cache_size = 0; 1046 ctx.cfg.cache_size = 0;
1048 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 1047 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
1049 ctx.qry.raw, ttl, process_request, &ctx); 1048 ctx.qry.raw, ttl, process_request);
1049 cgit_cleanup_filters();
1050 if (err) 1050 if (err)
1051 cgit_print_error("Error processing page: %s (%d)", 1051 cgit_print_error("Error processing page: %s (%d)",
1052 strerror(err), err); 1052 strerror(err), err);
diff --git a/cmd.c b/cmd.c
index 420b3b1..cbd235c 100644
--- a/cmd.c
+++ b/cmd.c
@@ -26,120 +26,120 @@
26#include "ui-tag.h" 26#include "ui-tag.h"
27#include "ui-tree.h" 27#include "ui-tree.h"
28 28
29static void HEAD_fn(struct cgit_context *ctx) 29static void HEAD_fn(void)
30{ 30{
31 cgit_clone_head(ctx); 31 cgit_clone_head();
32} 32}
33 33
34static void atom_fn(struct cgit_context *ctx) 34static void atom_fn(void)
35{ 35{
36 cgit_print_atom(ctx->qry.head, ctx->qry.path, ctx->cfg.max_atom_items); 36 cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items);
37} 37}
38 38
39static void about_fn(struct cgit_context *ctx) 39static void about_fn(void)
40{ 40{
41 if (ctx->repo) 41 if (ctx.repo)
42 cgit_print_repo_readme(ctx->qry.path); 42 cgit_print_repo_readme(ctx.qry.path);
43 else 43 else
44 cgit_print_site_readme(); 44 cgit_print_site_readme();
45} 45}
46 46
47static void blob_fn(struct cgit_context *ctx) 47static void blob_fn(void)
48{ 48{
49 cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head, 0); 49 cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0);
50} 50}
51 51
52static void commit_fn(struct cgit_context *ctx) 52static void commit_fn(void)
53{ 53{
54 cgit_print_commit(ctx->qry.sha1, ctx->qry.path); 54 cgit_print_commit(ctx.qry.sha1, ctx.qry.path);
55} 55}
56 56
57static void diff_fn(struct cgit_context *ctx) 57static void diff_fn(void)
58{ 58{
59 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1, 0); 59 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 0);
60} 60}
61 61
62static void rawdiff_fn(struct cgit_context *ctx) 62static void rawdiff_fn(void)
63{ 63{
64 cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1, 1); 64 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 1);
65} 65}
66 66
67static void info_fn(struct cgit_context *ctx) 67static void info_fn(void)
68{ 68{
69 cgit_clone_info(ctx); 69 cgit_clone_info();
70} 70}
71 71
72static void log_fn(struct cgit_context *ctx) 72static void log_fn(void)
73{ 73{
74 cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, 74 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, ctx.cfg.max_commit_count,
75 ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1, 75 ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1,
76 ctx->repo->enable_commit_graph, 76 ctx.repo->enable_commit_graph,
77 ctx->repo->commit_sort); 77 ctx.repo->commit_sort);
78} 78}
79 79
80static void ls_cache_fn(struct cgit_context *ctx) 80static void ls_cache_fn(void)
81{ 81{
82 ctx->page.mimetype = "text/plain"; 82 ctx.page.mimetype = "text/plain";
83 ctx->page.filename = "ls-cache.txt"; 83 ctx.page.filename = "ls-cache.txt";
84 cgit_print_http_headers(ctx); 84 cgit_print_http_headers();
85 cache_ls(ctx->cfg.cache_root); 85 cache_ls(ctx.cfg.cache_root);
86} 86}
87 87
88static void objects_fn(struct cgit_context *ctx) 88static void objects_fn(void)
89{ 89{
90 cgit_clone_objects(ctx); 90 cgit_clone_objects();
91} 91}
92 92
93static void repolist_fn(struct cgit_context *ctx) 93static void repolist_fn(void)
94{ 94{
95 cgit_print_repolist(); 95 cgit_print_repolist();
96} 96}
97 97
98static void patch_fn(struct cgit_context *ctx) 98static void patch_fn(void)
99{ 99{
100 cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); 100 cgit_print_patch(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path);
101} 101}
102 102
103static void plain_fn(struct cgit_context *ctx) 103static void plain_fn(void)
104{ 104{
105 cgit_print_plain(ctx); 105 cgit_print_plain();
106} 106}
107 107
108static void refs_fn(struct cgit_context *ctx) 108static void refs_fn(void)
109{ 109{
110 cgit_print_refs(); 110 cgit_print_refs();
111} 111}
112 112
113static void snapshot_fn(struct cgit_context *ctx) 113static void snapshot_fn(void)
114{ 114{
115 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path, 115 cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path,
116 ctx->repo->snapshots, ctx->qry.nohead); 116 ctx.repo->snapshots, ctx.qry.nohead);
117} 117}
118 118
119static void stats_fn(struct cgit_context *ctx) 119static void stats_fn(void)
120{ 120{
121 cgit_show_stats(ctx); 121 cgit_show_stats();
122} 122}
123 123
124static void summary_fn(struct cgit_context *ctx) 124static void summary_fn(void)
125{ 125{
126 cgit_print_summary(); 126 cgit_print_summary();
127} 127}
128 128
129static void tag_fn(struct cgit_context *ctx) 129static void tag_fn(void)
130{ 130{
131 cgit_print_tag(ctx->qry.sha1); 131 cgit_print_tag(ctx.qry.sha1);
132} 132}
133 133
134static void tree_fn(struct cgit_context *ctx) 134static void tree_fn(void)
135{ 135{
136 cgit_print_tree(ctx->qry.sha1, ctx->qry.path); 136 cgit_print_tree(ctx.qry.sha1, ctx.qry.path);
137} 137}
138 138
139#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ 139#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \
140 {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} 140 {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone}
141 141
142struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) 142struct cgit_cmd *cgit_get_cmd(void)
143{ 143{
144 static struct cgit_cmd cmds[] = { 144 static struct cgit_cmd cmds[] = {
145 def_cmd(HEAD, 1, 0, 0, 1), 145 def_cmd(HEAD, 1, 0, 0, 1),
@@ -165,15 +165,15 @@ struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
165 }; 165 };
166 int i; 166 int i;
167 167
168 if (ctx->qry.page == NULL) { 168 if (ctx.qry.page == NULL) {
169 if (ctx->repo) 169 if (ctx.repo)
170 ctx->qry.page = "summary"; 170 ctx.qry.page = "summary";
171 else 171 else
172 ctx->qry.page = "repolist"; 172 ctx.qry.page = "repolist";
173 } 173 }
174 174
175 for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) 175 for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
176 if (!strcmp(ctx->qry.page, cmds[i].name)) 176 if (!strcmp(ctx.qry.page, cmds[i].name))
177 return &cmds[i]; 177 return &cmds[i];
178 return NULL; 178 return NULL;
179} 179}
diff --git a/cmd.h b/cmd.h
index eb5bc87..752f078 100644
--- a/cmd.h
+++ b/cmd.h
@@ -1,7 +1,7 @@
1#ifndef CMD_H 1#ifndef CMD_H
2#define CMD_H 2#define CMD_H
3 3
4typedef void (*cgit_cmd_fn)(struct cgit_context *ctx); 4typedef void (*cgit_cmd_fn)(void);
5 5
6struct cgit_cmd { 6struct cgit_cmd {
7 const char *name; 7 const char *name;
@@ -12,6 +12,6 @@ struct cgit_cmd {
12 is_clone:1; 12 is_clone:1;
13}; 13};
14 14
15extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); 15extern struct cgit_cmd *cgit_get_cmd(void);
16 16
17#endif /* CMD_H */ 17#endif /* CMD_H */
diff --git a/ui-atom.c b/ui-atom.c
index 838f220..b22d745 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -108,7 +108,7 @@ void cgit_print_atom(char *tip, char *path, int max_count)
108 host = cgit_hosturl(); 108 host = cgit_hosturl();
109 ctx.page.mimetype = "text/xml"; 109 ctx.page.mimetype = "text/xml";
110 ctx.page.charset = "utf-8"; 110 ctx.page.charset = "utf-8";
111 cgit_print_http_headers(&ctx); 111 cgit_print_http_headers();
112 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); 112 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
113 html("<title>"); 113 html("<title>");
114 html_txt(ctx.repo->name); 114 html_txt(ctx.repo->name);
diff --git a/ui-blob.c b/ui-blob.c
index 608926e..9c99519 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -164,6 +164,6 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl
164 ctx.page.mimetype = "text/plain"; 164 ctx.page.mimetype = "text/plain";
165 } 165 }
166 ctx.page.filename = path; 166 ctx.page.filename = path;
167 cgit_print_http_headers(&ctx); 167 cgit_print_http_headers();
168 html_raw(buf, size); 168 html_raw(buf, size);
169} 169}
diff --git a/ui-clone.c b/ui-clone.c
index 9d0d6ad..d25553b 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -29,22 +29,22 @@ static int print_ref_info(const char *refname, const unsigned char *sha1,
29 return 0; 29 return 0;
30} 30}
31 31
32static void print_pack_info(struct cgit_context *ctx) 32static void print_pack_info(void)
33{ 33{
34 struct packed_git *pack; 34 struct packed_git *pack;
35 int ofs; 35 int ofs;
36 36
37 ctx->page.mimetype = "text/plain"; 37 ctx.page.mimetype = "text/plain";
38 ctx->page.filename = "objects/info/packs"; 38 ctx.page.filename = "objects/info/packs";
39 cgit_print_http_headers(ctx); 39 cgit_print_http_headers();
40 ofs = strlen(ctx->repo->path) + strlen("/objects/pack/"); 40 ofs = strlen(ctx.repo->path) + strlen("/objects/pack/");
41 prepare_packed_git(); 41 prepare_packed_git();
42 for (pack = packed_git; pack; pack = pack->next) 42 for (pack = packed_git; pack; pack = pack->next)
43 if (pack->pack_local) 43 if (pack->pack_local)
44 htmlf("P %s\n", pack->pack_name + ofs); 44 htmlf("P %s\n", pack->pack_name + ofs);
45} 45}
46 46
47static void send_file(struct cgit_context *ctx, char *path) 47static void send_file(char *path)
48{ 48{
49 struct stat st; 49 struct stat st;
50 50
@@ -61,41 +61,41 @@ static void send_file(struct cgit_context *ctx, char *path)
61 } 61 }
62 return; 62 return;
63 } 63 }
64 ctx->page.mimetype = "application/octet-stream"; 64 ctx.page.mimetype = "application/octet-stream";
65 ctx->page.filename = path; 65 ctx.page.filename = path;
66 if (prefixcmp(ctx->repo->path, path)) 66 if (prefixcmp(ctx.repo->path, path))
67 ctx->page.filename += strlen(ctx->repo->path) + 1; 67 ctx.page.filename += strlen(ctx.repo->path) + 1;
68 cgit_print_http_headers(ctx); 68 cgit_print_http_headers();
69 html_include(path); 69 html_include(path);
70} 70}
71 71
72void cgit_clone_info(struct cgit_context *ctx) 72void cgit_clone_info(void)
73{ 73{
74 if (!ctx->qry.path || strcmp(ctx->qry.path, "refs")) 74 if (!ctx.qry.path || strcmp(ctx.qry.path, "refs"))
75 return; 75 return;
76 76
77 ctx->page.mimetype = "text/plain"; 77 ctx.page.mimetype = "text/plain";
78 ctx->page.filename = "info/refs"; 78 ctx.page.filename = "info/refs";
79 cgit_print_http_headers(ctx); 79 cgit_print_http_headers();
80 for_each_ref(print_ref_info, ctx); 80 for_each_ref(print_ref_info, NULL);
81} 81}
82 82
83void cgit_clone_objects(struct cgit_context *ctx) 83void cgit_clone_objects(void)
84{ 84{
85 if (!ctx->qry.path) { 85 if (!ctx.qry.path) {
86 html_status(400, "Bad request", 0); 86 html_status(400, "Bad request", 0);
87 return; 87 return;
88 } 88 }
89 89
90 if (!strcmp(ctx->qry.path, "info/packs")) { 90 if (!strcmp(ctx.qry.path, "info/packs")) {
91 print_pack_info(ctx); 91 print_pack_info();
92 return; 92 return;
93 } 93 }
94 94
95 send_file(ctx, git_path("objects/%s", ctx->qry.path)); 95 send_file(git_path("objects/%s", ctx.qry.path));
96} 96}
97 97
98void cgit_clone_head(struct cgit_context *ctx) 98void cgit_clone_head(void)
99{ 99{
100 send_file(ctx, git_path("%s", "HEAD")); 100 send_file(git_path("%s", "HEAD"));
101} 101}
diff --git a/ui-clone.h b/ui-clone.h
index 89cd4f1..3e460a3 100644
--- a/ui-clone.h
+++ b/ui-clone.h
@@ -1,8 +1,8 @@
1#ifndef UI_CLONE_H 1#ifndef UI_CLONE_H
2#define UI_CLONE_H 2#define UI_CLONE_H
3 3
4void cgit_clone_info(struct cgit_context *ctx); 4void cgit_clone_info(void);
5void cgit_clone_objects(struct cgit_context *ctx); 5void cgit_clone_objects(void);
6void cgit_clone_head(struct cgit_context *ctx); 6void cgit_clone_head(void);
7 7
8#endif /* UI_CLONE_H */ 8#endif /* UI_CLONE_H */
diff --git a/ui-diff.c b/ui-diff.c
index 5ccd03e..71273aa 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -407,7 +407,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
407 diff_setup_done(&diffopt); 407 diff_setup_done(&diffopt);
408 408
409 ctx.page.mimetype = "text/plain"; 409 ctx.page.mimetype = "text/plain";
410 cgit_print_http_headers(&ctx); 410 cgit_print_http_headers();
411 if (old_tree_sha1) { 411 if (old_tree_sha1) {
412 diff_tree_sha1(old_tree_sha1, new_tree_sha1, "", 412 diff_tree_sha1(old_tree_sha1, new_tree_sha1, "",
413 &diffopt); 413 &diffopt);
diff --git a/ui-patch.c b/ui-patch.c
index 3086608..6878a46 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -59,7 +59,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
59 patchname = fmt("%s.patch", rev_range); 59 patchname = fmt("%s.patch", rev_range);
60 ctx.page.mimetype = "text/plain"; 60 ctx.page.mimetype = "text/plain";
61 ctx.page.filename = patchname; 61 ctx.page.filename = patchname;
62 cgit_print_http_headers(&ctx); 62 cgit_print_http_headers();
63 63
64 if (ctx.cfg.noplainemail) { 64 if (ctx.cfg.noplainemail) {
65 rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 " 65 rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 "
diff --git a/ui-plain.c b/ui-plain.c
index 68e0387..30fff89 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -103,7 +103,7 @@ static int print_object(const unsigned char *sha1, const char *path)
103 ctx.page.filename = path; 103 ctx.page.filename = path;
104 ctx.page.size = size; 104 ctx.page.size = size;
105 ctx.page.etag = sha1_to_hex(sha1); 105 ctx.page.etag = sha1_to_hex(sha1);
106 cgit_print_http_headers(&ctx); 106 cgit_print_http_headers();
107 html_raw(buf, size); 107 html_raw(buf, size);
108 /* If we allocated this, then casting away const is safe. */ 108 /* If we allocated this, then casting away const is safe. */
109 if (freemime) 109 if (freemime)
@@ -128,7 +128,7 @@ static void print_dir(const unsigned char *sha1, const char *base,
128 fullpath = buildpath(base, baselen, path); 128 fullpath = buildpath(base, baselen, path);
129 slash = (fullpath[0] == '/' ? "" : "/"); 129 slash = (fullpath[0] == '/' ? "" : "/");
130 ctx.page.etag = sha1_to_hex(sha1); 130 ctx.page.etag = sha1_to_hex(sha1);
131 cgit_print_http_headers(&ctx); 131 cgit_print_http_headers();
132 htmlf("<html><head><title>%s", slash); 132 htmlf("<html><head><title>%s", slash);
133 html_txt(fullpath); 133 html_txt(fullpath);
134 htmlf("</title></head>\n<body>\n<h2>%s", slash); 134 htmlf("</title></head>\n<body>\n<h2>%s", slash);
@@ -206,14 +206,14 @@ static int basedir_len(const char *path)
206 return 0; 206 return 0;
207} 207}
208 208
209void cgit_print_plain(struct cgit_context *ctx) 209void cgit_print_plain(void)
210{ 210{
211 const char *rev = ctx->qry.sha1; 211 const char *rev = ctx.qry.sha1;
212 unsigned char sha1[20]; 212 unsigned char sha1[20];
213 struct commit *commit; 213 struct commit *commit;
214 struct pathspec_item path_items = { 214 struct pathspec_item path_items = {
215 .match = ctx->qry.path, 215 .match = ctx.qry.path,
216 .len = ctx->qry.path ? strlen(ctx->qry.path) : 0 216 .len = ctx.qry.path ? strlen(ctx.qry.path) : 0
217 }; 217 };
218 struct pathspec paths = { 218 struct pathspec paths = {
219 .nr = 1, 219 .nr = 1,
@@ -224,7 +224,7 @@ void cgit_print_plain(struct cgit_context *ctx)
224 }; 224 };
225 225
226 if (!rev) 226 if (!rev)
227 rev = ctx->qry.head; 227 rev = ctx.qry.head;
228 228
229 if (get_sha1(rev, sha1)) { 229 if (get_sha1(rev, sha1)) {
230 html_status(404, "Not found", 0); 230 html_status(404, "Not found", 0);
diff --git a/ui-plain.h b/ui-plain.h
index 4373118..5bff07b 100644
--- a/ui-plain.h
+++ b/ui-plain.h
@@ -1,6 +1,6 @@
1#ifndef UI_PLAIN_H 1#ifndef UI_PLAIN_H
2#define UI_PLAIN_H 2#define UI_PLAIN_H
3 3
4extern void cgit_print_plain(struct cgit_context *ctx); 4extern void cgit_print_plain(void);
5 5
6#endif /* UI_PLAIN_H */ 6#endif /* UI_PLAIN_H */
diff --git a/ui-repolist.c b/ui-repolist.c
index f9cb21a..92e80cf 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -259,9 +259,9 @@ void cgit_print_repolist()
259 ++columns; 259 ++columns;
260 260
261 ctx.page.title = ctx.cfg.root_title; 261 ctx.page.title = ctx.cfg.root_title;
262 cgit_print_http_headers(&ctx); 262 cgit_print_http_headers();
263 cgit_print_docstart(&ctx); 263 cgit_print_docstart();
264 cgit_print_pageheader(&ctx); 264 cgit_print_pageheader();
265 265
266 if (ctx.cfg.index_header) 266 if (ctx.cfg.index_header)
267 html_include(ctx.cfg.index_header); 267 html_include(ctx.cfg.index_header);
diff --git a/ui-shared.c b/ui-shared.c
index 0838e18..070971f 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -436,59 +436,58 @@ void cgit_stats_link(const char *name, const char *title, const char *class,
436 reporevlink("stats", name, title, class, head, NULL, path); 436 reporevlink("stats", name, title, class, head, NULL, path);
437} 437}
438 438
439static void cgit_self_link(char *name, const char *title, const char *class, 439static void cgit_self_link(char *name, const char *title, const char *class)
440 struct cgit_context *ctx) 440{
441{ 441 if (!strcmp(ctx.qry.page, "repolist"))
442 if (!strcmp(ctx->qry.page, "repolist")) 442 cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort,
443 cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort, 443 ctx.qry.ofs);
444 ctx->qry.ofs); 444 else if (!strcmp(ctx.qry.page, "summary"))
445 else if (!strcmp(ctx->qry.page, "summary")) 445 cgit_summary_link(name, title, class, ctx.qry.head);
446 cgit_summary_link(name, title, class, ctx->qry.head); 446 else if (!strcmp(ctx.qry.page, "tag"))
447 else if (!strcmp(ctx->qry.page, "tag")) 447 cgit_tag_link(name, title, class, ctx.qry.head,
448 cgit_tag_link(name, title, class, ctx->qry.head, 448 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL);
449 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); 449 else if (!strcmp(ctx.qry.page, "tree"))
450 else if (!strcmp(ctx->qry.page, "tree")) 450 cgit_tree_link(name, title, class, ctx.qry.head,
451 cgit_tree_link(name, title, class, ctx->qry.head, 451 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
452 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 452 ctx.qry.path);
453 ctx->qry.path); 453 else if (!strcmp(ctx.qry.page, "plain"))
454 else if (!strcmp(ctx->qry.page, "plain")) 454 cgit_plain_link(name, title, class, ctx.qry.head,
455 cgit_plain_link(name, title, class, ctx->qry.head, 455 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
456 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 456 ctx.qry.path);
457 ctx->qry.path); 457 else if (!strcmp(ctx.qry.page, "log"))
458 else if (!strcmp(ctx->qry.page, "log")) 458 cgit_log_link(name, title, class, ctx.qry.head,
459 cgit_log_link(name, title, class, ctx->qry.head, 459 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
460 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 460 ctx.qry.path, ctx.qry.ofs,
461 ctx->qry.path, ctx->qry.ofs, 461 ctx.qry.grep, ctx.qry.search,
462 ctx->qry.grep, ctx->qry.search, 462 ctx.qry.showmsg);
463 ctx->qry.showmsg); 463 else if (!strcmp(ctx.qry.page, "commit"))
464 else if (!strcmp(ctx->qry.page, "commit")) 464 cgit_commit_link(name, title, class, ctx.qry.head,
465 cgit_commit_link(name, title, class, ctx->qry.head, 465 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
466 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 466 ctx.qry.path, 0);
467 ctx->qry.path, 0); 467 else if (!strcmp(ctx.qry.page, "patch"))
468 else if (!strcmp(ctx->qry.page, "patch")) 468 cgit_patch_link(name, title, class, ctx.qry.head,
469 cgit_patch_link(name, title, class, ctx->qry.head, 469 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
470 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 470 ctx.qry.path);
471 ctx->qry.path); 471 else if (!strcmp(ctx.qry.page, "refs"))
472 else if (!strcmp(ctx->qry.page, "refs")) 472 cgit_refs_link(name, title, class, ctx.qry.head,
473 cgit_refs_link(name, title, class, ctx->qry.head, 473 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
474 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 474 ctx.qry.path);
475 ctx->qry.path); 475 else if (!strcmp(ctx.qry.page, "snapshot"))
476 else if (!strcmp(ctx->qry.page, "snapshot")) 476 cgit_snapshot_link(name, title, class, ctx.qry.head,
477 cgit_snapshot_link(name, title, class, ctx->qry.head, 477 ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
478 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 478 ctx.qry.path);
479 ctx->qry.path); 479 else if (!strcmp(ctx.qry.page, "diff"))
480 else if (!strcmp(ctx->qry.page, "diff")) 480 cgit_diff_link(name, title, class, ctx.qry.head,
481 cgit_diff_link(name, title, class, ctx->qry.head, 481 ctx.qry.sha1, ctx.qry.sha2,
482 ctx->qry.sha1, ctx->qry.sha2, 482 ctx.qry.path, 0);
483 ctx->qry.path, 0); 483 else if (!strcmp(ctx.qry.page, "stats"))
484 else if (!strcmp(ctx->qry.page, "stats")) 484 cgit_stats_link(name, title, class, ctx.qry.head,
485 cgit_stats_link(name, title, class, ctx->qry.head, 485 ctx.qry.path);
486 ctx->qry.path);
487 else { 486 else {
488 /* Don't known how to make link for this page */ 487 /* Don't known how to make link for this page */
489 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); 488 repolink(title, class, ctx.qry.page, ctx.qry.head, ctx.qry.path);
490 html("><!-- cgit_self_link() doesn't know how to make link for page '"); 489 html("><!-- cgit_self_link() doesn't know how to make link for page '");
491 html_txt(ctx->qry.page); 490 html_txt(ctx.qry.page);
492 html("' -->"); 491 html("' -->");
493 html_txt(name); 492 html_txt(name);
494 html("</a>"); 493 html("</a>");
@@ -632,39 +631,39 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
632 secs * 1.0 / TM_YEAR); 631 secs * 1.0 / TM_YEAR);
633} 632}
634 633
635void cgit_print_http_headers(struct cgit_context *ctx) 634void cgit_print_http_headers(void)
636{ 635{
637 if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) 636 if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1"))
638 return; 637 return;
639 638
640 if (ctx->page.status) 639 if (ctx.page.status)
641 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 640 htmlf("Status: %d %s\n", ctx.page.status, ctx.page.statusmsg);
642 if (ctx->page.mimetype && ctx->page.charset) 641 if (ctx.page.mimetype && ctx.page.charset)
643 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 642 htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype,
644 ctx->page.charset); 643 ctx.page.charset);
645 else if (ctx->page.mimetype) 644 else if (ctx.page.mimetype)
646 htmlf("Content-Type: %s\n", ctx->page.mimetype); 645 htmlf("Content-Type: %s\n", ctx.page.mimetype);
647 if (ctx->page.size) 646 if (ctx.page.size)
648 htmlf("Content-Length: %zd\n", ctx->page.size); 647 htmlf("Content-Length: %zd\n", ctx.page.size);
649 if (ctx->page.filename) 648 if (ctx.page.filename)
650 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 649 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
651 ctx->page.filename); 650 ctx.page.filename);
652 if (!ctx->env.authenticated) 651 if (!ctx.env.authenticated)
653 html("Cache-Control: no-cache, no-store\n"); 652 html("Cache-Control: no-cache, no-store\n");
654 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 653 htmlf("Last-Modified: %s\n", http_date(ctx.page.modified));
655 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 654 htmlf("Expires: %s\n", http_date(ctx.page.expires));
656 if (ctx->page.etag) 655 if (ctx.page.etag)
657 htmlf("ETag: \"%s\"\n", ctx->page.etag); 656 htmlf("ETag: \"%s\"\n", ctx.page.etag);
658 html("\n"); 657 html("\n");
659 if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) 658 if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
660 exit(0); 659 exit(0);
661} 660}
662 661
663void cgit_print_docstart(struct cgit_context *ctx) 662void cgit_print_docstart(void)
664{ 663{
665 if (ctx->cfg.embedded) { 664 if (ctx.cfg.embedded) {
666 if (ctx->cfg.header) 665 if (ctx.cfg.header)
667 html_include(ctx->cfg.header); 666 html_include(ctx.cfg.header);
668 return; 667 return;
669 } 668 }
670 669
@@ -673,37 +672,37 @@ void cgit_print_docstart(struct cgit_context *ctx)
673 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 672 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
674 html("<head>\n"); 673 html("<head>\n");
675 html("<title>"); 674 html("<title>");
676 html_txt(ctx->page.title); 675 html_txt(ctx.page.title);
677 html("</title>\n"); 676 html("</title>\n");
678 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 677 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
679 if (ctx->cfg.robots && *ctx->cfg.robots) 678 if (ctx.cfg.robots && *ctx.cfg.robots)
680 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 679 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
681 html("<link rel='stylesheet' type='text/css' href='"); 680 html("<link rel='stylesheet' type='text/css' href='");
682 html_attr(ctx->cfg.css); 681 html_attr(ctx.cfg.css);
683 html("'/>\n"); 682 html("'/>\n");
684 if (ctx->cfg.favicon) { 683 if (ctx.cfg.favicon) {
685 html("<link rel='shortcut icon' href='"); 684 html("<link rel='shortcut icon' href='");
686 html_attr(ctx->cfg.favicon); 685 html_attr(ctx.cfg.favicon);
687 html("'/>\n"); 686 html("'/>\n");
688 } 687 }
689 if (host && ctx->repo && ctx->qry.head) { 688 if (host && ctx.repo && ctx.qry.head) {
690 struct strbuf sb = STRBUF_INIT; 689 struct strbuf sb = STRBUF_INIT;
691 strbuf_addf(&sb, "h=%s", ctx->qry.head); 690 strbuf_addf(&sb, "h=%s", ctx.qry.head);
692 691
693 html("<link rel='alternate' title='Atom feed' href='"); 692 html("<link rel='alternate' title='Atom feed' href='");
694 html(cgit_httpscheme()); 693 html(cgit_httpscheme());
695 html_attr(cgit_hosturl()); 694 html_attr(cgit_hosturl());
696 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, 695 html_attr(cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath,
697 sb.buf)); 696 sb.buf));
698 html("' type='application/atom+xml'/>\n"); 697 html("' type='application/atom+xml'/>\n");
699 strbuf_release(&sb); 698 strbuf_release(&sb);
700 } 699 }
701 if (ctx->cfg.head_include) 700 if (ctx.cfg.head_include)
702 html_include(ctx->cfg.head_include); 701 html_include(ctx.cfg.head_include);
703 html("</head>\n"); 702 html("</head>\n");
704 html("<body>\n"); 703 html("<body>\n");
705 if (ctx->cfg.header) 704 if (ctx.cfg.header)
706 html_include(ctx->cfg.header); 705 html_include(ctx.cfg.header);
707} 706}
708 707
709void cgit_print_docend() 708void cgit_print_docend()
@@ -767,47 +766,47 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search,
767 } 766 }
768} 767}
769 768
770static const char *hc(struct cgit_context *ctx, const char *page) 769static const char *hc(const char *page)
771{ 770{
772 return strcmp(ctx->qry.page, page) ? NULL : "active"; 771 return strcmp(ctx.qry.page, page) ? NULL : "active";
773} 772}
774 773
775static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) 774static void cgit_print_path_crumbs(char *path)
776{ 775{
777 char *old_path = ctx->qry.path; 776 char *old_path = ctx.qry.path;
778 char *p = path, *q, *end = path + strlen(path); 777 char *p = path, *q, *end = path + strlen(path);
779 778
780 ctx->qry.path = NULL; 779 ctx.qry.path = NULL;
781 cgit_self_link("root", NULL, NULL, ctx); 780 cgit_self_link("root", NULL, NULL);
782 ctx->qry.path = p = path; 781 ctx.qry.path = p = path;
783 while (p < end) { 782 while (p < end) {
784 if (!(q = strchr(p, '/'))) 783 if (!(q = strchr(p, '/')))
785 q = end; 784 q = end;
786 *q = '\0'; 785 *q = '\0';
787 html_txt("/"); 786 html_txt("/");
788 cgit_self_link(p, NULL, NULL, ctx); 787 cgit_self_link(p, NULL, NULL);
789 if (q < end) 788 if (q < end)
790 *q = '/'; 789 *q = '/';
791 p = q + 1; 790 p = q + 1;
792 } 791 }
793 ctx->qry.path = old_path; 792 ctx.qry.path = old_path;
794} 793}
795 794
796static void print_header(struct cgit_context *ctx) 795static void print_header(void)
797{ 796{
798 char *logo = NULL, *logo_link = NULL; 797 char *logo = NULL, *logo_link = NULL;
799 798
800 html("<table id='header'>\n"); 799 html("<table id='header'>\n");
801 html("<tr>\n"); 800 html("<tr>\n");
802 801
803 if (ctx->repo && ctx->repo->logo && *ctx->repo->logo) 802 if (ctx.repo && ctx.repo->logo && *ctx.repo->logo)
804 logo = ctx->repo->logo; 803 logo = ctx.repo->logo;
805 else 804 else
806 logo = ctx->cfg.logo; 805 logo = ctx.cfg.logo;
807 if (ctx->repo && ctx->repo->logo_link && *ctx->repo->logo_link) 806 if (ctx.repo && ctx.repo->logo_link && *ctx.repo->logo_link)
808 logo_link = ctx->repo->logo_link; 807 logo_link = ctx.repo->logo_link;
809 else 808 else
810 logo_link = ctx->cfg.logo_link; 809 logo_link = ctx.cfg.logo_link;
811 if (logo && *logo) { 810 if (logo && *logo) {
812 html("<td class='logo' rowspan='2'><a href='"); 811 html("<td class='logo' rowspan='2'><a href='");
813 if (logo_link && *logo_link) 812 if (logo_link && *logo_link)
@@ -820,104 +819,104 @@ static void print_header(struct cgit_context *ctx)
820 } 819 }
821 820
822 html("<td class='main'>"); 821 html("<td class='main'>");
823 if (ctx->repo) { 822 if (ctx.repo) {
824 cgit_index_link("index", NULL, NULL, NULL, NULL, 0); 823 cgit_index_link("index", NULL, NULL, NULL, NULL, 0);
825 html(" : "); 824 html(" : ");
826 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); 825 cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
827 if (ctx->env.authenticated) { 826 if (ctx.env.authenticated) {
828 html("</td><td class='form'>"); 827 html("</td><td class='form'>");
829 html("<form method='get' action=''>\n"); 828 html("<form method='get' action=''>\n");
830 cgit_add_hidden_formfields(0, 1, ctx->qry.page); 829 cgit_add_hidden_formfields(0, 1, ctx.qry.page);
831 html("<select name='h' onchange='this.form.submit();'>\n"); 830 html("<select name='h' onchange='this.form.submit();'>\n");
832 for_each_branch_ref(print_branch_option, ctx->qry.head); 831 for_each_branch_ref(print_branch_option, ctx.qry.head);
833 html("</select> "); 832 html("</select> ");
834 html("<input type='submit' name='' value='switch'/>"); 833 html("<input type='submit' name='' value='switch'/>");
835 html("</form>"); 834 html("</form>");
836 } 835 }
837 } else 836 } else
838 html_txt(ctx->cfg.root_title); 837 html_txt(ctx.cfg.root_title);
839 html("</td></tr>\n"); 838 html("</td></tr>\n");
840 839
841 html("<tr><td class='sub'>"); 840 html("<tr><td class='sub'>");
842 if (ctx->repo) { 841 if (ctx.repo) {
843 html_txt(ctx->repo->desc); 842 html_txt(ctx.repo->desc);
844 html("</td><td class='sub right'>"); 843 html("</td><td class='sub right'>");
845 html_txt(ctx->repo->owner); 844 html_txt(ctx.repo->owner);
846 } else { 845 } else {
847 if (ctx->cfg.root_desc) 846 if (ctx.cfg.root_desc)
848 html_txt(ctx->cfg.root_desc); 847 html_txt(ctx.cfg.root_desc);
849 else if (ctx->cfg.index_info) 848 else if (ctx.cfg.index_info)
850 html_include(ctx->cfg.index_info); 849 html_include(ctx.cfg.index_info);
851 } 850 }
852 html("</td></tr></table>\n"); 851 html("</td></tr></table>\n");
853} 852}
854 853
855void cgit_print_pageheader(struct cgit_context *ctx) 854void cgit_print_pageheader(void)
856{ 855{
857 html("<div id='cgit'>"); 856 html("<div id='cgit'>");
858 if (!ctx->env.authenticated || !ctx->cfg.noheader) 857 if (!ctx.env.authenticated || !ctx.cfg.noheader)
859 print_header(ctx); 858 print_header();
860 859
861 html("<table class='tabs'><tr><td>\n"); 860 html("<table class='tabs'><tr><td>\n");
862 if (ctx->env.authenticated && ctx->repo) { 861 if (ctx.env.authenticated && ctx.repo) {
863 cgit_summary_link("summary", NULL, hc(ctx, "summary"), 862 cgit_summary_link("summary", NULL, hc("summary"),
864 ctx->qry.head); 863 ctx.qry.head);
865 cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, 864 cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head,
866 ctx->qry.sha1, NULL); 865 ctx.qry.sha1, NULL);
867 cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, 866 cgit_log_link("log", NULL, hc("log"), ctx.qry.head,
868 NULL, ctx->qry.vpath, 0, NULL, NULL, 867 NULL, ctx.qry.vpath, 0, NULL, NULL,
869 ctx->qry.showmsg); 868 ctx.qry.showmsg);
870 cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, 869 cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
871 ctx->qry.sha1, ctx->qry.vpath); 870 ctx.qry.sha1, ctx.qry.vpath);
872 cgit_commit_link("commit", NULL, hc(ctx, "commit"), 871 cgit_commit_link("commit", NULL, hc("commit"),
873 ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); 872 ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, 0);
874 cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, 873 cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
875 ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); 874 ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath, 0);
876 if (ctx->repo->max_stats) 875 if (ctx.repo->max_stats)
877 cgit_stats_link("stats", NULL, hc(ctx, "stats"), 876 cgit_stats_link("stats", NULL, hc("stats"),
878 ctx->qry.head, ctx->qry.vpath); 877 ctx.qry.head, ctx.qry.vpath);
879 if (ctx->repo->readme.nr) 878 if (ctx.repo->readme.nr)
880 reporevlink("about", "about", NULL, 879 reporevlink("about", "about", NULL,
881 hc(ctx, "about"), ctx->qry.head, NULL, 880 hc("about"), ctx.qry.head, NULL,
882 NULL); 881 NULL);
883 html("</td><td class='form'>"); 882 html("</td><td class='form'>");
884 html("<form class='right' method='get' action='"); 883 html("<form class='right' method='get' action='");
885 if (ctx->cfg.virtual_root) 884 if (ctx.cfg.virtual_root)
886 html_url_path(cgit_fileurl(ctx->qry.repo, "log", 885 html_url_path(cgit_fileurl(ctx.qry.repo, "log",
887 ctx->qry.vpath, NULL)); 886 ctx.qry.vpath, NULL));
888 html("'>\n"); 887 html("'>\n");
889 cgit_add_hidden_formfields(1, 0, "log"); 888 cgit_add_hidden_formfields(1, 0, "log");
890 html("<select name='qt'>\n"); 889 html("<select name='qt'>\n");
891 html_option("grep", "log msg", ctx->qry.grep); 890 html_option("grep", "log msg", ctx.qry.grep);
892 html_option("author", "author", ctx->qry.grep); 891 html_option("author", "author", ctx.qry.grep);
893 html_option("committer", "committer", ctx->qry.grep); 892 html_option("committer", "committer", ctx.qry.grep);
894 html_option("range", "range", ctx->qry.grep); 893 html_option("range", "range", ctx.qry.grep);
895 html("</select>\n"); 894 html("</select>\n");
896 html("<input class='txt' type='text' size='10' name='q' value='"); 895 html("<input class='txt' type='text' size='10' name='q' value='");
897 html_attr(ctx->qry.search); 896 html_attr(ctx.qry.search);
898 html("'/>\n"); 897 html("'/>\n");
899 html("<input type='submit' value='search'/>\n"); 898 html("<input type='submit' value='search'/>\n");
900 html("</form>\n"); 899 html("</form>\n");
901 } else if (ctx->env.authenticated) { 900 } else if (ctx.env.authenticated) {
902 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, NULL, 0); 901 site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0);
903 if (ctx->cfg.root_readme) 902 if (ctx.cfg.root_readme)
904 site_link("about", "about", NULL, hc(ctx, "about"), 903 site_link("about", "about", NULL, hc("about"),
905 NULL, NULL, 0); 904 NULL, NULL, 0);
906 html("</td><td class='form'>"); 905 html("</td><td class='form'>");
907 html("<form method='get' action='"); 906 html("<form method='get' action='");
908 html_attr(cgit_rooturl()); 907 html_attr(cgit_rooturl());
909 html("'>\n"); 908 html("'>\n");
910 html("<input type='text' name='q' size='10' value='"); 909 html("<input type='text' name='q' size='10' value='");
911 html_attr(ctx->qry.search); 910 html_attr(ctx.qry.search);
912 html("'/>\n"); 911 html("'/>\n");
913 html("<input type='submit' value='search'/>\n"); 912 html("<input type='submit' value='search'/>\n");
914 html("</form>"); 913 html("</form>");
915 } 914 }
916 html("</td></tr></table>\n"); 915 html("</td></tr></table>\n");
917 if (ctx->env.authenticated && ctx->qry.vpath) { 916 if (ctx.env.authenticated && ctx.qry.vpath) {
918 html("<div class='path'>"); 917 html("<div class='path'>");
919 html("path: "); 918 html("path: ");
920 cgit_print_path_crumbs(ctx, ctx->qry.vpath); 919 cgit_print_path_crumbs(ctx.qry.vpath);
921 html("</div>"); 920 html("</div>");
922 } 921 }
923 html("<div class='content'>"); 922 html("<div class='content'>");
diff --git a/ui-shared.h b/ui-shared.h
index 889c28f..3e7a91b 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -59,10 +59,10 @@ __attribute__((format (printf,1,0)))
59extern void cgit_vprint_error(const char *fmt, va_list ap); 59extern void cgit_vprint_error(const char *fmt, va_list ap);
60extern void cgit_print_date(time_t secs, const char *format, int local_time); 60extern void cgit_print_date(time_t secs, const char *format, int local_time);
61extern void cgit_print_age(time_t t, time_t max_relative, const char *format); 61extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
62extern void cgit_print_http_headers(struct cgit_context *ctx); 62extern void cgit_print_http_headers(void);
63extern void cgit_print_docstart(struct cgit_context *ctx); 63extern void cgit_print_docstart(void);
64extern void cgit_print_docend(); 64extern void cgit_print_docend();
65extern void cgit_print_pageheader(struct cgit_context *ctx); 65extern void cgit_print_pageheader(void);
66extern void cgit_print_filemode(unsigned short mode); 66extern void cgit_print_filemode(unsigned short mode);
67extern void cgit_print_snapshot_links(const char *repo, const char *head, 67extern void cgit_print_snapshot_links(const char *repo, const char *head,
68 const char *hex, int snapshots); 68 const char *hex, int snapshots);
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 7115ec4..582dc31 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -121,7 +121,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
121 } 121 }
122 ctx.page.mimetype = xstrdup(format->mimetype); 122 ctx.page.mimetype = xstrdup(format->mimetype);
123 ctx.page.filename = xstrdup(filename); 123 ctx.page.filename = xstrdup(filename);
124 cgit_print_http_headers(&ctx); 124 cgit_print_http_headers();
125 format->write_func(hex, prefix); 125 format->write_func(hex, prefix);
126 return 0; 126 return 0;
127} 127}
@@ -183,9 +183,9 @@ static void show_error(char *fmt, ...)
183 va_list ap; 183 va_list ap;
184 184
185 ctx.page.mimetype = "text/html"; 185 ctx.page.mimetype = "text/html";
186 cgit_print_http_headers(&ctx); 186 cgit_print_http_headers();
187 cgit_print_docstart(&ctx); 187 cgit_print_docstart();
188 cgit_print_pageheader(&ctx); 188 cgit_print_pageheader();
189 va_start(ap, fmt); 189 va_start(ap, fmt);
190 cgit_vprint_error(fmt, ap); 190 cgit_vprint_error(fmt, ap);
191 va_end(ap); 191 va_end(ap);
diff --git a/ui-stats.c b/ui-stats.c
index 84b247c..bc27308 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -209,13 +209,12 @@ static int cmp_total_commits(const void *a1, const void *a2)
209/* Walk the commit DAG and collect number of commits per author per 209/* Walk the commit DAG and collect number of commits per author per
210 * timeperiod into a nested string_list collection. 210 * timeperiod into a nested string_list collection.
211 */ 211 */
212static struct string_list collect_stats(struct cgit_context *ctx, 212static struct string_list collect_stats(struct cgit_period *period)
213 struct cgit_period *period)
214{ 213{
215 struct string_list authors; 214 struct string_list authors;
216 struct rev_info rev; 215 struct rev_info rev;
217 struct commit *commit; 216 struct commit *commit;
218 const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; 217 const char *argv[] = {NULL, ctx.qry.head, NULL, NULL, NULL, NULL};
219 int argc = 3; 218 int argc = 3;
220 time_t now; 219 time_t now;
221 long i; 220 long i;
@@ -229,9 +228,9 @@ static struct string_list collect_stats(struct cgit_context *ctx,
229 period->dec(tm); 228 period->dec(tm);
230 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); 229 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm);
231 argv[2] = xstrdup(fmt("--since=%s", tmp)); 230 argv[2] = xstrdup(fmt("--since=%s", tmp));
232 if (ctx->qry.path) { 231 if (ctx.qry.path) {
233 argv[3] = "--"; 232 argv[3] = "--";
234 argv[4] = ctx->qry.path; 233 argv[4] = ctx.qry.path;
235 argc += 2; 234 argc += 2;
236 } 235 }
237 init_revisions(&rev, NULL); 236 init_revisions(&rev, NULL);
@@ -360,30 +359,30 @@ static void print_authors(struct string_list *authors, int top,
360 * for each author is another string_list which is used to calculate the 359 * for each author is another string_list which is used to calculate the
361 * number of commits per time-interval. 360 * number of commits per time-interval.
362 */ 361 */
363void cgit_show_stats(struct cgit_context *ctx) 362void cgit_show_stats(void)
364{ 363{
365 struct string_list authors; 364 struct string_list authors;
366 struct cgit_period *period; 365 struct cgit_period *period;
367 int top, i; 366 int top, i;
368 const char *code = "w"; 367 const char *code = "w";
369 368
370 if (ctx->qry.period) 369 if (ctx.qry.period)
371 code = ctx->qry.period; 370 code = ctx.qry.period;
372 371
373 i = cgit_find_stats_period(code, &period); 372 i = cgit_find_stats_period(code, &period);
374 if (!i) { 373 if (!i) {
375 cgit_print_error("Unknown statistics type: %c", code[0]); 374 cgit_print_error("Unknown statistics type: %c", code[0]);
376 return; 375 return;
377 } 376 }
378 if (i > ctx->repo->max_stats) { 377 if (i > ctx.repo->max_stats) {
379 cgit_print_error("Statistics type disabled: %s", period->name); 378 cgit_print_error("Statistics type disabled: %s", period->name);
380 return; 379 return;
381 } 380 }
382 authors = collect_stats(ctx, period); 381 authors = collect_stats(period);
383 qsort(authors.items, authors.nr, sizeof(struct string_list_item), 382 qsort(authors.items, authors.nr, sizeof(struct string_list_item),
384 cmp_total_commits); 383 cmp_total_commits);
385 384
386 top = ctx->qry.ofs; 385 top = ctx.qry.ofs;
387 if (!top) 386 if (!top)
388 top = 10; 387 top = 10;
389 388
@@ -392,10 +391,10 @@ void cgit_show_stats(struct cgit_context *ctx)
392 html("<form method='get' action=''>"); 391 html("<form method='get' action=''>");
393 cgit_add_hidden_formfields(1, 0, "stats"); 392 cgit_add_hidden_formfields(1, 0, "stats");
394 html("<table><tr><td colspan='2'/></tr>"); 393 html("<table><tr><td colspan='2'/></tr>");
395 if (ctx->repo->max_stats > 1) { 394 if (ctx.repo->max_stats > 1) {
396 html("<tr><td class='label'>Period:</td>"); 395 html("<tr><td class='label'>Period:</td>");
397 html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>"); 396 html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>");
398 for (i = 0; i < ctx->repo->max_stats; i++) 397 for (i = 0; i < ctx.repo->max_stats; i++)
399 html_option(fmt("%c", periods[i].code), 398 html_option(fmt("%c", periods[i].code),
400 periods[i].name, fmt("%c", period->code)); 399 periods[i].name, fmt("%c", period->code));
401 html("</select></td></tr>"); 400 html("</select></td></tr>");
@@ -414,9 +413,9 @@ void cgit_show_stats(struct cgit_context *ctx)
414 html("</form>"); 413 html("</form>");
415 html("</div>"); 414 html("</div>");
416 htmlf("<h2>Commits per author per %s", period->name); 415 htmlf("<h2>Commits per author per %s", period->name);
417 if (ctx->qry.path) { 416 if (ctx.qry.path) {
418 html(" (path '"); 417 html(" (path '");
419 html_txt(ctx->qry.path); 418 html_txt(ctx.qry.path);
420 html("')"); 419 html("')");
421 } 420 }
422 html("</h2>"); 421 html("</h2>");
diff --git a/ui-stats.h b/ui-stats.h
index f0761ba..341ab13 100644
--- a/ui-stats.h
+++ b/ui-stats.h
@@ -23,6 +23,6 @@ struct cgit_period {
23extern int cgit_find_stats_period(const char *expr, struct cgit_period **period); 23extern int cgit_find_stats_period(const char *expr, struct cgit_period **period);
24extern const char *cgit_find_stats_periodname(int idx); 24extern const char *cgit_find_stats_periodname(int idx);
25 25
26extern void cgit_show_stats(struct cgit_context *ctx); 26extern void cgit_show_stats(void);
27 27
28#endif /* UI_STATS_H */ 28#endif /* UI_STATS_H */