author | Lars Hjemli <hjemli@gmail.com> | 2008-04-28 23:13:08 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-04-28 23:13:08 (UTC) |
commit | 905dbaef5aa33ea11d385b82de0188fee73dd655 (patch) (side-by-side diff) | |
tree | 34712da2eef917be04b2acc5585612b65c1e49cc /cgit.c | |
parent | d188ed4f2905e6d10abd26c45572a0d48eb53969 (diff) | |
parent | 71adba1f1678914063fc109cf3805afde2c68f75 (diff) | |
download | cgit-905dbaef5aa33ea11d385b82de0188fee73dd655.zip cgit-905dbaef5aa33ea11d385b82de0188fee73dd655.tar.gz cgit-905dbaef5aa33ea11d385b82de0188fee73dd655.tar.bz2 |
Merge branch 'lh/about'
* lh/about:
Add 'about site' and 'about repo' pages
Prepare for 'about site' page / add 'root-readme' option to cgitrc
Make it possible for a single cmd to work both with and without a repo
Re-enable 'index-info' and add support for 'root-desc' in cgitrc
Move included header-file out of repolist table
Prepare for 'about repo' page
-rw-r--r-- | cgit.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,53 +1,57 @@ /* cgit.c: cgi for the git scm * * Copyright (C) 2006 Lars Hjemli * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" #include "cache.h" #include "cmd.h" #include "configfile.h" #include "html.h" #include "ui-shared.h" const char *cgit_version = CGIT_VERSION; void config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) ctx.cfg.root_title = xstrdup(value); + else if (!strcmp(name, "root-desc")) + ctx.cfg.root_desc = xstrdup(value); + else if (!strcmp(name, "root-readme")) + ctx.cfg.root_readme = 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); @@ -130,64 +134,65 @@ static void querystring_cb(const char *name, const char *value) } 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); } } static void 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.root_desc = "a fast webinterface for the git dscm"; ctx->cfg.script_name = CGIT_SCRIPT_NAME; ctx->page.mimetype = "text/html"; ctx->page.charset = PAGE_ENCODING; ctx->page.filename = NULL; } static int cgit_prepare_cache(struct cacheitem *item) { if (!ctx.repo && ctx.qry.repo) { ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); cgit_print_http_headers(&ctx); cgit_print_docstart(&ctx); cgit_print_pageheader(&ctx); cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); cgit_print_docend(); return 0; } if (!ctx.repo) { item->name = xstrdup(fmt("%s/index.%s.html", ctx.cfg.cache_root, cache_safe_filename(ctx.qry.raw))); item->ttl = ctx.cfg.cache_root_ttl; return 1; } if (!ctx.qry.page) { item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, cache_safe_filename(ctx.repo->url), cache_safe_filename(ctx.qry.raw))); item->ttl = ctx.cfg.cache_repo_ttl; @@ -275,65 +280,74 @@ static int prepare_repo_cmd(struct cgit_context *ctx) return 1; } if (get_sha1(ctx->qry.head, sha1)) { tmp = xstrdup(ctx->qry.head); ctx->qry.head = ctx->repo->defbranch; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); cgit_print_error(fmt("Invalid branch: %s", tmp)); cgit_print_docend(); return 1; } return 0; } static void process_request(struct cgit_context *ctx) { struct cgit_cmd *cmd; cmd = cgit_get_cmd(ctx); if (!cmd) { ctx->page.title = "cgit error"; ctx->repo = NULL; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); cgit_print_error("Invalid request"); cgit_print_docend(); return; } - if (cmd->want_repo && prepare_repo_cmd(ctx)) + if (cmd->want_repo && !ctx->repo) { + cgit_print_http_headers(ctx); + cgit_print_docstart(ctx); + cgit_print_pageheader(ctx); + cgit_print_error(fmt("No repository selected")); + cgit_print_docend(); + return; + } + + if (ctx->repo && prepare_repo_cmd(ctx)) return; if (cmd->want_layout) { cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); } cmd->fn(ctx); if (cmd->want_layout) cgit_print_docend(); } static long ttl_seconds(long ttl) { if (ttl<0) return 60 * 60 * 24 * 365; else return ttl * 60; } static void cgit_fill_cache(struct cacheitem *item, int use_cache) { int stdout2; if (use_cache) { stdout2 = chk_positive(dup(STDOUT_FILENO), "Preserving STDOUT"); chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); } |