summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c64
1 files changed, 49 insertions, 15 deletions
diff --git a/cgit.c b/cgit.c
index 9535abc..0fa203c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -12,3 +12,18 @@ const char cgit_version[] = CGIT_VERSION;
12 12
13static void cgit_prepare_cache(struct cacheitem *item) 13
14static struct repoinfo *cgit_get_repoinfo(char *url)
15{
16 int i;
17 struct repoinfo *repo;
18
19 for (i=0; i<cgit_repolist.count; i++) {
20 repo = &cgit_repolist.repos[i];
21 if (!strcmp(repo->url, url))
22 return repo;
23 }
24 return NULL;
25}
26
27
28static int cgit_prepare_cache(struct cacheitem *item)
14{ 29{
@@ -17,5 +32,17 @@ static void cgit_prepare_cache(struct cacheitem *item)
17 item->ttl = cgit_cache_root_ttl; 32 item->ttl = cgit_cache_root_ttl;
18 } else if (!cgit_query_page) { 33 return 1;
34 }
35 cgit_repo = cgit_get_repoinfo(cgit_query_repo);
36 if (!cgit_repo) {
37 char *title = fmt("%s - %s", cgit_root_title, "Bad request");
38 cgit_print_docstart(title, item);
39 cgit_print_pageheader(title, 0);
40 cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo));
41 cgit_print_docend();
42 return 0;
43 }
44
45 if (!cgit_query_page) {
19 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, 46 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root,
20 cgit_query_repo)); 47 cgit_repo->url));
21 item->ttl = cgit_cache_repo_ttl; 48 item->ttl = cgit_cache_repo_ttl;
@@ -23,3 +50,3 @@ static void cgit_prepare_cache(struct cacheitem *item)
23 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, 50 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
24 cgit_query_repo, cgit_query_page, 51 cgit_repo->url, cgit_query_page,
25 cache_safe_filename(cgit_querystring))); 52 cache_safe_filename(cgit_querystring)));
@@ -32,2 +59,3 @@ static void cgit_prepare_cache(struct cacheitem *item)
32 } 59 }
60 return 1;
33} 61}
@@ -36,5 +64,7 @@ static void cgit_print_repo_page(struct cacheitem *item)
36{ 64{
37 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || 65 char *title;
38 cgit_read_config("info/cgit", cgit_repo_config_cb)) { 66 int show_search;
39 char *title = fmt("%s - %s", cgit_root_title, "Bad request"); 67
68 if (chdir(cgit_repo->path)) {
69 title = fmt("%s - %s", cgit_root_title, "Bad request");
40 cgit_print_docstart(title, item); 70 cgit_print_docstart(title, item);
@@ -46,5 +76,6 @@ static void cgit_print_repo_page(struct cacheitem *item)
46 } 76 }
47 setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); 77
48 char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); 78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
49 int show_search = 0; 79 show_search = 0;
80 setenv("GIT_DIR", cgit_repo->path, 1);
50 if (cgit_query_page && !strcmp(cgit_query_page, "log")) 81 if (cgit_query_page && !strcmp(cgit_query_page, "log"))
@@ -133,5 +164,2 @@ static void cgit_parse_args(int argc, const char **argv)
133 for (i = 1; i < argc; i++) { 164 for (i = 1; i < argc; i++) {
134 if (!strncmp(argv[i], "--root=", 7)) {
135 cgit_root = xstrdup(argv[i]+7);
136 }
137 if (!strncmp(argv[i], "--cache=", 8)) { 165 if (!strncmp(argv[i], "--cache=", 8)) {
@@ -169,2 +197,8 @@ int main(int argc, const char **argv)
169 197
198 htmlfd = STDOUT_FILENO;
199 item.st.st_mtime = time(NULL);
200 cgit_repolist.length = 0;
201 cgit_repolist.count = 0;
202 cgit_repolist.repos = NULL;
203
170 cgit_read_config("/etc/cgitrc", cgit_global_config_cb); 204 cgit_read_config("/etc/cgitrc", cgit_global_config_cb);
@@ -174,4 +208,4 @@ int main(int argc, const char **argv)
174 cgit_parse_query(cgit_querystring, cgit_querystring_cb); 208 cgit_parse_query(cgit_querystring, cgit_querystring_cb);
175 209 if (!cgit_prepare_cache(&item))
176 cgit_prepare_cache(&item); 210 return 0;
177 if (cgit_nocache) { 211 if (cgit_nocache) {