diff options
Diffstat (limited to 'cgit.c')
| -rw-r--r-- | cgit.c | 31 |
1 files changed, 15 insertions, 16 deletions
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | static int cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
| 12 | { | 12 | { |
| 13 | if (!cgit_repo && ctx.qry.repo) { | 13 | if (!ctx.repo && ctx.qry.repo) { |
| 14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
| 15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
| 16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
| @@ -19,7 +19,7 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
| 19 | return 0; | 19 | return 0; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | if (!cgit_repo) { | 22 | if (!ctx.repo) { |
| 23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
| 24 | item->ttl = ctx.cfg.cache_root_ttl; | 24 | item->ttl = ctx.cfg.cache_root_ttl; |
| 25 | return 1; | 25 | return 1; |
| @@ -27,12 +27,12 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
| 27 | 27 | ||
| 28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
| 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
| 30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(ctx.repo->url), |
| 31 | cache_safe_filename(ctx.qry.raw))); | 31 | cache_safe_filename(ctx.qry.raw))); |
| 32 | item->ttl = ctx.cfg.cache_repo_ttl; | 32 | item->ttl = ctx.cfg.cache_repo_ttl; |
| 33 | } else { | 33 | } else { |
| 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
| 35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(ctx.repo->url), |
| 36 | ctx.qry.page, | 36 | ctx.qry.page, |
| 37 | cache_safe_filename(ctx.qry.raw))); | 37 | cache_safe_filename(ctx.qry.raw))); |
| 38 | if (ctx.qry.has_symref) | 38 | if (ctx.qry.has_symref) |
| @@ -64,7 +64,7 @@ int find_current_ref(const char *refname, const unsigned char *sha1, | |||
| 64 | return info->match; | 64 | return info->match; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | char *find_default_branch(struct repoinfo *repo) | 67 | char *find_default_branch(struct cgit_repo *repo) |
| 68 | { | 68 | { |
| 69 | struct refmatch info; | 69 | struct refmatch info; |
| 70 | 70 | ||
| @@ -84,7 +84,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 84 | int show_search; | 84 | int show_search; |
| 85 | unsigned char sha1[20]; | 85 | unsigned char sha1[20]; |
| 86 | 86 | ||
| 87 | if (chdir(cgit_repo->path)) { | 87 | if (chdir(ctx.repo->path)) { |
| 88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
| 89 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
| 90 | cgit_print_pageheader(title, 0); | 90 | cgit_print_pageheader(title, 0); |
| @@ -94,13 +94,13 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 94 | return; | 94 | return; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 97 | title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); |
| 98 | show_search = 0; | 98 | show_search = 0; |
| 99 | setenv("GIT_DIR", cgit_repo->path, 1); | 99 | setenv("GIT_DIR", ctx.repo->path, 1); |
| 100 | 100 | ||
| 101 | if (!ctx.qry.head) { | 101 | if (!ctx.qry.head) { |
| 102 | ctx.qry.head = xstrdup(find_default_branch(cgit_repo)); | 102 | ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); |
| 103 | cgit_repo->defbranch = ctx.qry.head; | 103 | ctx.repo->defbranch = ctx.qry.head; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if (!ctx.qry.head) { | 106 | if (!ctx.qry.head) { |
| @@ -113,7 +113,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 113 | 113 | ||
| 114 | if (get_sha1(ctx.qry.head, sha1)) { | 114 | if (get_sha1(ctx.qry.head, sha1)) { |
| 115 | tmp = xstrdup(ctx.qry.head); | 115 | tmp = xstrdup(ctx.qry.head); |
| 116 | ctx.qry.head = cgit_repo->defbranch; | 116 | ctx.qry.head = ctx.repo->defbranch; |
| 117 | cgit_print_docstart(title, item); | 117 | cgit_print_docstart(title, item); |
| 118 | cgit_print_pageheader(title, 0); | 118 | cgit_print_pageheader(title, 0); |
| 119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
| @@ -121,11 +121,11 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 121 | return; | 121 | return; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 124 | if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { |
| 125 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, | 125 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, |
| 126 | cgit_repobasename(cgit_repo->url), | 126 | cgit_repobasename(ctx.repo->url), |
| 127 | ctx.qry.path, | 127 | ctx.qry.path, |
| 128 | cgit_repo->snapshots ); | 128 | ctx.repo->snapshots ); |
| 129 | return; | 129 | return; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| @@ -192,7 +192,7 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
| 192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | if (cgit_repo) | 195 | if (ctx.repo) |
| 196 | cgit_print_repo_page(item); | 196 | cgit_print_repo_page(item); |
| 197 | else | 197 | else |
| 198 | cgit_print_repolist(item); | 198 | cgit_print_repolist(item); |
| @@ -300,7 +300,6 @@ int main(int argc, const char **argv) | |||
| 300 | 300 | ||
| 301 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 301 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
| 302 | cgit_global_config_cb); | 302 | cgit_global_config_cb); |
| 303 | cgit_repo = NULL; | ||
| 304 | if (getenv("SCRIPT_NAME")) | 303 | if (getenv("SCRIPT_NAME")) |
| 305 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); | 304 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
| 306 | if (getenv("QUERY_STRING")) | 305 | if (getenv("QUERY_STRING")) |
