aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/cgit.c b/cgit.c
index 34e590e..c86d290 100644
--- a/cgit.c
+++ b/cgit.c
@@ -8,9 +8,6 @@
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11const char cgit_version[] = CGIT_VERSION;
12
13
14static int cgit_prepare_cache(struct cacheitem *item) 11static int cgit_prepare_cache(struct cacheitem *item)
15{ 12{
16 if (!cgit_repo && cgit_query_repo) { 13 if (!cgit_repo && cgit_query_repo) {
@@ -29,13 +26,15 @@ static int cgit_prepare_cache(struct cacheitem *item)
29 } 26 }
30 27
31 if (!cgit_cmd) { 28 if (!cgit_cmd) {
32 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, 29 item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root,
33 cache_safe_filename(cgit_repo->url))); 30 cache_safe_filename(cgit_repo->url),
31 cache_safe_filename(cgit_querystring)));
34 item->ttl = cgit_cache_repo_ttl; 32 item->ttl = cgit_cache_repo_ttl;
35 } else { 33 } else {
36 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, 34 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
37 cache_safe_filename(cgit_repo->url), cgit_query_page, 35 cache_safe_filename(cgit_repo->url),
38 cache_safe_filename(cgit_querystring))); 36 cgit_query_page,
37 cache_safe_filename(cgit_querystring)));
39 if (cgit_query_has_symref) 38 if (cgit_query_has_symref)
40 item->ttl = cgit_cache_dynamic_ttl; 39 item->ttl = cgit_cache_dynamic_ttl;
41 else if (cgit_query_has_sha1) 40 else if (cgit_query_has_sha1)
@@ -69,8 +68,10 @@ static void cgit_print_repo_page(struct cacheitem *item)
69 setenv("GIT_DIR", cgit_repo->path, 1); 68 setenv("GIT_DIR", cgit_repo->path, 1);
70 69
71 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { 70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
72 cgit_print_snapshot(item, cgit_query_sha1, "zip", 71 cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1,
73 cgit_repo->url, cgit_query_name); 72 cgit_repobasename(cgit_repo->url),
73 cgit_query_path,
74 cgit_repo->snapshots );
74 return; 75 return;
75 } 76 }
76 77
@@ -92,22 +93,21 @@ static void cgit_print_repo_page(struct cacheitem *item)
92 93
93 switch(cgit_cmd) { 94 switch(cgit_cmd) {
94 case CMD_LOG: 95 case CMD_LOG:
95 cgit_print_log(cgit_query_head, cgit_query_ofs, 96 cgit_print_log(cgit_query_sha1, cgit_query_ofs,
96 cgit_max_commit_count, cgit_query_search, 97 cgit_max_commit_count, cgit_query_search,
97 cgit_query_path, 1); 98 cgit_query_path, 1);
98 break; 99 break;
99 case CMD_TREE: 100 case CMD_TREE:
100 cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); 101 cgit_print_tree(cgit_query_sha1, cgit_query_path);
101 break; 102 break;
102 case CMD_COMMIT: 103 case CMD_COMMIT:
103 cgit_print_commit(cgit_query_head); 104 cgit_print_commit(cgit_query_sha1);
104 break; 105 break;
105 case CMD_VIEW: 106 case CMD_TAG:
106 cgit_print_view(cgit_query_sha1, cgit_query_path); 107 cgit_print_tag(cgit_query_sha1);
107 break; 108 break;
108 case CMD_DIFF: 109 case CMD_DIFF:
109 cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, 110 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
110 cgit_query_path);
111 break; 111 break;
112 default: 112 default:
113 cgit_print_error("Invalid request"); 113 cgit_print_error("Invalid request");
@@ -227,6 +227,7 @@ static void cgit_parse_args(int argc, const char **argv)
227int main(int argc, const char **argv) 227int main(int argc, const char **argv)
228{ 228{
229 struct cacheitem item; 229 struct cacheitem item;
230 const char *cgit_config_env = getenv("CGIT_CONFIG");
230 231
231 htmlfd = STDOUT_FILENO; 232 htmlfd = STDOUT_FILENO;
232 item.st.st_mtime = time(NULL); 233 item.st.st_mtime = time(NULL);
@@ -234,7 +235,8 @@ int main(int argc, const char **argv)
234 cgit_repolist.count = 0; 235 cgit_repolist.count = 0;
235 cgit_repolist.repos = NULL; 236 cgit_repolist.repos = NULL;
236 237
237 cgit_read_config(CGIT_CONFIG, cgit_global_config_cb); 238 cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
239 cgit_global_config_cb);
238 cgit_repo = NULL; 240 cgit_repo = NULL;
239 if (getenv("SCRIPT_NAME")) 241 if (getenv("SCRIPT_NAME"))
240 cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); 242 cgit_script_name = xstrdup(getenv("SCRIPT_NAME"));