diff options
author | Lars Hjemli <hjemli@gmail.com> | 2008-04-09 04:29:21 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-04-09 04:29:21 (JST) |
commit | 23296ad648c0e2a9e3cf40a3de322b10ad25cce3 (patch) | |
tree | 136493d8228b0ff4971feb06b0e8aee296367b00 | |
parent | e2a44cf0923398396b7a321d5ce894ad3bf6f580 (diff) | |
parent | c6f747649ace1a92ed5dfaae9cc1ea3affe0bf51 (diff) | |
download | cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.zip cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.tar.gz |
Merge branch 'lh/cleanup'
* lh/cleanup: (21 commits)
Reset ctx.repo to NULL when the config parser is finished
Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
Move function for configfile parsing into configfile.[ch]
Add cache.h
Remove global and obsolete cgit_cmd
Makefile: copy the QUIET constructs from the Makefile in git.git
Move cgit_version from shared.c to cgit.c
Makefile: autobuild dependency rules
Initial Makefile cleanup
Move non-generic functions from shared.c to cgit.c
Add ui-shared.h
Add separate header-files for each page/view
Refactor snapshot support
Add command dispatcher
Remove obsolete cacheitem parameter to ui-functions
Add struct cgit_page to cgit_context
Introduce html.h
Improve initialization of git directory
Move cgit_repo into cgit_context
Add all config variables into struct cgit_context
...
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 75 | ||||
-rw-r--r-- | cache.c | 21 | ||||
-rw-r--r-- | cache.h | 23 | ||||
-rw-r--r-- | cgit.c | 391 | ||||
-rw-r--r-- | cgit.h | 237 | ||||
-rw-r--r-- | cmd.c | 112 | ||||
-rw-r--r-- | cmd.h | 15 | ||||
-rw-r--r-- | configfile.c | 87 | ||||
-rw-r--r-- | configfile.h | 8 | ||||
-rw-r--r-- | html.c | 95 | ||||
-rw-r--r-- | html.h | 20 | ||||
-rw-r--r-- | parsing.c | 146 | ||||
-rw-r--r-- | shared.c | 257 | ||||
-rw-r--r-- | ui-blob.c | 16 | ||||
-rw-r--r-- | ui-blob.h | 6 | ||||
-rw-r--r-- | ui-commit.c | 26 | ||||
-rw-r--r-- | ui-commit.h | 6 | ||||
-rw-r--r-- | ui-diff.c | 9 | ||||
-rw-r--r-- | ui-diff.h | 7 | ||||
-rw-r--r-- | ui-log.c | 32 | ||||
-rw-r--r-- | ui-log.h | 7 | ||||
-rw-r--r-- | ui-patch.c | 10 | ||||
-rw-r--r-- | ui-patch.h | 6 | ||||
-rw-r--r-- | ui-refs.c | 175 | ||||
-rw-r--r-- | ui-refs.h | 8 | ||||
-rw-r--r-- | ui-repolist.c | 54 | ||||
-rw-r--r-- | ui-repolist.h | 6 | ||||
-rw-r--r-- | ui-shared.c | 237 | ||||
-rw-r--r-- | ui-shared.h | 36 | ||||
-rw-r--r-- | ui-snapshot.c | 123 | ||||
-rw-r--r-- | ui-snapshot.h | 8 | ||||
-rw-r--r-- | ui-summary.c | 189 | ||||
-rw-r--r-- | ui-summary.h | 6 | ||||
-rw-r--r-- | ui-tag.c | 3 | ||||
-rw-r--r-- | ui-tag.h | 6 | ||||
-rw-r--r-- | ui-tree.c | 26 | ||||
-rw-r--r-- | ui-tree.h | 6 |
38 files changed, 1379 insertions, 1117 deletions
@@ -3,3 +3,4 @@ cgit | |||
3 | cgit.conf | 3 | cgit.conf |
4 | VERSION | 4 | VERSION |
5 | *.o | 5 | *.o |
6 | *.d | ||
@@ -12,13 +12,62 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | |||
12 | # | 12 | # |
13 | -include cgit.conf | 13 | -include cgit.conf |
14 | 14 | ||
15 | # | ||
16 | # Define a way to invoke make in subdirs quietly, shamelessly ripped | ||
17 | # from git.git | ||
18 | # | ||
19 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | ||
20 | QUIET_SUBDIR1 = | ||
15 | 21 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 22 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 23 | PRINT_DIR = --no-print-directory |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 24 | else # "make -w" |
19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o | 25 | NO_SUBDIR = : |
26 | endif | ||
27 | |||
28 | ifndef V | ||
29 | QUIET_CC = @echo ' ' CC $@; | ||
30 | QUIET_MM = @echo ' ' MM $@; | ||
31 | QUIET_SUBDIR0 = +@subdir= | ||
32 | QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ | ||
33 | $(MAKE) $(PRINT_DIR) -C $$subdir | ||
34 | endif | ||
35 | |||
36 | # | ||
37 | # Define a pattern rule for automatic dependency building | ||
38 | # | ||
39 | %.d: %.c | ||
40 | $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ | ||
41 | |||
42 | # | ||
43 | # Define a pattern rule for silent object building | ||
44 | # | ||
45 | %.o: %.c | ||
46 | $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< | ||
20 | 47 | ||
21 | 48 | ||
49 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | ||
50 | OBJECTS = | ||
51 | OBJECTS += cache.o | ||
52 | OBJECTS += cgit.o | ||
53 | OBJECTS += cmd.o | ||
54 | OBJECTS += configfile.o | ||
55 | OBJECTS += html.o | ||
56 | OBJECTS += parsing.o | ||
57 | OBJECTS += shared.o | ||
58 | OBJECTS += ui-blob.o | ||
59 | OBJECTS += ui-commit.o | ||
60 | OBJECTS += ui-diff.o | ||
61 | OBJECTS += ui-log.o | ||
62 | OBJECTS += ui-patch.o | ||
63 | OBJECTS += ui-refs.o | ||
64 | OBJECTS += ui-repolist.o | ||
65 | OBJECTS += ui-shared.o | ||
66 | OBJECTS += ui-snapshot.o | ||
67 | OBJECTS += ui-summary.o | ||
68 | OBJECTS += ui-tag.o | ||
69 | OBJECTS += ui-tree.o | ||
70 | |||
22 | ifdef NEEDS_LIBICONV | 71 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | 72 | EXTLIBS += -liconv |
24 | endif | 73 | endif |
@@ -41,21 +90,25 @@ CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | |||
41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 90 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
42 | 91 | ||
43 | 92 | ||
44 | cgit: cgit.c $(OBJECTS) | 93 | cgit: $(OBJECTS) |
45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 94 | $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) |
95 | |||
96 | $(OBJECTS): git/xdiff/lib.a git/libgit.a | ||
97 | |||
98 | cgit.o: VERSION | ||
46 | 99 | ||
47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 100 | -include $(OBJECTS:.o=.d) |
48 | 101 | ||
49 | git/xdiff/lib.a: | git | 102 | git/xdiff/lib.a: | git |
50 | 103 | ||
51 | git/libgit.a: | git | 104 | git/libgit.a: | git |
52 | 105 | ||
53 | git: | 106 | git: |
54 | cd git && $(MAKE) xdiff/lib.a | 107 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a |
55 | cd git && $(MAKE) libgit.a | 108 | $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a |
56 | 109 | ||
57 | test: all | 110 | test: all |
58 | $(MAKE) -C tests | 111 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
59 | 112 | ||
60 | install: all | 113 | install: all |
61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 114 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
@@ -69,7 +122,7 @@ uninstall: | |||
69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 122 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
70 | 123 | ||
71 | clean: | 124 | clean: |
72 | rm -f cgit VERSION *.o | 125 | rm -f cgit VERSION *.o *.d |
73 | cd git && $(MAKE) clean | 126 | cd git && $(MAKE) clean |
74 | 127 | ||
75 | distclean: clean | 128 | distclean: clean |
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cache.h" | ||
10 | 11 | ||
11 | const int NOLOCK = -1; | 12 | const int NOLOCK = -1; |
12 | 13 | ||
@@ -44,23 +45,23 @@ int cache_create_dirs() | |||
44 | { | 45 | { |
45 | char *path; | 46 | char *path; |
46 | 47 | ||
47 | path = fmt("%s", cgit_cache_root); | 48 | path = fmt("%s", ctx.cfg.cache_root); |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 49 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | return 0; | 50 | return 0; |
50 | 51 | ||
51 | if (!cgit_repo) | 52 | if (!ctx.repo) |
52 | return 0; | 53 | return 0; |
53 | 54 | ||
54 | path = fmt("%s/%s", cgit_cache_root, | 55 | path = fmt("%s/%s", ctx.cfg.cache_root, |
55 | cache_safe_filename(cgit_repo->url)); | 56 | cache_safe_filename(ctx.repo->url)); |
56 | 57 | ||
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 58 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | return 0; | 59 | return 0; |
59 | 60 | ||
60 | if (cgit_query_page) { | 61 | if (ctx.qry.page) { |
61 | path = fmt("%s/%s/%s", cgit_cache_root, | 62 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
62 | cache_safe_filename(cgit_repo->url), | 63 | cache_safe_filename(ctx.repo->url), |
63 | cgit_query_page); | 64 | ctx.qry.page); |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 65 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
65 | return 0; | 66 | return 0; |
66 | } | 67 | } |
@@ -74,7 +75,7 @@ int cache_refill_overdue(const char *lockfile) | |||
74 | if (stat(lockfile, &st)) | 75 | if (stat(lockfile, &st)) |
75 | return 0; | 76 | return 0; |
76 | else | 77 | else |
77 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); | 78 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
78 | } | 79 | } |
79 | 80 | ||
80 | int cache_lock(struct cacheitem *item) | 81 | int cache_lock(struct cacheitem *item) |
@@ -83,7 +84,7 @@ int cache_lock(struct cacheitem *item) | |||
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); | 84 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | 85 | ||
85 | top: | 86 | top: |
86 | if (++i > cgit_max_lock_attempts) | 87 | if (++i > ctx.cfg.max_lock_attempts) |
87 | die("cache_lock: unable to lock %s: %s", | 88 | die("cache_lock: unable to lock %s: %s", |
88 | item->name, strerror(errno)); | 89 | item->name, strerror(errno)); |
89 | 90 | ||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * Since git has it's own cache.h which we include, | ||
3 | * lets test on CGIT_CACHE_H to avoid confusion | ||
4 | */ | ||
5 | |||
6 | #ifndef CGIT_CACHE_H | ||
7 | #define CGIT_CACHE_H | ||
8 | |||
9 | struct cacheitem { | ||
10 | char *name; | ||
11 | struct stat st; | ||
12 | int ttl; | ||
13 | int fd; | ||
14 | }; | ||
15 | |||
16 | extern char *cache_safe_filename(const char *unsafe); | ||
17 | extern int cache_lock(struct cacheitem *item); | ||
18 | extern int cache_unlock(struct cacheitem *item); | ||
19 | extern int cache_cancel_lock(struct cacheitem *item); | ||
20 | extern int cache_exist(struct cacheitem *item); | ||
21 | extern int cache_expired(struct cacheitem *item); | ||
22 | |||
23 | #endif /* CGIT_CACHE_H */ | ||
@@ -7,40 +7,199 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cache.h" | ||
11 | #include "cmd.h" | ||
12 | #include "configfile.h" | ||
13 | #include "html.h" | ||
14 | #include "ui-shared.h" | ||
15 | |||
16 | const char *cgit_version = CGIT_VERSION; | ||
17 | |||
18 | void config_cb(const char *name, const char *value) | ||
19 | { | ||
20 | if (!strcmp(name, "root-title")) | ||
21 | ctx.cfg.root_title = xstrdup(value); | ||
22 | else if (!strcmp(name, "css")) | ||
23 | ctx.cfg.css = xstrdup(value); | ||
24 | else if (!strcmp(name, "logo")) | ||
25 | ctx.cfg.logo = xstrdup(value); | ||
26 | else if (!strcmp(name, "index-header")) | ||
27 | ctx.cfg.index_header = xstrdup(value); | ||
28 | else if (!strcmp(name, "index-info")) | ||
29 | ctx.cfg.index_info = xstrdup(value); | ||
30 | else if (!strcmp(name, "logo-link")) | ||
31 | ctx.cfg.logo_link = xstrdup(value); | ||
32 | else if (!strcmp(name, "module-link")) | ||
33 | ctx.cfg.module_link = xstrdup(value); | ||
34 | else if (!strcmp(name, "virtual-root")) { | ||
35 | ctx.cfg.virtual_root = trim_end(value, '/'); | ||
36 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | ||
37 | ctx.cfg.virtual_root = ""; | ||
38 | } else if (!strcmp(name, "nocache")) | ||
39 | ctx.cfg.nocache = atoi(value); | ||
40 | else if (!strcmp(name, "snapshots")) | ||
41 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | ||
42 | else if (!strcmp(name, "enable-index-links")) | ||
43 | ctx.cfg.enable_index_links = atoi(value); | ||
44 | else if (!strcmp(name, "enable-log-filecount")) | ||
45 | ctx.cfg.enable_log_filecount = atoi(value); | ||
46 | else if (!strcmp(name, "enable-log-linecount")) | ||
47 | ctx.cfg.enable_log_linecount = atoi(value); | ||
48 | else if (!strcmp(name, "cache-root")) | ||
49 | ctx.cfg.cache_root = xstrdup(value); | ||
50 | else if (!strcmp(name, "cache-root-ttl")) | ||
51 | ctx.cfg.cache_root_ttl = atoi(value); | ||
52 | else if (!strcmp(name, "cache-repo-ttl")) | ||
53 | ctx.cfg.cache_repo_ttl = atoi(value); | ||
54 | else if (!strcmp(name, "cache-static-ttl")) | ||
55 | ctx.cfg.cache_static_ttl = atoi(value); | ||
56 | else if (!strcmp(name, "cache-dynamic-ttl")) | ||
57 | ctx.cfg.cache_dynamic_ttl = atoi(value); | ||
58 | else if (!strcmp(name, "max-message-length")) | ||
59 | ctx.cfg.max_msg_len = atoi(value); | ||
60 | else if (!strcmp(name, "max-repodesc-length")) | ||
61 | ctx.cfg.max_repodesc_len = atoi(value); | ||
62 | else if (!strcmp(name, "max-commit-count")) | ||
63 | ctx.cfg.max_commit_count = atoi(value); | ||
64 | else if (!strcmp(name, "summary-log")) | ||
65 | ctx.cfg.summary_log = atoi(value); | ||
66 | else if (!strcmp(name, "summary-branches")) | ||
67 | ctx.cfg.summary_branches = atoi(value); | ||
68 | else if (!strcmp(name, "summary-tags")) | ||
69 | ctx.cfg.summary_tags = atoi(value); | ||
70 | else if (!strcmp(name, "agefile")) | ||
71 | ctx.cfg.agefile = xstrdup(value); | ||
72 | else if (!strcmp(name, "renamelimit")) | ||
73 | ctx.cfg.renamelimit = atoi(value); | ||
74 | else if (!strcmp(name, "robots")) | ||
75 | ctx.cfg.robots = xstrdup(value); | ||
76 | else if (!strcmp(name, "clone-prefix")) | ||
77 | ctx.cfg.clone_prefix = xstrdup(value); | ||
78 | else if (!strcmp(name, "repo.group")) | ||
79 | ctx.cfg.repo_group = xstrdup(value); | ||
80 | else if (!strcmp(name, "repo.url")) | ||
81 | ctx.repo = cgit_add_repo(value); | ||
82 | else if (!strcmp(name, "repo.name")) | ||
83 | ctx.repo->name = xstrdup(value); | ||
84 | else if (ctx.repo && !strcmp(name, "repo.path")) | ||
85 | ctx.repo->path = trim_end(value, '/'); | ||
86 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) | ||
87 | ctx.repo->clone_url = xstrdup(value); | ||
88 | else if (ctx.repo && !strcmp(name, "repo.desc")) | ||
89 | ctx.repo->desc = xstrdup(value); | ||
90 | else if (ctx.repo && !strcmp(name, "repo.owner")) | ||
91 | ctx.repo->owner = xstrdup(value); | ||
92 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) | ||
93 | ctx.repo->defbranch = xstrdup(value); | ||
94 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | ||
95 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | ||
96 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | ||
97 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | ||
98 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | ||
99 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | ||
100 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | ||
101 | ctx.repo->module_link= xstrdup(value); | ||
102 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | ||
103 | if (*value == '/') | ||
104 | ctx.repo->readme = xstrdup(value); | ||
105 | else | ||
106 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | ||
107 | } else if (!strcmp(name, "include")) | ||
108 | parse_configfile(value, config_cb); | ||
109 | } | ||
110 | |||
111 | static void querystring_cb(const char *name, const char *value) | ||
112 | { | ||
113 | if (!strcmp(name,"r")) { | ||
114 | ctx.qry.repo = xstrdup(value); | ||
115 | ctx.repo = cgit_get_repoinfo(value); | ||
116 | } else if (!strcmp(name, "p")) { | ||
117 | ctx.qry.page = xstrdup(value); | ||
118 | } else if (!strcmp(name, "url")) { | ||
119 | cgit_parse_url(value); | ||
120 | } else if (!strcmp(name, "qt")) { | ||
121 | ctx.qry.grep = xstrdup(value); | ||
122 | } else if (!strcmp(name, "q")) { | ||
123 | ctx.qry.search = xstrdup(value); | ||
124 | } else if (!strcmp(name, "h")) { | ||
125 | ctx.qry.head = xstrdup(value); | ||
126 | ctx.qry.has_symref = 1; | ||
127 | } else if (!strcmp(name, "id")) { | ||
128 | ctx.qry.sha1 = xstrdup(value); | ||
129 | ctx.qry.has_sha1 = 1; | ||
130 | } else if (!strcmp(name, "id2")) { | ||
131 | ctx.qry.sha2 = xstrdup(value); | ||
132 | ctx.qry.has_sha1 = 1; | ||
133 | } else if (!strcmp(name, "ofs")) { | ||
134 | ctx.qry.ofs = atoi(value); | ||
135 | } else if (!strcmp(name, "path")) { | ||
136 | ctx.qry.path = trim_end(value, '/'); | ||
137 | } else if (!strcmp(name, "name")) { | ||
138 | ctx.qry.name = xstrdup(value); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | static void prepare_context(struct cgit_context *ctx) | ||
143 | { | ||
144 | memset(ctx, 0, sizeof(ctx)); | ||
145 | ctx->cfg.agefile = "info/web/last-modified"; | ||
146 | ctx->cfg.cache_dynamic_ttl = 5; | ||
147 | ctx->cfg.cache_max_create_time = 5; | ||
148 | ctx->cfg.cache_repo_ttl = 5; | ||
149 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | ||
150 | ctx->cfg.cache_root_ttl = 5; | ||
151 | ctx->cfg.cache_static_ttl = -1; | ||
152 | ctx->cfg.css = "/cgit.css"; | ||
153 | ctx->cfg.logo = "/git-logo.png"; | ||
154 | ctx->cfg.max_commit_count = 50; | ||
155 | ctx->cfg.max_lock_attempts = 5; | ||
156 | ctx->cfg.max_msg_len = 60; | ||
157 | ctx->cfg.max_repodesc_len = 60; | ||
158 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | ||
159 | ctx->cfg.renamelimit = -1; | ||
160 | ctx->cfg.robots = "index, nofollow"; | ||
161 | ctx->cfg.root_title = "Git repository browser"; | ||
162 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | ||
163 | ctx->page.mimetype = "text/html"; | ||
164 | ctx->page.charset = PAGE_ENCODING; | ||
165 | ctx->page.filename = NULL; | ||
166 | } | ||
10 | 167 | ||
11 | static int cgit_prepare_cache(struct cacheitem *item) | 168 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 169 | { |
13 | if (!cgit_repo && cgit_query_repo) { | 170 | if (!ctx.repo && ctx.qry.repo) { |
14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 171 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
15 | cgit_print_docstart(title, item); | 172 | "Bad request"); |
16 | cgit_print_pageheader(title, 0); | 173 | cgit_print_http_headers(&ctx); |
17 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 174 | cgit_print_docstart(&ctx); |
175 | cgit_print_pageheader(&ctx); | ||
176 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | ||
18 | cgit_print_docend(); | 177 | cgit_print_docend(); |
19 | return 0; | 178 | return 0; |
20 | } | 179 | } |
21 | 180 | ||
22 | if (!cgit_repo) { | 181 | if (!ctx.repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 182 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
24 | item->ttl = cgit_cache_root_ttl; | 183 | item->ttl = ctx.cfg.cache_root_ttl; |
25 | return 1; | 184 | return 1; |
26 | } | 185 | } |
27 | 186 | ||
28 | if (!cgit_cmd) { | 187 | if (!ctx.qry.page) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 188 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
30 | cache_safe_filename(cgit_repo->url), | 189 | cache_safe_filename(ctx.repo->url), |
31 | cache_safe_filename(cgit_querystring))); | 190 | cache_safe_filename(ctx.qry.raw))); |
32 | item->ttl = cgit_cache_repo_ttl; | 191 | item->ttl = ctx.cfg.cache_repo_ttl; |
33 | } else { | 192 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 193 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
35 | cache_safe_filename(cgit_repo->url), | 194 | cache_safe_filename(ctx.repo->url), |
36 | cgit_query_page, | 195 | ctx.qry.page, |
37 | cache_safe_filename(cgit_querystring))); | 196 | cache_safe_filename(ctx.qry.raw))); |
38 | if (cgit_query_has_symref) | 197 | if (ctx.qry.has_symref) |
39 | item->ttl = cgit_cache_dynamic_ttl; | 198 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
40 | else if (cgit_query_has_sha1) | 199 | else if (ctx.qry.has_sha1) |
41 | item->ttl = cgit_cache_static_ttl; | 200 | item->ttl = ctx.cfg.cache_static_ttl; |
42 | else | 201 | else |
43 | item->ttl = cgit_cache_repo_ttl; | 202 |