In initialization routines, use the global context variable instead of
passing a pointer around locally.

Signed-off-by: Lukas Fleischer <c...@cryptocrack.de>
---
 cgit.c | 207 ++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 103 insertions(+), 104 deletions(-)

diff --git a/cgit.c b/cgit.c
index 54efd59..19bcd0d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -320,78 +320,78 @@ static void querystring_cb(const char *name, const char 
*value)
        }
 }
 
-static void prepare_context(struct cgit_context *ctx)
+static void prepare_context(void)
 {
-       memset(ctx, 0, sizeof(*ctx));
-       ctx->cfg.agefile = "info/web/last-modified";
-       ctx->cfg.nocache = 0;
-       ctx->cfg.cache_size = 0;
-       ctx->cfg.cache_max_create_time = 5;
-       ctx->cfg.cache_root = CGIT_CACHE_ROOT;
-       ctx->cfg.cache_about_ttl = 15;
-       ctx->cfg.cache_repo_ttl = 5;
-       ctx->cfg.cache_root_ttl = 5;
-       ctx->cfg.cache_scanrc_ttl = 15;
-       ctx->cfg.cache_dynamic_ttl = 5;
-       ctx->cfg.cache_static_ttl = -1;
-       ctx->cfg.case_sensitive_sort = 1;
-       ctx->cfg.branch_sort = 0;
-       ctx->cfg.commit_sort = 0;
-       ctx->cfg.css = "/cgit.css";
-       ctx->cfg.logo = "/cgit.png";
-       ctx->cfg.favicon = "/favicon.ico";
-       ctx->cfg.local_time = 0;
-       ctx->cfg.enable_http_clone = 1;
-       ctx->cfg.enable_index_owner = 1;
-       ctx->cfg.enable_tree_linenumbers = 1;
-       ctx->cfg.enable_git_config = 0;
-       ctx->cfg.max_repo_count = 50;
-       ctx->cfg.max_commit_count = 50;
-       ctx->cfg.max_lock_attempts = 5;
-       ctx->cfg.max_msg_len = 80;
-       ctx->cfg.max_repodesc_len = 80;
-       ctx->cfg.max_blob_size = 0;
-       ctx->cfg.max_stats = 0;
-       ctx->cfg.project_list = NULL;
-       ctx->cfg.renamelimit = -1;
-       ctx->cfg.remove_suffix = 0;
-       ctx->cfg.robots = "index, nofollow";
-       ctx->cfg.root_title = "Git repository browser";
-       ctx->cfg.root_desc = "a fast webinterface for the git dscm";
-       ctx->cfg.scan_hidden_path = 0;
-       ctx->cfg.script_name = CGIT_SCRIPT_NAME;
-       ctx->cfg.section = "";
-       ctx->cfg.repository_sort = "name";
-       ctx->cfg.section_sort = 1;
-       ctx->cfg.summary_branches = 10;
-       ctx->cfg.summary_log = 10;
-       ctx->cfg.summary_tags = 10;
-       ctx->cfg.max_atom_items = 10;
-       ctx->cfg.ssdiff = 0;
-       ctx->env.cgit_config = getenv("CGIT_CONFIG");
-       ctx->env.http_host = getenv("HTTP_HOST");
-       ctx->env.https = getenv("HTTPS");
-       ctx->env.no_http = getenv("NO_HTTP");
-       ctx->env.path_info = getenv("PATH_INFO");
-       ctx->env.query_string = getenv("QUERY_STRING");
-       ctx->env.request_method = getenv("REQUEST_METHOD");
-       ctx->env.script_name = getenv("SCRIPT_NAME");
-       ctx->env.server_name = getenv("SERVER_NAME");
-       ctx->env.server_port = getenv("SERVER_PORT");
-       ctx->page.mimetype = "text/html";
-       ctx->page.charset = PAGE_ENCODING;
-       ctx->page.filename = NULL;
-       ctx->page.size = 0;
-       ctx->page.modified = time(NULL);
-       ctx->page.expires = ctx->page.modified;
-       ctx->page.etag = NULL;
-       memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
-       if (ctx->env.script_name)
-               ctx->cfg.script_name = xstrdup(ctx->env.script_name);
-       if (ctx->env.query_string)
-               ctx->qry.raw = xstrdup(ctx->env.query_string);
-       if (!ctx->env.cgit_config)
-               ctx->env.cgit_config = CGIT_CONFIG;
+       memset(&ctx, 0, sizeof(ctx));
+       ctx.cfg.agefile = "info/web/last-modified";
+       ctx.cfg.nocache = 0;
+       ctx.cfg.cache_size = 0;
+       ctx.cfg.cache_max_create_time = 5;
+       ctx.cfg.cache_root = CGIT_CACHE_ROOT;
+       ctx.cfg.cache_about_ttl = 15;
+       ctx.cfg.cache_repo_ttl = 5;
+       ctx.cfg.cache_root_ttl = 5;
+       ctx.cfg.cache_scanrc_ttl = 15;
+       ctx.cfg.cache_dynamic_ttl = 5;
+       ctx.cfg.cache_static_ttl = -1;
+       ctx.cfg.case_sensitive_sort = 1;
+       ctx.cfg.branch_sort = 0;
+       ctx.cfg.commit_sort = 0;
+       ctx.cfg.css = "/cgit.css";
+       ctx.cfg.logo = "/cgit.png";
+       ctx.cfg.favicon = "/favicon.ico";
+       ctx.cfg.local_time = 0;
+       ctx.cfg.enable_http_clone = 1;
+       ctx.cfg.enable_index_owner = 1;
+       ctx.cfg.enable_tree_linenumbers = 1;
+       ctx.cfg.enable_git_config = 0;
+       ctx.cfg.max_repo_count = 50;
+       ctx.cfg.max_commit_count = 50;
+       ctx.cfg.max_lock_attempts = 5;
+       ctx.cfg.max_msg_len = 80;
+       ctx.cfg.max_repodesc_len = 80;
+       ctx.cfg.max_blob_size = 0;
+       ctx.cfg.max_stats = 0;
+       ctx.cfg.project_list = NULL;
+       ctx.cfg.renamelimit = -1;
+       ctx.cfg.remove_suffix = 0;
+       ctx.cfg.robots = "index, nofollow";
+       ctx.cfg.root_title = "Git repository browser";
+       ctx.cfg.root_desc = "a fast webinterface for the git dscm";
+       ctx.cfg.scan_hidden_path = 0;
+       ctx.cfg.script_name = CGIT_SCRIPT_NAME;
+       ctx.cfg.section = "";
+       ctx.cfg.repository_sort = "name";
+       ctx.cfg.section_sort = 1;
+       ctx.cfg.summary_branches = 10;
+       ctx.cfg.summary_log = 10;
+       ctx.cfg.summary_tags = 10;
+       ctx.cfg.max_atom_items = 10;
+       ctx.cfg.ssdiff = 0;
+       ctx.env.cgit_config = getenv("CGIT_CONFIG");
+       ctx.env.http_host = getenv("HTTP_HOST");
+       ctx.env.https = getenv("HTTPS");
+       ctx.env.no_http = getenv("NO_HTTP");
+       ctx.env.path_info = getenv("PATH_INFO");
+       ctx.env.query_string = getenv("QUERY_STRING");
+       ctx.env.request_method = getenv("REQUEST_METHOD");
+       ctx.env.script_name = getenv("SCRIPT_NAME");
+       ctx.env.server_name = getenv("SERVER_NAME");
+       ctx.env.server_port = getenv("SERVER_PORT");
+       ctx.page.mimetype = "text/html";
+       ctx.page.charset = PAGE_ENCODING;
+       ctx.page.filename = NULL;
+       ctx.page.size = 0;
+       ctx.page.modified = time(NULL);
+       ctx.page.expires = ctx.page.modified;
+       ctx.page.etag = NULL;
+       memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list));
+       if (ctx.env.script_name)
+               ctx.cfg.script_name = xstrdup(ctx.env.script_name);
+       if (ctx.env.query_string)
+               ctx.qry.raw = xstrdup(ctx.env.query_string);
+       if (!ctx.env.cgit_config)
+               ctx.env.cgit_config = CGIT_CONFIG;
 }
 
 struct refmatch {
@@ -521,14 +521,14 @@ static void choose_readme(struct cgit_repo *repo)
                string_list_append(&repo->readme, filename)->util = ref;
 }
 
-static int prepare_repo_cmd(struct cgit_context *ctx)
+static int prepare_repo_cmd(void)
 {
        unsigned char sha1[20];
        int nongit = 0;
        int rc;
 
        /* The path to the git repository. */
-       setenv("GIT_DIR", ctx->repo->path, 1);
+       setenv("GIT_DIR", ctx.repo->path, 1);
 
        /* Do not look in /etc/ for gitconfig and gitattributes. */
        setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
@@ -543,11 +543,11 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
        init_display_notes(NULL);
 
        if (nongit) {
-               const char *name = ctx->repo->name;
+               const char *name = ctx.repo->name;
                rc = errno;
-               ctx->page.title = fmtalloc("%s - %s", ctx->cfg.root_title,
+               ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title,
                                                "config error");
-               ctx->repo = NULL;
+               ctx.repo = NULL;
                cgit_print_http_headers();
                cgit_print_docstart();
                cgit_print_pageheader();
@@ -556,17 +556,17 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
                cgit_print_docend();
                return 1;
        }
-       ctx->page.title = fmtalloc("%s - %s", ctx->repo->name, ctx->repo->desc);
+       ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
 
-       if (!ctx->repo->defbranch)
-               ctx->repo->defbranch = guess_defbranch();
+       if (!ctx.repo->defbranch)
+               ctx.repo->defbranch = guess_defbranch();
 
-       if (!ctx->qry.head) {
-               ctx->qry.nohead = 1;
-               ctx->qry.head = find_default_branch(ctx->repo);
+       if (!ctx.qry.head) {
+               ctx.qry.nohead = 1;
+               ctx.qry.head = find_default_branch(ctx.repo);
        }
 
-       if (!ctx->qry.head) {
+       if (!ctx.qry.head) {
                cgit_print_http_headers();
                cgit_print_docstart();
                cgit_print_pageheader();
@@ -575,11 +575,11 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
                return 1;
        }
 
-       if (get_sha1(ctx->qry.head, sha1)) {
-               char *tmp = xstrdup(ctx->qry.head);
-               ctx->qry.head = ctx->repo->defbranch;
-               ctx->page.status = 404;
-               ctx->page.statusmsg = "Not found";
+       if (get_sha1(ctx.qry.head, sha1)) {
+               char *tmp = xstrdup(ctx.qry.head);
+               ctx.qry.head = ctx.repo->defbranch;
+               ctx.page.status = 404;
+               ctx.page.statusmsg = "Not found";
                cgit_print_http_headers();
                cgit_print_docstart();
                cgit_print_pageheader();
@@ -587,22 +587,21 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
                cgit_print_docend();
                return 1;
        }
-       sort_string_list(&ctx->repo->submodules);
-       cgit_prepare_repo_env(ctx->repo);
-       choose_readme(ctx->repo);
+       sort_string_list(&ctx.repo->submodules);
+       cgit_prepare_repo_env(ctx.repo);
+       choose_readme(ctx.repo);
        return 0;
 }
 
 static void process_request(void *cbdata)
 {
-       struct cgit_context *ctx = cbdata;
        struct cgit_cmd *cmd;
 
        cmd = cgit_get_cmd();
        if (!cmd) {
-               ctx->page.title = "cgit error";
-               ctx->page.status = 404;
-               ctx->page.statusmsg = "Not found";
+               ctx.page.title = "cgit error";
+               ctx.page.status = 404;
+               ctx.page.statusmsg = "Not found";
                cgit_print_http_headers();
                cgit_print_docstart();
                cgit_print_pageheader();
@@ -611,18 +610,18 @@ static void process_request(void *cbdata)
                return;
        }
 
-       if (!ctx->cfg.enable_http_clone && cmd->is_clone) {
+       if (!ctx.cfg.enable_http_clone && cmd->is_clone) {
                html_status(404, "Not found", 0);
                return;
        }
 
-       /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
-        * in-project path limit to be made available at ctx->qry.vpath.
-        * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
+       /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
+        * in-project path limit to be made available at ctx.qry.vpath.
+        * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
         */
-       ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL;
+       ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
 
-       if (cmd->want_repo && !ctx->repo) {
+       if (cmd->want_repo && !ctx.repo) {
                cgit_print_http_headers();
                cgit_print_docstart();
                cgit_print_pageheader();
@@ -631,7 +630,7 @@ static void process_request(void *cbdata)
                return;
        }
 
-       if (ctx->repo && prepare_repo_cmd(ctx))
+       if (ctx.repo && prepare_repo_cmd())
                return;
 
        if (cmd->want_layout) {
@@ -912,7 +911,7 @@ int main(int argc, const char **argv)
 
        cgit_init_filters();
 
-       prepare_context(&ctx);
+       prepare_context();
        cgit_repolist.length = 0;
        cgit_repolist.count = 0;
        cgit_repolist.repos = NULL;
@@ -958,7 +957,7 @@ int main(int argc, const char **argv)
        if (ctx.cfg.nocache)
                ctx.cfg.cache_size = 0;
        err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
-                           ctx.qry.raw, ttl, process_request, &ctx);
+                           ctx.qry.raw, ttl, process_request, NULL);
        cgit_cleanup_filters();
        if (err)
                cgit_print_error("Error processing page: %s (%d)",
-- 
1.8.5.2

_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to