From d14d77fe95c3b6224b40df9b101dded0deea913c Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 11:53:40 +0100 Subject: Introduce struct cgit_context This struct will hold all the cgit runtime information currently found in a multitude of global variables. The first cleanup removes all querystring-related variables. Signed-off-by: Lars Hjemli --- shared.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index f063894..6c1a762 100644 --- a/shared.c +++ b/shared.c @@ -10,6 +10,7 @@ struct repolist cgit_repolist; struct repoinfo *cgit_repo; +struct cgit_context ctx; int cgit_cmd; const char *cgit_version = CGIT_VERSION; @@ -49,24 +50,8 @@ int cgit_max_msg_len = 60; int cgit_max_repodesc_len = 60; int cgit_max_commit_count = 50; -int cgit_query_has_symref = 0; -int cgit_query_has_sha1 = 0; - -char *cgit_querystring = NULL; -char *cgit_query_repo = NULL; -char *cgit_query_page = NULL; -char *cgit_query_head = NULL; -char *cgit_query_search = NULL; -char *cgit_query_grep = NULL; -char *cgit_query_sha1 = NULL; -char *cgit_query_sha2 = NULL; -char *cgit_query_path = NULL; -char *cgit_query_name = NULL; -int cgit_query_ofs = 0; - int htmlfd = 0; - int cgit_get_cmd_index(const char *cmd) { static char *cmds[] = {"log", "commit", "diff", "tree", "blob", @@ -239,32 +224,32 @@ void cgit_global_config_cb(const char *name, const char *value) void cgit_querystring_cb(const char *name, const char *value) { if (!strcmp(name,"r")) { - cgit_query_repo = xstrdup(value); + ctx.qry.repo = xstrdup(value); cgit_repo = cgit_get_repoinfo(value); } else if (!strcmp(name, "p")) { - cgit_query_page = xstrdup(value); + ctx.qry.page = xstrdup(value); cgit_cmd = cgit_get_cmd_index(value); } else if (!strcmp(name, "url")) { cgit_parse_url(value); } else if (!strcmp(name, "qt")) { - cgit_query_grep = xstrdup(value); + ctx.qry.grep = xstrdup(value); } else if (!strcmp(name, "q")) { - cgit_query_search = xstrdup(value); + ctx.qry.search = xstrdup(value); } else if (!strcmp(name, "h")) { - cgit_query_head = xstrdup(value); - cgit_query_has_symref = 1; + ctx.qry.head = xstrdup(value); + ctx.qry.has_symref = 1; } else if (!strcmp(name, "id")) { - cgit_query_sha1 = xstrdup(value); - cgit_query_has_sha1 = 1; + ctx.qry.sha1 = xstrdup(value); + ctx.qry.has_sha1 = 1; } else if (!strcmp(name, "id2")) { - cgit_query_sha2 = xstrdup(value); - cgit_query_has_sha1 = 1; + ctx.qry.sha2 = xstrdup(value); + ctx.qry.has_sha1 = 1; } else if (!strcmp(name, "ofs")) { - cgit_query_ofs = atoi(value); + ctx.qry.ofs = atoi(value); } else if (!strcmp(name, "path")) { - cgit_query_path = trim_end(value, '/'); + ctx.qry.path = trim_end(value, '/'); } else if (!strcmp(name, "name")) { - cgit_query_name = xstrdup(value); + ctx.qry.name = xstrdup(value); } } -- cgit v1.2.1 From b228d4ff82a65fdcd4a7364759fe36a0bdda5978 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 13:07:13 +0100 Subject: Add all config variables into struct cgit_context This removes another big set of global variables, and introduces the cgit_prepare_context() function which populates a context-variable with compile-time default values. Signed-off-by: Lars Hjemli --- shared.c | 138 +++++++++++++++++++++++++++++---------------------------------- 1 file changed, 63 insertions(+), 75 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 6c1a762..8dd2b00 100644 --- a/shared.c +++ b/shared.c @@ -15,43 +15,31 @@ int cgit_cmd; const char *cgit_version = CGIT_VERSION; -char *cgit_root_title = "Git repository browser"; -char *cgit_css = "/cgit.css"; -char *cgit_logo = "/git-logo.png"; -char *cgit_index_header = NULL; -char *cgit_index_info = NULL; -char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; -char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; -char *cgit_agefile = "info/web/last-modified"; -char *cgit_virtual_root = NULL; -char *cgit_script_name = CGIT_SCRIPT_NAME; -char *cgit_cache_root = CGIT_CACHE_ROOT; -char *cgit_repo_group = NULL; -char *cgit_robots = "index, nofollow"; -char *cgit_clone_prefix = NULL; - -int cgit_nocache = 0; -int cgit_snapshots = 0; -int cgit_enable_index_links = 0; -int cgit_enable_log_filecount = 0; -int cgit_enable_log_linecount = 0; -int cgit_max_lock_attempts = 5; -int cgit_cache_root_ttl = 5; -int cgit_cache_repo_ttl = 5; -int cgit_cache_dynamic_ttl = 5; -int cgit_cache_static_ttl = -1; -int cgit_cache_max_create_time = 5; -int cgit_summary_log = 0; -int cgit_summary_tags = 0; -int cgit_summary_branches = 0; -int cgit_renamelimit = -1; - -int cgit_max_msg_len = 60; -int cgit_max_repodesc_len = 60; -int cgit_max_commit_count = 50; - int htmlfd = 0; +void cgit_prepare_context(struct cgit_context *ctx) +{ + memset(ctx, 0, sizeof(ctx)); + ctx->cfg.agefile = "info/web/last-modified"; + ctx->cfg.cache_dynamic_ttl = 5; + ctx->cfg.cache_max_create_time = 5; + ctx->cfg.cache_repo_ttl = 5; + ctx->cfg.cache_root = CGIT_CACHE_ROOT; + ctx->cfg.cache_root_ttl = 5; + ctx->cfg.cache_static_ttl = -1; + ctx->cfg.css = "/cgit.css"; + ctx->cfg.logo = "/git-logo.png"; + ctx->cfg.max_commit_count = 50; + ctx->cfg.max_lock_attempts = 5; + ctx->cfg.max_msg_len = 60; + ctx->cfg.max_repodesc_len = 60; + ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; + ctx->cfg.renamelimit = -1; + ctx->cfg.robots = "index, nofollow"; + ctx->cfg.root_title = "Git repository browser"; + ctx->cfg.script_name = CGIT_SCRIPT_NAME; +} + int cgit_get_cmd_index(const char *cmd) { static char *cmds[] = {"log", "commit", "diff", "tree", "blob", @@ -105,12 +93,12 @@ struct repoinfo *add_repo(const char *url) ret->path = NULL; ret->desc = "[no description]"; ret->owner = NULL; - ret->group = cgit_repo_group; + ret->group = ctx.cfg.repo_group; ret->defbranch = "master"; - ret->snapshots = cgit_snapshots; - ret->enable_log_filecount = cgit_enable_log_filecount; - ret->enable_log_linecount = cgit_enable_log_linecount; - ret->module_link = cgit_module_link; + ret->snapshots = ctx.cfg.snapshots; + ret->enable_log_filecount = ctx.cfg.enable_log_filecount; + ret->enable_log_linecount = ctx.cfg.enable_log_linecount; + ret->module_link = ctx.cfg.module_link; ret->readme = NULL; return ret; } @@ -131,65 +119,65 @@ struct repoinfo *cgit_get_repoinfo(const char *url) void cgit_global_config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) - cgit_root_title = xstrdup(value); + ctx.cfg.root_title = xstrdup(value); else if (!strcmp(name, "css")) - cgit_css = xstrdup(value); + ctx.cfg.css = xstrdup(value); else if (!strcmp(name, "logo")) - cgit_logo = xstrdup(value); + ctx.cfg.logo = xstrdup(value); else if (!strcmp(name, "index-header")) - cgit_index_header = xstrdup(value); + ctx.cfg.index_header = xstrdup(value); else if (!strcmp(name, "index-info")) - cgit_index_info = xstrdup(value); + ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) - cgit_logo_link = xstrdup(value); + ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) - cgit_module_link = xstrdup(value); + ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) { - cgit_virtual_root = trim_end(value, '/'); - if (!cgit_virtual_root && (!strcmp(value, "/"))) - cgit_virtual_root = ""; + ctx.cfg.virtual_root = trim_end(value, '/'); + if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) + ctx.cfg.virtual_root = ""; } else if (!strcmp(name, "nocache")) - cgit_nocache = atoi(value); + ctx.cfg.nocache = atoi(value); else if (!strcmp(name, "snapshots")) - cgit_snapshots = cgit_parse_snapshots_mask(value); + ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-index-links")) - cgit_enable_index_links = atoi(value); + ctx.cfg.enable_index_links = atoi(value); else if (!strcmp(name, "enable-log-filecount")) - cgit_enable_log_filecount = atoi(value); + ctx.cfg.enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) - cgit_enable_log_linecount = atoi(value); + ctx.cfg.enable_log_linecount = atoi(value); else if (!strcmp(name, "cache-root")) - cgit_cache_root = xstrdup(value); + ctx.cfg.cache_root = xstrdup(value); else if (!strcmp(name, "cache-root-ttl")) - cgit_cache_root_ttl = atoi(value); + ctx.cfg.cache_root_ttl = atoi(value); else if (!strcmp(name, "cache-repo-ttl")) - cgit_cache_repo_ttl = atoi(value); + ctx.cfg.cache_repo_ttl = atoi(value); else if (!strcmp(name, "cache-static-ttl")) - cgit_cache_static_ttl = atoi(value); + ctx.cfg.cache_static_ttl = atoi(value); else if (!strcmp(name, "cache-dynamic-ttl")) - cgit_cache_dynamic_ttl = atoi(value); + ctx.cfg.cache_dynamic_ttl = atoi(value); else if (!strcmp(name, "max-message-length")) - cgit_max_msg_len = atoi(value); + ctx.cfg.max_msg_len = atoi(value); else if (!strcmp(name, "max-repodesc-length")) - cgit_max_repodesc_len = atoi(value); + ctx.cfg.max_repodesc_len = atoi(value); else if (!strcmp(name, "max-commit-count")) - cgit_max_commit_count = atoi(value); + ctx.cfg.max_commit_count = atoi(value); else if (!strcmp(name, "summary-log")) - cgit_summary_log = atoi(value); + ctx.cfg.summary_log = atoi(value); else if (!strcmp(name, "summary-branches")) - cgit_summary_branches = atoi(value); + ctx.cfg.summary_branches = atoi(value); else if (!strcmp(name, "summary-tags")) - cgit_summary_tags = atoi(value); + ctx.cfg.summary_tags = atoi(value); else if (!strcmp(name, "agefile")) - cgit_agefile = xstrdup(value); + ctx.cfg.agefile = xstrdup(value); else if (!strcmp(name, "renamelimit")) - cgit_renamelimit = atoi(value); + ctx.cfg.renamelimit = atoi(value); else if (!strcmp(name, "robots")) - cgit_robots = xstrdup(value); + ctx.cfg.robots = xstrdup(value); else if (!strcmp(name, "clone-prefix")) - cgit_clone_prefix = xstrdup(value); + ctx.cfg.clone_prefix = xstrdup(value); else if (!strcmp(name, "repo.group")) - cgit_repo_group = xstrdup(value); + ctx.cfg.repo_group = xstrdup(value); else if (!strcmp(name, "repo.url")) cgit_repo = add_repo(value); else if (!strcmp(name, "repo.name")) @@ -205,11 +193,11 @@ void cgit_global_config_cb(const char *name, const char *value) else if (cgit_repo && !strcmp(name, "repo.defbranch")) cgit_repo->defbranch = xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.snapshots")) - cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ + cgit_repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) - cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); + cgit_repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) - cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); + cgit_repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); else if (cgit_repo && !strcmp(name, "repo.module-link")) cgit_repo->module_link= xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { @@ -476,7 +464,7 @@ void cgit_diff_tree(const unsigned char *old_sha1, diff_setup(&opt); opt.output_format = DIFF_FORMAT_CALLBACK; opt.detect_rename = 1; - opt.rename_limit = cgit_renamelimit; + opt.rename_limit = ctx.cfg.renamelimit; DIFF_OPT_SET(&opt, RECURSIVE); opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; -- cgit v1.2.1 From d1f3bbe9d22029f45a77bb938c176ccc0c827d46 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Feb 2008 13:56:09 +0100 Subject: Move cgit_repo into cgit_context This removes the global variable which is used to keep track of the currently selected repository, and adds a new variable in the cgit_context structure. Signed-off-by: Lars Hjemli --- shared.c | 61 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 8dd2b00..808e674 100644 --- a/shared.c +++ b/shared.c @@ -8,8 +8,7 @@ #include "cgit.h" -struct repolist cgit_repolist; -struct repoinfo *cgit_repo; +struct cgit_repolist cgit_repolist; struct cgit_context ctx; int cgit_cmd; @@ -73,9 +72,9 @@ int chk_non_negative(int result, char *msg) return result; } -struct repoinfo *add_repo(const char *url) +struct cgit_repo *add_repo(const char *url) { - struct repoinfo *ret; + struct cgit_repo *ret; if (++cgit_repolist.count > cgit_repolist.length) { if (cgit_repolist.length == 0) @@ -84,7 +83,7 @@ struct repoinfo *add_repo(const char *url) cgit_repolist.length *= 2; cgit_repolist.repos = xrealloc(cgit_repolist.repos, cgit_repolist.length * - sizeof(struct repoinfo)); + sizeof(struct cgit_repo)); } ret = &cgit_repolist.repos[cgit_repolist.count-1]; @@ -103,10 +102,10 @@ struct repoinfo *add_repo(const char *url) return ret; } -struct repoinfo *cgit_get_repoinfo(const char *url) +struct cgit_repo *cgit_get_repoinfo(const char *url) { int i; - struct repoinfo *repo; + struct cgit_repo *repo; for (i=0; iname = xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.path")) - cgit_repo->path = trim_end(value, '/'); - else if (cgit_repo && !strcmp(name, "repo.clone-url")) - cgit_repo->clone_url = xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.desc")) - cgit_repo->desc = xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.owner")) - cgit_repo->owner = xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.defbranch")) - cgit_repo->defbranch = xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.snapshots")) - cgit_repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ - else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) - cgit_repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); - else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) - cgit_repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); - else if (cgit_repo && !strcmp(name, "repo.module-link")) - cgit_repo->module_link= xstrdup(value); - else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { + ctx.repo->name = xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.path")) + ctx.repo->path = trim_end(value, '/'); + else if (ctx.repo && !strcmp(name, "repo.clone-url")) + ctx.repo->clone_url = xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.desc")) + ctx.repo->desc = xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.owner")) + ctx.repo->owner = xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.defbranch")) + ctx.repo->defbranch = xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.snapshots")) + ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ + else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) + ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); + else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) + ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); + else if (ctx.repo && !strcmp(name, "repo.module-link")) + ctx.repo->module_link= xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { if (*value == '/') - cgit_repo->readme = xstrdup(value); + ctx.repo->readme = xstrdup(value); else - cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); + ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); } else if (!strcmp(name, "include")) cgit_read_config(value, cgit_global_config_cb); } @@ -213,7 +212,7 @@ void cgit_querystring_cb(const char *name, const char *value) { if (!strcmp(name,"r")) { ctx.qry.repo = xstrdup(value); - cgit_repo = cgit_get_repoinfo(value); + ctx.repo = cgit_get_repoinfo(value); } else if (!strcmp(name, "p")) { ctx.qry.page = xstrdup(value); cgit_cmd = cgit_get_cmd_index(value); -- cgit v1.2.1 From b1f9b9c1459cb9a30ebf80721aff6ef788d1f891 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 23 Feb 2008 22:45:33 +0100 Subject: Introduce html.h All html-functions can be quite easily separated from the rest of cgit, so lets do it; the only issue was html_filemode which uses some git-defined macros so the function is moved into ui-shared.c::cgit_print_filemode(). Signed-off-by: Lars Hjemli --- shared.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 808e674..76e10d0 100644 --- a/shared.c +++ b/shared.c @@ -14,8 +14,6 @@ int cgit_cmd; const char *cgit_version = CGIT_VERSION; -int htmlfd = 0; - void cgit_prepare_context(struct cgit_context *ctx) { memset(ctx, 0, sizeof(ctx)); -- cgit v1.2.1 From f3c1a187fe2bc33f8423cd535d5045899699995b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 00:51:19 +0100 Subject: Add struct cgit_page to cgit_context This struct is used when generating http headers, and as such is another small step towards the goal of the whole cleanup series; to invoke each page/view function with a function pointer. Signed-off-by: Lars Hjemli --- shared.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 76e10d0..539d533 100644 --- a/shared.c +++ b/shared.c @@ -35,6 +35,9 @@ void cgit_prepare_context(struct cgit_context *ctx) ctx->cfg.robots = "index, nofollow"; ctx->cfg.root_title = "Git repository browser"; ctx->cfg.script_name = CGIT_SCRIPT_NAME; + ctx->page.mimetype = "text/html"; + ctx->page.charset = PAGE_ENCODING; + ctx->page.filename = NULL; } int cgit_get_cmd_index(const char *cmd) -- cgit v1.2.1 From e0e4478e7b4812f822d60a13a33525f8e529e1e8 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 01:09:39 +0100 Subject: Add command dispatcher This simplifies the code in cgit.c and makes it easier to extend cgit with new pages/commands. Signed-off-by: Lars Hjemli --- shared.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 539d533..67eb67b 100644 --- a/shared.c +++ b/shared.c @@ -40,18 +40,6 @@ void cgit_prepare_context(struct cgit_context *ctx) ctx->page.filename = NULL; } -int cgit_get_cmd_index(const char *cmd) -{ - static char *cmds[] = {"log", "commit", "diff", "tree", "blob", - "snapshot", "tag", "refs", "patch", NULL}; - int i; - - for(i = 0; cmds[i]; i++) - if (!strcmp(cmd, cmds[i])) - return i + 1; - return 0; -} - int chk_zero(int result, char *msg) { if (result != 0) @@ -216,7 +204,6 @@ void cgit_querystring_cb(const char *name, const char *value) ctx.repo = cgit_get_repoinfo(value); } else if (!strcmp(name, "p")) { ctx.qry.page = xstrdup(value); - cgit_cmd = cgit_get_cmd_index(value); } else if (!strcmp(name, "url")) { cgit_parse_url(value); } else if (!strcmp(name, "qt")) { -- cgit v1.2.1 From f34478cbe0214a201e7ecef3e79ed6c957b7beee Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 16:00:27 +0100 Subject: Refactor snapshot support The snapshot support needs to be split between output- and config-related functions to get the layering between shared.c and ui-*.c right. There is also some codestyle-issues which needs fixing to make the snapshot functions more similar to the rest of the cgit code. Signed-off-by: Lars Hjemli --- shared.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 67eb67b..800c06a 100644 --- a/shared.c +++ b/shared.c @@ -479,3 +479,30 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn) old_sha1 = commit->parents->item->object.sha1; cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); } + +int cgit_parse_snapshots_mask(const char *str) +{ + const struct cgit_snapshot_format *f; + static const char *delim = " \t,:/|;"; + int tl, sl, rv = 0; + + /* favor legacy setting */ + if(atoi(str)) + return 1; + for(;;) { + str += strspn(str,delim); + tl = strcspn(str,delim); + if (!tl) + break; + for (f = cgit_snapshot_formats; f->suffix; f++) { + sl = strlen(f->suffix); + if((tl == sl && !strncmp(f->suffix, str, tl)) || + (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) { + rv |= f->bit; + break; + } + } + str += tl; + } + return rv; +} -- cgit v1.2.1 From 163037e79c6cde1073d555dbeae2a095298e6101 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 17:26:08 +0100 Subject: Move non-generic functions from shared.c to cgit.c Signed-off-by: Lars Hjemli --- shared.c | 152 +-------------------------------------------------------------- 1 file changed, 1 insertion(+), 151 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 800c06a..cd60da5 100644 --- a/shared.c +++ b/shared.c @@ -14,32 +14,6 @@ int cgit_cmd; const char *cgit_version = CGIT_VERSION; -void cgit_prepare_context(struct cgit_context *ctx) -{ - memset(ctx, 0, sizeof(ctx)); - ctx->cfg.agefile = "info/web/last-modified"; - ctx->cfg.cache_dynamic_ttl = 5; - ctx->cfg.cache_max_create_time = 5; - ctx->cfg.cache_repo_ttl = 5; - ctx->cfg.cache_root = CGIT_CACHE_ROOT; - ctx->cfg.cache_root_ttl = 5; - ctx->cfg.cache_static_ttl = -1; - ctx->cfg.css = "/cgit.css"; - ctx->cfg.logo = "/git-logo.png"; - ctx->cfg.max_commit_count = 50; - ctx->cfg.max_lock_attempts = 5; - ctx->cfg.max_msg_len = 60; - ctx->cfg.max_repodesc_len = 60; - ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; - ctx->cfg.renamelimit = -1; - ctx->cfg.robots = "index, nofollow"; - ctx->cfg.root_title = "Git repository browser"; - ctx->cfg.script_name = CGIT_SCRIPT_NAME; - ctx->page.mimetype = "text/html"; - ctx->page.charset = PAGE_ENCODING; - ctx->page.filename = NULL; -} - int chk_zero(int result, char *msg) { if (result != 0) @@ -61,7 +35,7 @@ int chk_non_negative(int result, char *msg) return result; } -struct cgit_repo *add_repo(const char *url) +struct cgit_repo *cgit_add_repo(const char *url) { struct cgit_repo *ret; @@ -104,130 +78,6 @@ struct cgit_repo *cgit_get_repoinfo(const char *url) return NULL; } -void cgit_global_config_cb(const char *name, const char *value) -{ - if (!strcmp(name, "root-title")) - ctx.cfg.root_title = xstrdup(value); - else if (!strcmp(name, "css")) - ctx.cfg.css = xstrdup(value); - else if (!strcmp(name, "logo")) - ctx.cfg.logo = xstrdup(value); - else if (!strcmp(name, "index-header")) - ctx.cfg.index_header = xstrdup(value); - else if (!strcmp(name, "index-info")) - ctx.cfg.index_info = xstrdup(value); - else if (!strcmp(name, "logo-link")) - ctx.cfg.logo_link = xstrdup(value); - else if (!strcmp(name, "module-link")) - ctx.cfg.module_link = xstrdup(value); - else if (!strcmp(name, "virtual-root")) { - ctx.cfg.virtual_root = trim_end(value, '/'); - if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) - ctx.cfg.virtual_root = ""; - } else if (!strcmp(name, "nocache")) - ctx.cfg.nocache = atoi(value); - else if (!strcmp(name, "snapshots")) - ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); - else if (!strcmp(name, "enable-index-links")) - ctx.cfg.enable_index_links = atoi(value); - else if (!strcmp(name, "enable-log-filecount")) - ctx.cfg.enable_log_filecount = atoi(value); - else if (!strcmp(name, "enable-log-linecount")) - ctx.cfg.enable_log_linecount = atoi(value); - else if (!strcmp(name, "cache-root")) - ctx.cfg.cache_root = xstrdup(value); - else if (!strcmp(name, "cache-root-ttl")) - ctx.cfg.cache_root_ttl = atoi(value); - else if (!strcmp(name, "cache-repo-ttl")) - ctx.cfg.cache_repo_ttl = atoi(value); - else if (!strcmp(name, "cache-static-ttl")) - ctx.cfg.cache_static_ttl = atoi(value); - else if (!strcmp(name, "cache-dynamic-ttl")) - ctx.cfg.cache_dynamic_ttl = atoi(value); - else if (!strcmp(name, "max-message-length")) - ctx.cfg.max_msg_len = atoi(value); - else if (!strcmp(name, "max-repodesc-length")) - ctx.cfg.max_repodesc_len = atoi(value); - else if (!strcmp(name, "max-commit-count")) - ctx.cfg.max_commit_count = atoi(value); - else if (!strcmp(name, "summary-log")) - ctx.cfg.summary_log = atoi(value); - else if (!strcmp(name, "summary-branches")) - ctx.cfg.summary_branches = atoi(value); - else if (!strcmp(name, "summary-tags")) - ctx.cfg.summary_tags = atoi(value); - else if (!strcmp(name, "agefile")) - ctx.cfg.agefile = xstrdup(value); - else if (!strcmp(name, "renamelimit")) - ctx.cfg.renamelimit = atoi(value); - else if (!strcmp(name, "robots")) - ctx.cfg.robots = xstrdup(value); - else if (!strcmp(name, "clone-prefix")) - ctx.cfg.clone_prefix = xstrdup(value); - else if (!strcmp(name, "repo.group")) - ctx.cfg.repo_group = xstrdup(value); - else if (!strcmp(name, "repo.url")) - ctx.repo = add_repo(value); - else if (!strcmp(name, "repo.name")) - ctx.repo->name = xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.path")) - ctx.repo->path = trim_end(value, '/'); - else if (ctx.repo && !strcmp(name, "repo.clone-url")) - ctx.repo->clone_url = xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.desc")) - ctx.repo->desc = xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.owner")) - ctx.repo->owner = xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.defbranch")) - ctx.repo->defbranch = xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.snapshots")) - ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ - else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) - ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); - else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) - ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); - else if (ctx.repo && !strcmp(name, "repo.module-link")) - ctx.repo->module_link= xstrdup(value); - else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { - if (*value == '/') - ctx.repo->readme = xstrdup(value); - else - ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); - } else if (!strcmp(name, "include")) - cgit_read_config(value, cgit_global_config_cb); -} - -void cgit_querystring_cb(const char *name, const char *value) -{ - if (!strcmp(name,"r")) { - ctx.qry.repo = xstrdup(value); - ctx.repo = cgit_get_repoinfo(value); - } else if (!strcmp(name, "p")) { - ctx.qry.page = xstrdup(value); - } else if (!strcmp(name, "url")) { - cgit_parse_url(value); - } else if (!strcmp(name, "qt")) { - ctx.qry.grep = xstrdup(value); - } else if (!strcmp(name, "q")) { - ctx.qry.search = xstrdup(value); - } else if (!strcmp(name, "h")) { - ctx.qry.head = xstrdup(value); - ctx.qry.has_symref = 1; - } else if (!strcmp(name, "id")) { - ctx.qry.sha1 = xstrdup(value); - ctx.qry.has_sha1 = 1; - } else if (!strcmp(name, "id2")) { - ctx.qry.sha2 = xstrdup(value); - ctx.qry.has_sha1 = 1; - } else if (!strcmp(name, "ofs")) { - ctx.qry.ofs = atoi(value); - } else if (!strcmp(name, "path")) { - ctx.qry.path = trim_end(value, '/'); - } else if (!strcmp(name, "name")) { - ctx.qry.name = xstrdup(value); - } -} - void *cgit_free_commitinfo(struct commitinfo *info) { free(info->author); -- cgit v1.2.1 From 92908af4558d7362c7deeb05254343a5a5f11a05 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 24 Mar 2008 23:10:59 +0100 Subject: Move cgit_version from shared.c to cgit.c With the matching Makefile change, this makes sure that only cgit.o and cgit proper needs to be rebuildt when VERSION has been modified. Signed-off-by: Lars Hjemli --- shared.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index cd60da5..48002ac 100644 --- a/shared.c +++ b/shared.c @@ -12,8 +12,6 @@ struct cgit_repolist cgit_repolist; struct cgit_context ctx; int cgit_cmd; -const char *cgit_version = CGIT_VERSION; - int chk_zero(int result, char *msg) { if (result != 0) -- cgit v1.2.1 From e87e89633383b8b75c68c98be3e0c14212109de2 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Tue, 8 Apr 2008 21:11:36 +0200 Subject: Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring() This is a generic http-function. Signed-off-by: Lars Hjemli --- shared.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 48002ac..f5875e4 100644 --- a/shared.c +++ b/shared.c @@ -89,18 +89,6 @@ void *cgit_free_commitinfo(struct commitinfo *info) return NULL; } -int hextoint(char c) -{ - if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - else if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - else if (c >= '0' && c <= '9') - return c - '0'; - else - return -1; -} - char *trim_end(const char *str, char c) { int len; -- cgit v1.2.1