author | Lars Hjemli <hjemli@gmail.com> | 2008-02-16 12:56:09 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-02-16 12:56:09 (UTC) |
commit | d1f3bbe9d22029f45a77bb938c176ccc0c827d46 (patch) (unidiff) | |
tree | 3f1741c012763cbc5485f31377abdd9241fbac6b /cgit.c | |
parent | b228d4ff82a65fdcd4a7364759fe36a0bdda5978 (diff) | |
download | cgit-d1f3bbe9d22029f45a77bb938c176ccc0c827d46.zip cgit-d1f3bbe9d22029f45a77bb938c176ccc0c827d46.tar.gz cgit-d1f3bbe9d22029f45a77bb938c176ccc0c827d46.tar.bz2 |
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 <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -11,5 +11,5 @@ | |||
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); |
@@ -20,5 +20,5 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
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; |
@@ -28,10 +28,10 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
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))); |
@@ -65,5 +65,5 @@ int find_current_ref(const char *refname, const unsigned char *sha1, | |||
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; |
@@ -85,5 +85,5 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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); |
@@ -95,11 +95,11 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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 | ||
@@ -114,5 +114,5 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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); |
@@ -122,9 +122,9 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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 | } |
@@ -193,5 +193,5 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) | |||
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 |
@@ -301,5 +301,4 @@ int main(int argc, const char **argv) | |||
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")); |