summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c11
-rw-r--r--cgit.h2
-rw-r--r--cgitrc.5.txt17
-rw-r--r--ui-plain.c20
4 files changed, 45 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index 2039ab1..4f414c3 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,498 +1,509 @@
1/* cgit.c: cgi for the git scm 1/* cgit.c: cgi for the git scm
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cache.h" 10#include "cache.h"
11#include "cmd.h" 11#include "cmd.h"
12#include "configfile.h" 12#include "configfile.h"
13#include "html.h" 13#include "html.h"
14#include "ui-shared.h" 14#include "ui-shared.h"
15#include "ui-stats.h" 15#include "ui-stats.h"
16#include "scan-tree.h" 16#include "scan-tree.h"
17 17
18const char *cgit_version = CGIT_VERSION; 18const char *cgit_version = CGIT_VERSION;
19 19
20void add_mimetype(const char *name, const char *value)
21{
22 struct string_list_item *item;
23
24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
25 item->util = xstrdup(value);
26}
27
20void config_cb(const char *name, const char *value) 28void config_cb(const char *name, const char *value)
21{ 29{
22 if (!strcmp(name, "root-title")) 30 if (!strcmp(name, "root-title"))
23 ctx.cfg.root_title = xstrdup(value); 31 ctx.cfg.root_title = xstrdup(value);
24 else if (!strcmp(name, "root-desc")) 32 else if (!strcmp(name, "root-desc"))
25 ctx.cfg.root_desc = xstrdup(value); 33 ctx.cfg.root_desc = xstrdup(value);
26 else if (!strcmp(name, "root-readme")) 34 else if (!strcmp(name, "root-readme"))
27 ctx.cfg.root_readme = xstrdup(value); 35 ctx.cfg.root_readme = xstrdup(value);
28 else if (!strcmp(name, "css")) 36 else if (!strcmp(name, "css"))
29 ctx.cfg.css = xstrdup(value); 37 ctx.cfg.css = xstrdup(value);
30 else if (!strcmp(name, "favicon")) 38 else if (!strcmp(name, "favicon"))
31 ctx.cfg.favicon = xstrdup(value); 39 ctx.cfg.favicon = xstrdup(value);
32 else if (!strcmp(name, "footer")) 40 else if (!strcmp(name, "footer"))
33 ctx.cfg.footer = xstrdup(value); 41 ctx.cfg.footer = xstrdup(value);
34 else if (!strcmp(name, "head-include")) 42 else if (!strcmp(name, "head-include"))
35 ctx.cfg.head_include = xstrdup(value); 43 ctx.cfg.head_include = xstrdup(value);
36 else if (!strcmp(name, "header")) 44 else if (!strcmp(name, "header"))
37 ctx.cfg.header = xstrdup(value); 45 ctx.cfg.header = xstrdup(value);
38 else if (!strcmp(name, "logo")) 46 else if (!strcmp(name, "logo"))
39 ctx.cfg.logo = xstrdup(value); 47 ctx.cfg.logo = xstrdup(value);
40 else if (!strcmp(name, "index-header")) 48 else if (!strcmp(name, "index-header"))
41 ctx.cfg.index_header = xstrdup(value); 49 ctx.cfg.index_header = xstrdup(value);
42 else if (!strcmp(name, "index-info")) 50 else if (!strcmp(name, "index-info"))
43 ctx.cfg.index_info = xstrdup(value); 51 ctx.cfg.index_info = xstrdup(value);
44 else if (!strcmp(name, "logo-link")) 52 else if (!strcmp(name, "logo-link"))
45 ctx.cfg.logo_link = xstrdup(value); 53 ctx.cfg.logo_link = xstrdup(value);
46 else if (!strcmp(name, "module-link")) 54 else if (!strcmp(name, "module-link"))
47 ctx.cfg.module_link = xstrdup(value); 55 ctx.cfg.module_link = xstrdup(value);
48 else if (!strcmp(name, "virtual-root")) { 56 else if (!strcmp(name, "virtual-root")) {
49 ctx.cfg.virtual_root = trim_end(value, '/'); 57 ctx.cfg.virtual_root = trim_end(value, '/');
50 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 58 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
51 ctx.cfg.virtual_root = ""; 59 ctx.cfg.virtual_root = "";
52 } else if (!strcmp(name, "nocache")) 60 } else if (!strcmp(name, "nocache"))
53 ctx.cfg.nocache = atoi(value); 61 ctx.cfg.nocache = atoi(value);
54 else if (!strcmp(name, "noheader")) 62 else if (!strcmp(name, "noheader"))
55 ctx.cfg.noheader = atoi(value); 63 ctx.cfg.noheader = atoi(value);
56 else if (!strcmp(name, "snapshots")) 64 else if (!strcmp(name, "snapshots"))
57 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 65 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
58 else if (!strcmp(name, "enable-index-links")) 66 else if (!strcmp(name, "enable-index-links"))
59 ctx.cfg.enable_index_links = atoi(value); 67 ctx.cfg.enable_index_links = atoi(value);
60 else if (!strcmp(name, "enable-log-filecount")) 68 else if (!strcmp(name, "enable-log-filecount"))
61 ctx.cfg.enable_log_filecount = atoi(value); 69 ctx.cfg.enable_log_filecount = atoi(value);
62 else if (!strcmp(name, "enable-log-linecount")) 70 else if (!strcmp(name, "enable-log-linecount"))
63 ctx.cfg.enable_log_linecount = atoi(value); 71 ctx.cfg.enable_log_linecount = atoi(value);
64 else if (!strcmp(name, "max-stats")) 72 else if (!strcmp(name, "max-stats"))
65 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 73 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
66 else if (!strcmp(name, "cache-size")) 74 else if (!strcmp(name, "cache-size"))
67 ctx.cfg.cache_size = atoi(value); 75 ctx.cfg.cache_size = atoi(value);
68 else if (!strcmp(name, "cache-root")) 76 else if (!strcmp(name, "cache-root"))
69 ctx.cfg.cache_root = xstrdup(value); 77 ctx.cfg.cache_root = xstrdup(value);
70 else if (!strcmp(name, "cache-root-ttl")) 78 else if (!strcmp(name, "cache-root-ttl"))
71 ctx.cfg.cache_root_ttl = atoi(value); 79 ctx.cfg.cache_root_ttl = atoi(value);
72 else if (!strcmp(name, "cache-repo-ttl")) 80 else if (!strcmp(name, "cache-repo-ttl"))
73 ctx.cfg.cache_repo_ttl = atoi(value); 81 ctx.cfg.cache_repo_ttl = atoi(value);
74 else if (!strcmp(name, "cache-static-ttl")) 82 else if (!strcmp(name, "cache-static-ttl"))
75 ctx.cfg.cache_static_ttl = atoi(value); 83 ctx.cfg.cache_static_ttl = atoi(value);
76 else if (!strcmp(name, "cache-dynamic-ttl")) 84 else if (!strcmp(name, "cache-dynamic-ttl"))
77 ctx.cfg.cache_dynamic_ttl = atoi(value); 85 ctx.cfg.cache_dynamic_ttl = atoi(value);
78 else if (!strcmp(name, "embedded")) 86 else if (!strcmp(name, "embedded"))
79 ctx.cfg.embedded = atoi(value); 87 ctx.cfg.embedded = atoi(value);
80 else if (!strcmp(name, "max-message-length")) 88 else if (!strcmp(name, "max-message-length"))
81 ctx.cfg.max_msg_len = atoi(value); 89 ctx.cfg.max_msg_len = atoi(value);
82 else if (!strcmp(name, "max-repodesc-length")) 90 else if (!strcmp(name, "max-repodesc-length"))
83 ctx.cfg.max_repodesc_len = atoi(value); 91 ctx.cfg.max_repodesc_len = atoi(value);
84 else if (!strcmp(name, "max-repo-count")) 92 else if (!strcmp(name, "max-repo-count"))
85 ctx.cfg.max_repo_count = atoi(value); 93 ctx.cfg.max_repo_count = atoi(value);
86 else if (!strcmp(name, "max-commit-count")) 94 else if (!strcmp(name, "max-commit-count"))
87 ctx.cfg.max_commit_count = atoi(value); 95 ctx.cfg.max_commit_count = atoi(value);
88 else if (!strcmp(name, "summary-log")) 96 else if (!strcmp(name, "summary-log"))
89 ctx.cfg.summary_log = atoi(value); 97 ctx.cfg.summary_log = atoi(value);
90 else if (!strcmp(name, "summary-branches")) 98 else if (!strcmp(name, "summary-branches"))
91 ctx.cfg.summary_branches = atoi(value); 99 ctx.cfg.summary_branches = atoi(value);
92 else if (!strcmp(name, "summary-tags")) 100 else if (!strcmp(name, "summary-tags"))
93 ctx.cfg.summary_tags = atoi(value); 101 ctx.cfg.summary_tags = atoi(value);
94 else if (!strcmp(name, "agefile")) 102 else if (!strcmp(name, "agefile"))
95 ctx.cfg.agefile = xstrdup(value); 103 ctx.cfg.agefile = xstrdup(value);
96 else if (!strcmp(name, "renamelimit")) 104 else if (!strcmp(name, "renamelimit"))
97 ctx.cfg.renamelimit = atoi(value); 105 ctx.cfg.renamelimit = atoi(value);
98 else if (!strcmp(name, "robots")) 106 else if (!strcmp(name, "robots"))
99 ctx.cfg.robots = xstrdup(value); 107 ctx.cfg.robots = xstrdup(value);
100 else if (!strcmp(name, "clone-prefix")) 108 else if (!strcmp(name, "clone-prefix"))
101 ctx.cfg.clone_prefix = xstrdup(value); 109 ctx.cfg.clone_prefix = xstrdup(value);
102 else if (!strcmp(name, "local-time")) 110 else if (!strcmp(name, "local-time"))
103 ctx.cfg.local_time = atoi(value); 111 ctx.cfg.local_time = atoi(value);
112 else if (!prefixcmp(name, "mimetype."))
113 add_mimetype(name + 9, value);
104 else if (!strcmp(name, "repo.group")) 114 else if (!strcmp(name, "repo.group"))
105 ctx.cfg.repo_group = xstrdup(value); 115 ctx.cfg.repo_group = xstrdup(value);
106 else if (!strcmp(name, "repo.url")) 116 else if (!strcmp(name, "repo.url"))
107 ctx.repo = cgit_add_repo(value); 117 ctx.repo = cgit_add_repo(value);
108 else if (!strcmp(name, "repo.name")) 118 else if (!strcmp(name, "repo.name"))
109 ctx.repo->name = xstrdup(value); 119 ctx.repo->name = xstrdup(value);
110 else if (ctx.repo && !strcmp(name, "repo.path")) 120 else if (ctx.repo && !strcmp(name, "repo.path"))
111 ctx.repo->path = trim_end(value, '/'); 121 ctx.repo->path = trim_end(value, '/');
112 else if (ctx.repo && !strcmp(name, "repo.clone-url")) 122 else if (ctx.repo && !strcmp(name, "repo.clone-url"))
113 ctx.repo->clone_url = xstrdup(value); 123 ctx.repo->clone_url = xstrdup(value);
114 else if (ctx.repo && !strcmp(name, "repo.desc")) 124 else if (ctx.repo && !strcmp(name, "repo.desc"))
115 ctx.repo->desc = xstrdup(value); 125 ctx.repo->desc = xstrdup(value);
116 else if (ctx.repo && !strcmp(name, "repo.owner")) 126 else if (ctx.repo && !strcmp(name, "repo.owner"))
117 ctx.repo->owner = xstrdup(value); 127 ctx.repo->owner = xstrdup(value);
118 else if (ctx.repo && !strcmp(name, "repo.defbranch")) 128 else if (ctx.repo && !strcmp(name, "repo.defbranch"))
119 ctx.repo->defbranch = xstrdup(value); 129 ctx.repo->defbranch = xstrdup(value);
120 else if (ctx.repo && !strcmp(name, "repo.snapshots")) 130 else if (ctx.repo && !strcmp(name, "repo.snapshots"))
121 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 131 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
122 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) 132 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
123 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 133 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
124 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) 134 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
125 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 135 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
126 else if (ctx.repo && !strcmp(name, "repo.max-stats")) 136 else if (ctx.repo && !strcmp(name, "repo.max-stats"))
127 ctx.repo->max_stats = cgit_find_stats_period(value, NULL); 137 ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
128 else if (ctx.repo && !strcmp(name, "repo.module-link")) 138 else if (ctx.repo && !strcmp(name, "repo.module-link"))
129 ctx.repo->module_link= xstrdup(value); 139 ctx.repo->module_link= xstrdup(value);
130 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 140 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
131 if (*value == '/') 141 if (*value == '/')
132 ctx.repo->readme = xstrdup(value); 142 ctx.repo->readme = xstrdup(value);
133 else 143 else
134 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); 144 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
135 } else if (!strcmp(name, "include")) 145 } else if (!strcmp(name, "include"))
136 parse_configfile(value, config_cb); 146 parse_configfile(value, config_cb);
137} 147}
138 148
139static void querystring_cb(const char *name, const char *value) 149static void querystring_cb(const char *name, const char *value)
140{ 150{
141 if (!strcmp(name,"r")) { 151 if (!strcmp(name,"r")) {
142 ctx.qry.repo = xstrdup(value); 152 ctx.qry.repo = xstrdup(value);
143 ctx.repo = cgit_get_repoinfo(value); 153 ctx.repo = cgit_get_repoinfo(value);
144 } else if (!strcmp(name, "p")) { 154 } else if (!strcmp(name, "p")) {
145 ctx.qry.page = xstrdup(value); 155 ctx.qry.page = xstrdup(value);
146 } else if (!strcmp(name, "url")) { 156 } else if (!strcmp(name, "url")) {
147 ctx.qry.url = xstrdup(value); 157 ctx.qry.url = xstrdup(value);
148 cgit_parse_url(value); 158 cgit_parse_url(value);
149 } else if (!strcmp(name, "qt")) { 159 } else if (!strcmp(name, "qt")) {
150 ctx.qry.grep = xstrdup(value); 160 ctx.qry.grep = xstrdup(value);
151 } else if (!strcmp(name, "q")) { 161 } else if (!strcmp(name, "q")) {
152 ctx.qry.search = xstrdup(value); 162 ctx.qry.search = xstrdup(value);
153 } else if (!strcmp(name, "h")) { 163 } else if (!strcmp(name, "h")) {
154 ctx.qry.head = xstrdup(value); 164 ctx.qry.head = xstrdup(value);
155 ctx.qry.has_symref = 1; 165 ctx.qry.has_symref = 1;
156 } else if (!strcmp(name, "id")) { 166 } else if (!strcmp(name, "id")) {
157 ctx.qry.sha1 = xstrdup(value); 167 ctx.qry.sha1 = xstrdup(value);
158 ctx.qry.has_sha1 = 1; 168 ctx.qry.has_sha1 = 1;
159 } else if (!strcmp(name, "id2")) { 169 } else if (!strcmp(name, "id2")) {
160 ctx.qry.sha2 = xstrdup(value); 170 ctx.qry.sha2 = xstrdup(value);
161 ctx.qry.has_sha1 = 1; 171 ctx.qry.has_sha1 = 1;
162 } else if (!strcmp(name, "ofs")) { 172 } else if (!strcmp(name, "ofs")) {
163 ctx.qry.ofs = atoi(value); 173 ctx.qry.ofs = atoi(value);
164 } else if (!strcmp(name, "path")) { 174 } else if (!strcmp(name, "path")) {
165 ctx.qry.path = trim_end(value, '/'); 175 ctx.qry.path = trim_end(value, '/');
166 } else if (!strcmp(name, "name")) { 176 } else if (!strcmp(name, "name")) {
167 ctx.qry.name = xstrdup(value); 177 ctx.qry.name = xstrdup(value);
168 } else if (!strcmp(name, "mimetype")) { 178 } else if (!strcmp(name, "mimetype")) {
169 ctx.qry.mimetype = xstrdup(value); 179 ctx.qry.mimetype = xstrdup(value);
170 } else if (!strcmp(name, "s")){ 180 } else if (!strcmp(name, "s")){
171 ctx.qry.sort = xstrdup(value); 181 ctx.qry.sort = xstrdup(value);
172 } else if (!strcmp(name, "showmsg")) { 182 } else if (!strcmp(name, "showmsg")) {
173 ctx.qry.showmsg = atoi(value); 183 ctx.qry.showmsg = atoi(value);
174 } else if (!strcmp(name, "period")) { 184 } else if (!strcmp(name, "period")) {
175 ctx.qry.period = xstrdup(value); 185 ctx.qry.period = xstrdup(value);
176 } 186 }
177} 187}
178 188
179static void prepare_context(struct cgit_context *ctx) 189static void prepare_context(struct cgit_context *ctx)
180{ 190{
181 memset(ctx, 0, sizeof(ctx)); 191 memset(ctx, 0, sizeof(ctx));
182 ctx->cfg.agefile = "info/web/last-modified"; 192 ctx->cfg.agefile = "info/web/last-modified";
183 ctx->cfg.nocache = 0; 193 ctx->cfg.nocache = 0;
184 ctx->cfg.cache_size = 0; 194 ctx->cfg.cache_size = 0;
185 ctx->cfg.cache_dynamic_ttl = 5; 195 ctx->cfg.cache_dynamic_ttl = 5;
186 ctx->cfg.cache_max_create_time = 5; 196 ctx->cfg.cache_max_create_time = 5;
187 ctx->cfg.cache_repo_ttl = 5; 197 ctx->cfg.cache_repo_ttl = 5;
188 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 198 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
189 ctx->cfg.cache_root_ttl = 5; 199 ctx->cfg.cache_root_ttl = 5;
190 ctx->cfg.cache_static_ttl = -1; 200 ctx->cfg.cache_static_ttl = -1;
191 ctx->cfg.css = "/cgit.css"; 201 ctx->cfg.css = "/cgit.css";
192 ctx->cfg.logo = "/git-logo.png"; 202 ctx->cfg.logo = "/git-logo.png";
193 ctx->cfg.local_time = 0; 203 ctx->cfg.local_time = 0;
194 ctx->cfg.max_repo_count = 50; 204 ctx->cfg.max_repo_count = 50;
195 ctx->cfg.max_commit_count = 50; 205 ctx->cfg.max_commit_count = 50;
196 ctx->cfg.max_lock_attempts = 5; 206 ctx->cfg.max_lock_attempts = 5;
197 ctx->cfg.max_msg_len = 80; 207 ctx->cfg.max_msg_len = 80;
198 ctx->cfg.max_repodesc_len = 80; 208 ctx->cfg.max_repodesc_len = 80;
199 ctx->cfg.max_stats = 0; 209 ctx->cfg.max_stats = 0;
200 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 210 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
201 ctx->cfg.renamelimit = -1; 211 ctx->cfg.renamelimit = -1;
202 ctx->cfg.robots = "index, nofollow"; 212 ctx->cfg.robots = "index, nofollow";
203 ctx->cfg.root_title = "Git repository browser"; 213 ctx->cfg.root_title = "Git repository browser";
204 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 214 ctx->cfg.root_desc = "a fast webinterface for the git dscm";
205 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 215 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
206 ctx->cfg.summary_branches = 10; 216 ctx->cfg.summary_branches = 10;
207 ctx->cfg.summary_log = 10; 217 ctx->cfg.summary_log = 10;
208 ctx->cfg.summary_tags = 10; 218 ctx->cfg.summary_tags = 10;
209 ctx->page.mimetype = "text/html"; 219 ctx->page.mimetype = "text/html";
210 ctx->page.charset = PAGE_ENCODING; 220 ctx->page.charset = PAGE_ENCODING;
211 ctx->page.filename = NULL; 221 ctx->page.filename = NULL;
212 ctx->page.size = 0; 222 ctx->page.size = 0;
213 ctx->page.modified = time(NULL); 223 ctx->page.modified = time(NULL);
214 ctx->page.expires = ctx->page.modified; 224 ctx->page.expires = ctx->page.modified;
215 ctx->page.etag = NULL; 225 ctx->page.etag = NULL;
226 memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
216} 227}
217 228
218struct refmatch { 229struct refmatch {
219 char *req_ref; 230 char *req_ref;
220 char *first_ref; 231 char *first_ref;
221 int match; 232 int match;
222}; 233};
223 234
224int find_current_ref(const char *refname, const unsigned char *sha1, 235int find_current_ref(const char *refname, const unsigned char *sha1,
225 int flags, void *cb_data) 236 int flags, void *cb_data)
226{ 237{
227 struct refmatch *info; 238 struct refmatch *info;
228 239
229 info = (struct refmatch *)cb_data; 240 info = (struct refmatch *)cb_data;
230 if (!strcmp(refname, info->req_ref)) 241 if (!strcmp(refname, info->req_ref))
231 info->match = 1; 242 info->match = 1;
232 if (!info->first_ref) 243 if (!info->first_ref)
233 info->first_ref = xstrdup(refname); 244 info->first_ref = xstrdup(refname);
234 return info->match; 245 return info->match;
235} 246}
236 247
237char *find_default_branch(struct cgit_repo *repo) 248char *find_default_branch(struct cgit_repo *repo)
238{ 249{
239 struct refmatch info; 250 struct refmatch info;
240 char *ref; 251 char *ref;
241 252
242 info.req_ref = repo->defbranch; 253 info.req_ref = repo->defbranch;
243 info.first_ref = NULL; 254 info.first_ref = NULL;
244 info.match = 0; 255 info.match = 0;
245 for_each_branch_ref(find_current_ref, &info); 256 for_each_branch_ref(find_current_ref, &info);
246 if (info.match) 257 if (info.match)
247 ref = info.req_ref; 258 ref = info.req_ref;
248 else 259 else
249 ref = info.first_ref; 260 ref = info.first_ref;
250 if (ref) 261 if (ref)
251 ref = xstrdup(ref); 262 ref = xstrdup(ref);
252 return ref; 263 return ref;
253} 264}
254 265
255static int prepare_repo_cmd(struct cgit_context *ctx) 266static int prepare_repo_cmd(struct cgit_context *ctx)
256{ 267{
257 char *tmp; 268 char *tmp;
258 unsigned char sha1[20]; 269 unsigned char sha1[20];
259 int nongit = 0; 270 int nongit = 0;
260 271
261 setenv("GIT_DIR", ctx->repo->path, 1); 272 setenv("GIT_DIR", ctx->repo->path, 1);
262 setup_git_directory_gently(&nongit); 273 setup_git_directory_gently(&nongit);
263 if (nongit) { 274 if (nongit) {
264 ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, 275 ctx->page.title = fmt("%s - %s", ctx->cfg.root_title,
265 "config error"); 276 "config error");
266 tmp = fmt("Not a git repository: '%s'", ctx->repo->path); 277 tmp = fmt("Not a git repository: '%s'", ctx->repo->path);
267 ctx->repo = NULL; 278 ctx->repo = NULL;
268 cgit_print_http_headers(ctx); 279 cgit_print_http_headers(ctx);
269 cgit_print_docstart(ctx); 280 cgit_print_docstart(ctx);
270 cgit_print_pageheader(ctx); 281 cgit_print_pageheader(ctx);
271 cgit_print_error(tmp); 282 cgit_print_error(tmp);
272 cgit_print_docend(); 283 cgit_print_docend();
273 return 1; 284 return 1;
274 } 285 }
275 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); 286 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
276 287
277 if (!ctx->qry.head) { 288 if (!ctx->qry.head) {
278 ctx->qry.nohead = 1; 289 ctx->qry.nohead = 1;
279 ctx->qry.head = find_default_branch(ctx->repo); 290 ctx->qry.head = find_default_branch(ctx->repo);
280 ctx->repo->defbranch = ctx->qry.head; 291 ctx->repo->defbranch = ctx->qry.head;
281 } 292 }
282 293
283 if (!ctx->qry.head) { 294 if (!ctx->qry.head) {
284 cgit_print_http_headers(ctx); 295 cgit_print_http_headers(ctx);
285 cgit_print_docstart(ctx); 296 cgit_print_docstart(ctx);
286 cgit_print_pageheader(ctx); 297 cgit_print_pageheader(ctx);
287 cgit_print_error("Repository seems to be empty"); 298 cgit_print_error("Repository seems to be empty");
288 cgit_print_docend(); 299 cgit_print_docend();
289 return 1; 300 return 1;
290 } 301 }
291 302
292 if (get_sha1(ctx->qry.head, sha1)) { 303 if (get_sha1(ctx->qry.head, sha1)) {
293 tmp = xstrdup(ctx->qry.head); 304 tmp = xstrdup(ctx->qry.head);
294 ctx->qry.head = ctx->repo->defbranch; 305 ctx->qry.head = ctx->repo->defbranch;
295 ctx->page.status = 404; 306 ctx->page.status = 404;
296 ctx->page.statusmsg = "not found"; 307 ctx->page.statusmsg = "not found";
297 cgit_print_http_headers(ctx); 308 cgit_print_http_headers(ctx);
298 cgit_print_docstart(ctx); 309 cgit_print_docstart(ctx);
299 cgit_print_pageheader(ctx); 310 cgit_print_pageheader(ctx);
300 cgit_print_error(fmt("Invalid branch: %s", tmp)); 311 cgit_print_error(fmt("Invalid branch: %s", tmp));
301 cgit_print_docend(); 312 cgit_print_docend();
302 return 1; 313 return 1;
303 } 314 }
304 return 0; 315 return 0;
305} 316}
306 317
307static void process_request(void *cbdata) 318static void process_request(void *cbdata)
308{ 319{
309 struct cgit_context *ctx = cbdata; 320 struct cgit_context *ctx = cbdata;
310 struct cgit_cmd *cmd; 321 struct cgit_cmd *cmd;
311 322
312 cmd = cgit_get_cmd(ctx); 323 cmd = cgit_get_cmd(ctx);
313 if (!cmd) { 324 if (!cmd) {
314 ctx->page.title = "cgit error"; 325 ctx->page.title = "cgit error";
315 cgit_print_http_headers(ctx); 326 cgit_print_http_headers(ctx);
316 cgit_print_docstart(ctx); 327 cgit_print_docstart(ctx);
317 cgit_print_pageheader(ctx); 328 cgit_print_pageheader(ctx);
318 cgit_print_error("Invalid request"); 329 cgit_print_error("Invalid request");
319 cgit_print_docend(); 330 cgit_print_docend();
320 return; 331 return;
321 } 332 }
322 333
323 if (cmd->want_repo && !ctx->repo) { 334 if (cmd->want_repo && !ctx->repo) {
324 cgit_print_http_headers(ctx); 335 cgit_print_http_headers(ctx);
325 cgit_print_docstart(ctx); 336 cgit_print_docstart(ctx);
326 cgit_print_pageheader(ctx); 337 cgit_print_pageheader(ctx);
327 cgit_print_error(fmt("No repository selected")); 338 cgit_print_error(fmt("No repository selected"));
328 cgit_print_docend(); 339 cgit_print_docend();
329 return; 340 return;
330 } 341 }
331 342
332 if (ctx->repo && prepare_repo_cmd(ctx)) 343 if (ctx->repo && prepare_repo_cmd(ctx))
333 return; 344 return;
334 345
335 if (cmd->want_layout) { 346 if (cmd->want_layout) {
336 cgit_print_http_headers(ctx); 347 cgit_print_http_headers(ctx);
337 cgit_print_docstart(ctx); 348 cgit_print_docstart(ctx);
338 cgit_print_pageheader(ctx); 349 cgit_print_pageheader(ctx);
339 } 350 }
340 351
341 cmd->fn(ctx); 352 cmd->fn(ctx);
342 353
343 if (cmd->want_layout) 354 if (cmd->want_layout)
344 cgit_print_docend(); 355 cgit_print_docend();
345} 356}
346 357
347int cmp_repos(const void *a, const void *b) 358int cmp_repos(const void *a, const void *b)
348{ 359{
349 const struct cgit_repo *ra = a, *rb = b; 360 const struct cgit_repo *ra = a, *rb = b;
350 return strcmp(ra->url, rb->url); 361 return strcmp(ra->url, rb->url);
351} 362}
352 363
353void print_repo(struct cgit_repo *repo) 364void print_repo(struct cgit_repo *repo)
354{ 365{
355 printf("repo.url=%s\n", repo->url); 366 printf("repo.url=%s\n", repo->url);
356 printf("repo.name=%s\n", repo->name); 367 printf("repo.name=%s\n", repo->name);
357 printf("repo.path=%s\n", repo->path); 368 printf("repo.path=%s\n", repo->path);
358 if (repo->owner) 369 if (repo->owner)
359 printf("repo.owner=%s\n", repo->owner); 370 printf("repo.owner=%s\n", repo->owner);
360 if (repo->desc) 371 if (repo->desc)
361 printf("repo.desc=%s\n", repo->desc); 372 printf("repo.desc=%s\n", repo->desc);
362 if (repo->readme) 373 if (repo->readme)
363 printf("repo.readme=%s\n", repo->readme); 374 printf("repo.readme=%s\n", repo->readme);
364 printf("\n"); 375 printf("\n");
365} 376}
366 377
367void print_repolist(struct cgit_repolist *list) 378void print_repolist(struct cgit_repolist *list)
368{ 379{
369 int i; 380 int i;
370 381
371 for(i = 0; i < list->count; i++) 382 for(i = 0; i < list->count; i++)
372 print_repo(&list->repos[i]); 383 print_repo(&list->repos[i]);
373} 384}
374 385
375 386
376static void cgit_parse_args(int argc, const char **argv) 387static void cgit_parse_args(int argc, const char **argv)
377{ 388{
378 int i; 389 int i;
379 int scan = 0; 390 int scan = 0;
380 391
381 for (i = 1; i < argc; i++) { 392 for (i = 1; i < argc; i++) {
382 if (!strncmp(argv[i], "--cache=", 8)) { 393 if (!strncmp(argv[i], "--cache=", 8)) {
383 ctx.cfg.cache_root = xstrdup(argv[i]+8); 394 ctx.cfg.cache_root = xstrdup(argv[i]+8);
384 } 395 }
385 if (!strcmp(argv[i], "--nocache")) { 396 if (!strcmp(argv[i], "--nocache")) {
386 ctx.cfg.nocache = 1; 397 ctx.cfg.nocache = 1;
387 } 398 }
388 if (!strncmp(argv[i], "--query=", 8)) { 399 if (!strncmp(argv[i], "--query=", 8)) {
389 ctx.qry.raw = xstrdup(argv[i]+8); 400 ctx.qry.raw = xstrdup(argv[i]+8);
390 } 401 }
391 if (!strncmp(argv[i], "--repo=", 7)) { 402 if (!strncmp(argv[i], "--repo=", 7)) {
392 ctx.qry.repo = xstrdup(argv[i]+7); 403 ctx.qry.repo = xstrdup(argv[i]+7);
393 } 404 }
394 if (!strncmp(argv[i], "--page=", 7)) { 405 if (!strncmp(argv[i], "--page=", 7)) {
395 ctx.qry.page = xstrdup(argv[i]+7); 406 ctx.qry.page = xstrdup(argv[i]+7);
396 } 407 }
397 if (!strncmp(argv[i], "--head=", 7)) { 408 if (!strncmp(argv[i], "--head=", 7)) {
398 ctx.qry.head = xstrdup(argv[i]+7); 409 ctx.qry.head = xstrdup(argv[i]+7);
399 ctx.qry.has_symref = 1; 410 ctx.qry.has_symref = 1;
400 } 411 }
401 if (!strncmp(argv[i], "--sha1=", 7)) { 412 if (!strncmp(argv[i], "--sha1=", 7)) {
402 ctx.qry.sha1 = xstrdup(argv[i]+7); 413 ctx.qry.sha1 = xstrdup(argv[i]+7);
403 ctx.qry.has_sha1 = 1; 414 ctx.qry.has_sha1 = 1;
404 } 415 }
405 if (!strncmp(argv[i], "--ofs=", 6)) { 416 if (!strncmp(argv[i], "--ofs=", 6)) {
406 ctx.qry.ofs = atoi(argv[i]+6); 417 ctx.qry.ofs = atoi(argv[i]+6);
407 } 418 }
408 if (!strncmp(argv[i], "--scan-tree=", 12)) { 419 if (!strncmp(argv[i], "--scan-tree=", 12)) {
409 scan++; 420 scan++;
410 scan_tree(argv[i] + 12); 421 scan_tree(argv[i] + 12);
411 } 422 }
412 } 423 }
413 if (scan) { 424 if (scan) {
414 qsort(cgit_repolist.repos, cgit_repolist.count, 425 qsort(cgit_repolist.repos, cgit_repolist.count,
415 sizeof(struct cgit_repo), cmp_repos); 426 sizeof(struct cgit_repo), cmp_repos);
416 print_repolist(&cgit_repolist); 427 print_repolist(&cgit_repolist);
417 exit(0); 428 exit(0);
418 } 429 }
419} 430}
420 431
421static int calc_ttl() 432static int calc_ttl()
422{ 433{
423 if (!ctx.repo) 434 if (!ctx.repo)
424 return ctx.cfg.cache_root_ttl; 435 return ctx.cfg.cache_root_ttl;
425 436
426 if (!ctx.qry.page) 437 if (!ctx.qry.page)
427 return ctx.cfg.cache_repo_ttl; 438 return ctx.cfg.cache_repo_ttl;
428 439
429 if (ctx.qry.has_symref) 440 if (ctx.qry.has_symref)
430 return ctx.cfg.cache_dynamic_ttl; 441 return ctx.cfg.cache_dynamic_ttl;
431 442
432 if (ctx.qry.has_sha1) 443 if (ctx.qry.has_sha1)
433 return ctx.cfg.cache_static_ttl; 444 return ctx.cfg.cache_static_ttl;
434 445
435 return ctx.cfg.cache_repo_ttl; 446 return ctx.cfg.cache_repo_ttl;
436} 447}
437 448
438int main(int argc, const char **argv) 449int main(int argc, const char **argv)
439{ 450{
440 const char *cgit_config_env = getenv("CGIT_CONFIG"); 451 const char *cgit_config_env = getenv("CGIT_CONFIG");
441 const char *method = getenv("REQUEST_METHOD"); 452 const char *method = getenv("REQUEST_METHOD");
442 const char *path; 453 const char *path;
443 char *qry; 454 char *qry;
444 int err, ttl; 455 int err, ttl;
445 456
446 prepare_context(&ctx); 457 prepare_context(&ctx);
447 cgit_repolist.length = 0; 458 cgit_repolist.length = 0;
448 cgit_repolist.count = 0; 459 cgit_repolist.count = 0;
449 cgit_repolist.repos = NULL; 460 cgit_repolist.repos = NULL;
450 461
451 if (getenv("SCRIPT_NAME")) 462 if (getenv("SCRIPT_NAME"))
452 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); 463 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
453 if (getenv("QUERY_STRING")) 464 if (getenv("QUERY_STRING"))
454 ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); 465 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
455 cgit_parse_args(argc, argv); 466 cgit_parse_args(argc, argv);
456 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 467 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
457 config_cb); 468 config_cb);
458 ctx.repo = NULL; 469 ctx.repo = NULL;
459 http_parse_querystring(ctx.qry.raw, querystring_cb); 470 http_parse_querystring(ctx.qry.raw, querystring_cb);
460 471
461 /* If virtual-root isn't specified in cgitrc, lets pretend 472 /* If virtual-root isn't specified in cgitrc, lets pretend
462 * that virtual-root equals SCRIPT_NAME. 473 * that virtual-root equals SCRIPT_NAME.
463 */ 474 */
464 if (!ctx.cfg.virtual_root) 475 if (!ctx.cfg.virtual_root)
465 ctx.cfg.virtual_root = ctx.cfg.script_name; 476 ctx.cfg.virtual_root = ctx.cfg.script_name;
466 477
467 /* If no url parameter is specified on the querystring, lets 478 /* If no url parameter is specified on the querystring, lets
468 * use PATH_INFO as url. This allows cgit to work with virtual 479 * use PATH_INFO as url. This allows cgit to work with virtual
469 * urls without the need for rewriterules in the webserver (as 480 * urls without the need for rewriterules in the webserver (as
470 * long as PATH_INFO is included in the cache lookup key). 481 * long as PATH_INFO is included in the cache lookup key).
471 */ 482 */
472 path = getenv("PATH_INFO"); 483 path = getenv("PATH_INFO");
473 if (!ctx.qry.url && path) { 484 if (!ctx.qry.url && path) {
474 if (path[0] == '/') 485 if (path[0] == '/')
475 path++; 486 path++;
476 ctx.qry.url = xstrdup(path); 487 ctx.qry.url = xstrdup(path);
477 if (ctx.qry.raw) { 488 if (ctx.qry.raw) {
478 qry = ctx.qry.raw; 489 qry = ctx.qry.raw;
479 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); 490 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
480 free(qry); 491 free(qry);
481 } else 492 } else
482 ctx.qry.raw = ctx.qry.url; 493 ctx.qry.raw = ctx.qry.url;
483 cgit_parse_url(ctx.qry.url); 494 cgit_parse_url(ctx.qry.url);
484 } 495 }
485 496
486 ttl = calc_ttl(); 497 ttl = calc_ttl();
487 ctx.page.expires += ttl*60; 498 ctx.page.expires += ttl*60;
488 if (method && !strcmp(method, "HEAD")) 499 if (method && !strcmp(method, "HEAD"))
489 ctx.cfg.nocache = 1; 500 ctx.cfg.nocache = 1;
490 if (ctx.cfg.nocache) 501 if (ctx.cfg.nocache)
491 ctx.cfg.cache_size = 0; 502 ctx.cfg.cache_size = 0;
492 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 503 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
493 ctx.qry.raw, ttl, process_request, &ctx); 504 ctx.qry.raw, ttl, process_request, &ctx);
494 if (err) 505 if (err)
495 cgit_print_error(fmt("Error processing page: %s (%d)", 506 cgit_print_error(fmt("Error processing page: %s (%d)",
496 strerror(err), err)); 507 strerror(err), err));
497 return err; 508 return err;
498} 509}
diff --git a/cgit.h b/cgit.h
index 8c64efe..9259f33 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,252 +1,254 @@
1#ifndef CGIT_H 1#ifndef CGIT_H
2#define CGIT_H 2#define CGIT_H
3 3
4 4
5#include <git-compat-util.h> 5#include <git-compat-util.h>
6#include <cache.h> 6#include <cache.h>
7#include <grep.h> 7#include <grep.h>
8#include <object.h> 8#include <object.h>
9#include <tree.h> 9#include <tree.h>
10#include <commit.h> 10#include <commit.h>
11#include <tag.h> 11#include <tag.h>
12#include <diff.h> 12#include <diff.h>
13#include <diffcore.h> 13#include <diffcore.h>
14#include <refs.h> 14#include <refs.h>
15#include <revision.h> 15#include <revision.h>
16#include <log-tree.h> 16#include <log-tree.h>
17#include <archive.h> 17#include <archive.h>
18#include <string-list.h>
18#include <xdiff-interface.h> 19#include <xdiff-interface.h>
19#include <xdiff/xdiff.h> 20#include <xdiff/xdiff.h>
20#include <utf8.h> 21#include <utf8.h>
21 22
22 23
23/* 24/*
24 * Dateformats used on misc. pages 25 * Dateformats used on misc. pages
25 */ 26 */
26#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" 27#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
27#define FMT_SHORTDATE "%Y-%m-%d" 28#define FMT_SHORTDATE "%Y-%m-%d"
28#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" 29#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
29 30
30 31
31/* 32/*
32 * Limits used for relative dates 33 * Limits used for relative dates
33 */ 34 */
34#define TM_MIN 60 35#define TM_MIN 60
35#define TM_HOUR (TM_MIN * 60) 36#define TM_HOUR (TM_MIN * 60)
36#define TM_DAY (TM_HOUR * 24) 37#define TM_DAY (TM_HOUR * 24)
37#define TM_WEEK (TM_DAY * 7) 38#define TM_WEEK (TM_DAY * 7)
38#define TM_YEAR (TM_DAY * 365) 39#define TM_YEAR (TM_DAY * 365)
39#define TM_MONTH (TM_YEAR / 12.0) 40#define TM_MONTH (TM_YEAR / 12.0)
40 41
41 42
42/* 43/*
43 * Default encoding 44 * Default encoding
44 */ 45 */
45#define PAGE_ENCODING "UTF-8" 46#define PAGE_ENCODING "UTF-8"
46 47
47typedef void (*configfn)(const char *name, const char *value); 48typedef void (*configfn)(const char *name, const char *value);
48typedef void (*filepair_fn)(struct diff_filepair *pair); 49typedef void (*filepair_fn)(struct diff_filepair *pair);
49typedef void (*linediff_fn)(char *line, int len); 50typedef void (*linediff_fn)(char *line, int len);
50 51
51struct cgit_repo { 52struct cgit_repo {
52 char *url; 53 char *url;
53 char *name; 54 char *name;
54 char *path; 55 char *path;
55 char *desc; 56 char *desc;
56 char *owner; 57 char *owner;
57 char *defbranch; 58 char *defbranch;
58 char *group; 59 char *group;
59 char *module_link; 60 char *module_link;
60 char *readme; 61 char *readme;
61 char *clone_url; 62 char *clone_url;
62 int snapshots; 63 int snapshots;
63 int enable_log_filecount; 64 int enable_log_filecount;
64 int enable_log_linecount; 65 int enable_log_linecount;
65 int max_stats; 66 int max_stats;
66 time_t mtime; 67 time_t mtime;
67}; 68};
68 69
69struct cgit_repolist { 70struct cgit_repolist {
70 int length; 71 int length;
71 int count; 72 int count;
72 struct cgit_repo *repos; 73 struct cgit_repo *repos;
73}; 74};
74 75
75struct commitinfo { 76struct commitinfo {
76 struct commit *commit; 77 struct commit *commit;
77 char *author; 78 char *author;
78 char *author_email; 79 char *author_email;
79 unsigned long author_date; 80 unsigned long author_date;
80 char *committer; 81 char *committer;
81 char *committer_email; 82 char *committer_email;
82 unsigned long committer_date; 83 unsigned long committer_date;
83 char *subject; 84 char *subject;
84 char *msg; 85 char *msg;
85 char *msg_encoding; 86 char *msg_encoding;
86}; 87};
87 88
88struct taginfo { 89struct taginfo {
89 char *tagger; 90 char *tagger;
90 char *tagger_email; 91 char *tagger_email;
91 unsigned long tagger_date; 92 unsigned long tagger_date;
92 char *msg; 93 char *msg;
93}; 94};
94 95
95struct refinfo { 96struct refinfo {
96 const char *refname; 97 const char *refname;
97 struct object *object; 98 struct object *object;
98 union { 99 union {
99 struct taginfo *tag; 100 struct taginfo *tag;
100 struct commitinfo *commit; 101 struct commitinfo *commit;
101 }; 102 };
102}; 103};
103 104
104struct reflist { 105struct reflist {
105 struct refinfo **refs; 106 struct refinfo **refs;
106 int alloc; 107 int alloc;
107 int count; 108 int count;
108}; 109};
109 110
110struct cgit_query { 111struct cgit_query {
111 int has_symref; 112 int has_symref;
112 int has_sha1; 113 int has_sha1;
113 char *raw; 114 char *raw;
114 char *repo; 115 char *repo;
115 char *page; 116 char *page;
116 char *search; 117 char *search;
117 char *grep; 118 char *grep;
118 char *head; 119 char *head;
119 char *sha1; 120 char *sha1;
120 char *sha2; 121 char *sha2;
121 char *path; 122 char *path;
122 char *name; 123 char *name;
123 char *mimetype; 124 char *mimetype;
124 char *url; 125 char *url;
125 char *period; 126 char *period;
126 int ofs; 127 int ofs;
127 int nohead; 128 int nohead;
128 char *sort; 129 char *sort;
129 int showmsg; 130 int showmsg;
130}; 131};
131 132
132struct cgit_config { 133struct cgit_config {
133 char *agefile; 134 char *agefile;
134 char *cache_root; 135 char *cache_root;
135 char *clone_prefix; 136 char *clone_prefix;
136 char *css; 137 char *css;
137 char *favicon; 138 char *favicon;
138 char *footer; 139 char *footer;
139 char *head_include; 140 char *head_include;
140 char *header; 141 char *header;
141 char *index_header; 142 char *index_header;
142 char *index_info; 143 char *index_info;
143 char *logo; 144 char *logo;
144 char *logo_link; 145 char *logo_link;
145 char *module_link; 146 char *module_link;
146 char *repo_group; 147 char *repo_group;
147 char *robots; 148 char *robots;
148 char *root_title; 149 char *root_title;
149 char *root_desc; 150 char *root_desc;
150 char *root_readme; 151 char *root_readme;
151 char *script_name; 152 char *script_name;
152 char *virtual_root; 153 char *virtual_root;
153 int cache_size; 154 int cache_size;
154 int cache_dynamic_ttl; 155 int cache_dynamic_ttl;
155 int cache_max_create_time; 156 int cache_max_create_time;
156 int cache_repo_ttl; 157 int cache_repo_ttl;
157 int cache_root_ttl; 158 int cache_root_ttl;
158 int cache_static_ttl; 159 int cache_static_ttl;
159 int embedded; 160 int embedded;
160 int enable_index_links; 161 int enable_index_links;
161 int enable_log_filecount; 162 int enable_log_filecount;
162 int enable_log_linecount; 163 int enable_log_linecount;
163 int local_time; 164 int local_time;
164 int max_repo_count; 165 int max_repo_count;
165 int max_commit_count; 166 int max_commit_count;
166 int max_lock_attempts; 167 int max_lock_attempts;
167 int max_msg_len; 168 int max_msg_len;
168 int max_repodesc_len; 169 int max_repodesc_len;
169 int max_stats; 170 int max_stats;
170 int nocache; 171 int nocache;
171 int noheader; 172 int noheader;
172 int renamelimit; 173 int renamelimit;
173 int snapshots; 174 int snapshots;
174 int summary_branches; 175 int summary_branches;
175 int summary_log; 176 int summary_log;
176 int summary_tags; 177 int summary_tags;
178 struct string_list mimetypes;
177}; 179};
178 180
179struct cgit_page { 181struct cgit_page {
180 time_t modified; 182 time_t modified;
181 time_t expires; 183 time_t expires;
182 size_t size; 184 size_t size;
183 char *mimetype; 185 char *mimetype;
184 char *charset; 186 char *charset;
185 char *filename; 187 char *filename;
186 char *etag; 188 char *etag;
187 char *title; 189 char *title;
188 int status; 190 int status;
189 char *statusmsg; 191 char *statusmsg;
190}; 192};
191 193
192struct cgit_context { 194struct cgit_context {
193 struct cgit_query qry; 195 struct cgit_query qry;
194 struct cgit_config cfg; 196 struct cgit_config cfg;
195 struct cgit_repo *repo; 197 struct cgit_repo *repo;
196 struct cgit_page page; 198 struct cgit_page page;
197}; 199};
198 200
199struct cgit_snapshot_format { 201struct cgit_snapshot_format {
200 const char *suffix; 202 const char *suffix;
201 const char *mimetype; 203 const char *mimetype;
202 write_archive_fn_t write_func; 204 write_archive_fn_t write_func;
203 int bit; 205 int bit;
204}; 206};
205 207
206extern const char *cgit_version; 208extern const char *cgit_version;
207 209
208extern struct cgit_repolist cgit_repolist; 210extern struct cgit_repolist cgit_repolist;
209extern struct cgit_context ctx; 211extern struct cgit_context ctx;
210extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 212extern const struct cgit_snapshot_format cgit_snapshot_formats[];
211 213
212extern struct cgit_repo *cgit_add_repo(const char *url); 214extern struct cgit_repo *cgit_add_repo(const char *url);
213extern struct cgit_repo *cgit_get_repoinfo(const char *url); 215extern struct cgit_repo *cgit_get_repoinfo(const char *url);
214extern void cgit_repo_config_cb(const char *name, const char *value); 216extern void cgit_repo_config_cb(const char *name, const char *value);
215 217
216extern int chk_zero(int result, char *msg); 218extern int chk_zero(int result, char *msg);
217extern int chk_positive(int result, char *msg); 219extern int chk_positive(int result, char *msg);
218extern int chk_non_negative(int result, char *msg); 220extern int chk_non_negative(int result, char *msg);
219 221
220extern char *trim_end(const char *str, char c); 222extern char *trim_end(const char *str, char c);
221extern char *strlpart(char *txt, int maxlen); 223extern char *strlpart(char *txt, int maxlen);
222extern char *strrpart(char *txt, int maxlen); 224extern char *strrpart(char *txt, int maxlen);
223 225
224extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); 226extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
225extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, 227extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
226 int flags, void *cb_data); 228 int flags, void *cb_data);
227 229
228extern void *cgit_free_commitinfo(struct commitinfo *info); 230extern void *cgit_free_commitinfo(struct commitinfo *info);
229 231
230extern int cgit_diff_files(const unsigned char *old_sha1, 232extern int cgit_diff_files(const unsigned char *old_sha1,
231 const unsigned char *new_sha1, 233 const unsigned char *new_sha1,
232 unsigned long *old_size, unsigned long *new_size, 234 unsigned long *old_size, unsigned long *new_size,
233 int *binary, linediff_fn fn); 235 int *binary, linediff_fn fn);
234 236
235extern void cgit_diff_tree(const unsigned char *old_sha1, 237extern void cgit_diff_tree(const unsigned char *old_sha1,
236 const unsigned char *new_sha1, 238 const unsigned char *new_sha1,
237 filepair_fn fn, const char *prefix); 239 filepair_fn fn, const char *prefix);
238 240
239extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 241extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
240 242
241extern char *fmt(const char *format,...); 243extern char *fmt(const char *format,...);
242 244
243extern struct commitinfo *cgit_parse_commit(struct commit *commit); 245extern struct commitinfo *cgit_parse_commit(struct commit *commit);
244extern struct taginfo *cgit_parse_tag(struct tag *tag); 246extern struct taginfo *cgit_parse_tag(struct tag *tag);
245extern void cgit_parse_url(const char *url); 247extern void cgit_parse_url(const char *url);
246 248
247extern const char *cgit_repobasename(const char *reponame); 249extern const char *cgit_repobasename(const char *reponame);
248 250
249extern int cgit_parse_snapshots_mask(const char *str); 251extern int cgit_parse_snapshots_mask(const char *str);
250 252
251 253
252#endif /* CGIT_H */ 254#endif /* CGIT_H */
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index a207fe0..7256ec0 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -1,403 +1,420 @@
1CGITRC(5) 1CGITRC(5)
2======== 2========
3 3
4 4
5NAME 5NAME
6---- 6----
7cgitrc - runtime configuration for cgit 7cgitrc - runtime configuration for cgit
8 8
9 9
10SYNOPSIS 10SYNOPSIS
11-------- 11--------
12Cgitrc contains all runtime settings for cgit, including the list of git 12Cgitrc contains all runtime settings for cgit, including the list of git
13repositories, formatted as a line-separated list of NAME=VALUE pairs. Blank 13repositories, formatted as a line-separated list of NAME=VALUE pairs. Blank
14lines, and lines starting with '#', are ignored. 14lines, and lines starting with '#', are ignored.
15 15
16 16
17GLOBAL SETTINGS 17GLOBAL SETTINGS
18--------------- 18---------------
19agefile:: 19agefile::
20 Specifies a path, relative to each repository path, which can be used 20 Specifies a path, relative to each repository path, which can be used
21 to specify the date and time of the youngest commit in the repository. 21 to specify the date and time of the youngest commit in the repository.
22 The first line in the file is used as input to the "parse_date" 22 The first line in the file is used as input to the "parse_date"
23 function in libgit. Recommended timestamp-format is "yyyy-mm-dd 23 function in libgit. Recommended timestamp-format is "yyyy-mm-dd
24 hh:mm:ss". Default value: "info/web/last-modified". 24 hh:mm:ss". Default value: "info/web/last-modified".
25 25
26cache-root:: 26cache-root::
27 Path used to store the cgit cache entries. Default value: 27 Path used to store the cgit cache entries. Default value:
28 "/var/cache/cgit". 28 "/var/cache/cgit".
29 29
30cache-dynamic-ttl:: 30cache-dynamic-ttl::
31 Number which specifies the time-to-live, in minutes, for the cached 31 Number which specifies the time-to-live, in minutes, for the cached
32 version of repository pages accessed without a fixed SHA1. Default 32 version of repository pages accessed without a fixed SHA1. Default
33 value: "5". 33 value: "5".
34 34
35cache-repo-ttl:: 35cache-repo-ttl::
36 Number which specifies the time-to-live, in minutes, for the cached 36 Number which specifies the time-to-live, in minutes, for the cached
37 version of the repository summary page. Default value: "5". 37 version of the repository summary page. Default value: "5".
38 38
39cache-root-ttl:: 39cache-root-ttl::
40 Number which specifies the time-to-live, in minutes, for the cached 40 Number which specifies the time-to-live, in minutes, for the cached
41 version of the repository index page. Default value: "5". 41 version of the repository index page. Default value: "5".
42 42
43cache-size:: 43cache-size::
44 The maximum number of entries in the cgit cache. Default value: "0" 44 The maximum number of entries in the cgit cache. Default value: "0"
45 (i.e. caching is disabled). 45 (i.e. caching is disabled).
46 46
47cache-static-ttl:: 47cache-static-ttl::
48 Number which specifies the time-to-live, in minutes, for the cached 48 Number which specifies the time-to-live, in minutes, for the cached
49 version of repository pages accessed with a fixed SHA1. Default value: 49 version of repository pages accessed with a fixed SHA1. Default value:
50 "5". 50 "5".
51 51
52clone-prefix:: 52clone-prefix::
53 Space-separated list of common prefixes which, when combined with a 53 Space-separated list of common prefixes which, when combined with a
54 repository url, generates valid clone urls for the repository. This 54 repository url, generates valid clone urls for the repository. This
55 setting is only used if `repo.clone-url` is unspecified. Default value: 55 setting is only used if `repo.clone-url` is unspecified. Default value:
56 none. 56 none.
57 57
58css:: 58css::
59 Url which specifies the css document to include in all cgit pages. 59 Url which specifies the css document to include in all cgit pages.
60 Default value: "/cgit.css". 60 Default value: "/cgit.css".
61 61
62embedded:: 62embedded::
63 Flag which, when set to "1", will make cgit generate a html fragment 63 Flag which, when set to "1", will make cgit generate a html fragment
64 suitable for embedding in other html pages. Default value: none. See 64 suitable for embedding in other html pages. Default value: none. See
65 also: "noheader". 65 also: "noheader".
66 66
67enable-index-links:: 67enable-index-links::
68 Flag which, when set to "1", will make cgit generate extra links for 68 Flag which, when set to "1", will make cgit generate extra links for
69 each repo in the repository index (specifically, to the "summary", 69 each repo in the repository index (specifically, to the "summary",
70 "commit" and "tree" pages). Default value: "0". 70 "commit" and "tree" pages). Default value: "0".
71 71
72enable-log-filecount:: 72enable-log-filecount::
73 Flag which, when set to "1", will make cgit print the number of 73 Flag which, when set to "1", will make cgit print the number of
74 modified files for each commit on the repository log page. Default 74 modified files for each commit on the repository log page. Default
75 value: "0". 75 value: "0".
76 76
77enable-log-linecount:: 77enable-log-linecount::
78 Flag which, when set to "1", will make cgit print the number of added 78 Flag which, when set to "1", will make cgit print the number of added
79 and removed lines for each commit on the repository log page. Default 79 and removed lines for each commit on the repository log page. Default
80 value: "0". 80 value: "0".
81 81
82favicon:: 82favicon::
83 Url used as link to a shortcut icon for cgit. If specified, it is 83 Url used as link to a shortcut icon for cgit. If specified, it is
84 suggested to use the value "/favicon.ico" since certain browsers will 84 suggested to use the value "/favicon.ico" since certain browsers will
85 ignore other values. Default value: none. 85 ignore other values. Default value: none.
86 86
87footer:: 87footer::
88 The content of the file specified with this option will be included 88 The content of the file specified with this option will be included
89 verbatim at the bottom of all pages (i.e. it replaces the standard 89 verbatim at the bottom of all pages (i.e. it replaces the standard
90 "generated by..." message. Default value: none. 90 "generated by..." message. Default value: none.
91 91
92head-include:: 92head-include::
93 The content of the file specified with this option will be included 93 The content of the file specified with this option will be included
94 verbatim in the html HEAD section on all pages. Default value: none. 94 verbatim in the html HEAD section on all pages. Default value: none.
95 95
96header:: 96header::
97 The content of the file specified with this option will be included 97 The content of the file specified with this option will be included
98 verbatim at the top of all pages. Default value: none. 98 verbatim at the top of all pages. Default value: none.
99 99
100include:: 100include::
101 Name of a configfile to include before the rest of the current config- 101 Name of a configfile to include before the rest of the current config-
102 file is parsed. Default value: none. 102 file is parsed. Default value: none.
103 103
104index-header:: 104index-header::
105 The content of the file specified with this option will be included 105 The content of the file specified with this option will be included
106 verbatim above the repository index. This setting is deprecated, and 106 verbatim above the repository index. This setting is deprecated, and
107 will not be supported by cgit-1.0 (use root-readme instead). Default 107 will not be supported by cgit-1.0 (use root-readme instead). Default
108 value: none. 108 value: none.
109 109
110index-info:: 110index-info::
111 The content of the file specified with this option will be included 111 The content of the file specified with this option will be included
112 verbatim below the heading on the repository index page. This setting 112 verbatim below the heading on the repository index page. This setting
113 is deprecated, and will not be supported by cgit-1.0 (use root-desc 113 is deprecated, and will not be supported by cgit-1.0 (use root-desc
114 instead). Default value: none. 114 instead). Default value: none.
115 115
116local-time:: 116local-time::
117 Flag which, if set to "1", makes cgit print commit and tag times in the 117 Flag which, if set to "1", makes cgit print commit and tag times in the
118 servers timezone. Default value: "0". 118 servers timezone. Default value: "0".
119 119
120logo:: 120logo::
121 Url which specifies the source of an image which will be used as a logo 121 Url which specifies the source of an image which will be used as a logo
122 on all cgit pages. 122 on all cgit pages.
123 123
124logo-link:: 124logo-link::
125 Url loaded when clicking on the cgit logo image. If unspecified the 125 Url loaded when clicking on the cgit logo image. If unspecified the
126 calculated url of the repository index page will be used. Default 126 calculated url of the repository index page will be used. Default
127 value: none. 127 value: none.
128 128
129max-commit-count:: 129max-commit-count::
130 Specifies the number of entries to list per page in "log" view. Default 130 Specifies the number of entries to list per page in "log" view. Default
131 value: "50". 131 value: "50".
132 132
133max-message-length:: 133max-message-length::
134 Specifies the maximum number of commit message characters to display in 134 Specifies the maximum number of commit message characters to display in
135 "log" view. Default value: "80". 135 "log" view. Default value: "80".
136 136
137max-repo-count:: 137max-repo-count::
138 Specifies the number of entries to list per page on therepository 138 Specifies the number of entries to list per page on therepository
139 index page. Default value: "50". 139 index page. Default value: "50".
140 140
141max-repodesc-length:: 141max-repodesc-length::
142 Specifies the maximum number of repo description characters to display 142 Specifies the maximum number of repo description characters to display
143 on the repository index page. Default value: "80". 143 on the repository index page. Default value: "80".
144 144
145max-stats:: 145max-stats::
146 Set the default maximum statistics period. Valid values are "week", 146 Set the default maximum statistics period. Valid values are "week",
147 "month", "quarter" and "year". If unspecified, statistics are 147 "month", "quarter" and "year". If unspecified, statistics are
148 disabled. Default value: none. See also: "repo.max-stats". 148 disabled. Default value: none. See also: "repo.max-stats".
149 149
150mimetype.<ext>::
151 Set the mimetype for the specified filename extension. This is used
152 by the `plain` command when returning blob content.
153
150module-link:: 154module-link::
151 Text which will be used as the formatstring for a hyperlink when a 155 Text which will be used as the formatstring for a hyperlink when a
152 submodule is printed in a directory listing. The arguments for the 156 submodule is printed in a directory listing. The arguments for the
153 formatstring are the path and SHA1 of the submodule commit. Default 157 formatstring are the path and SHA1 of the submodule commit. Default
154 value: "./?repo=%s&page=commit&id=%s" 158 value: "./?repo=%s&page=commit&id=%s"
155 159
156nocache:: 160nocache::
157 If set to the value "1" caching will be disabled. This settings is 161 If set to the value "1" caching will be disabled. This settings is
158 deprecated, and will not be honored starting with cgit-1.0. Default 162 deprecated, and will not be honored starting with cgit-1.0. Default
159 value: "0". 163 value: "0".
160 164
161noheader:: 165noheader::
162 Flag which, when set to "1", will make cgit omit the standard header 166 Flag which, when set to "1", will make cgit omit the standard header
163 on all pages. Default value: none. See also: "embedded". 167 on all pages. Default value: none. See also: "embedded".
164 168
165renamelimit:: 169renamelimit::
166 Maximum number of files to consider when detecting renames. The value 170 Maximum number of files to consider when detecting renames. The value
167 "-1" uses the compiletime value in git (for further info, look at 171 "-1" uses the compiletime value in git (for further info, look at
168 `man git-diff`). Default value: "-1". 172 `man git-diff`). Default value: "-1".
169 173
170repo.group:: 174repo.group::
171 A value for the current repository group, which all repositories 175 A value for the current repository group, which all repositories
172 specified after this setting will inherit. Default value: none. 176 specified after this setting will inherit. Default value: none.
173 177
174robots:: 178robots::
175 Text used as content for the "robots" meta-tag. Default value: 179 Text used as content for the "robots" meta-tag. Default value:
176 "index, nofollow". 180 "index, nofollow".
177 181
178root-desc:: 182root-desc::
179 Text printed below the heading on the repository index page. Default 183 Text printed below the heading on the repository index page. Default
180 value: "a fast webinterface for the git dscm". 184 value: "a fast webinterface for the git dscm".
181 185
182root-readme:: 186root-readme::
183 The content of the file specified with this option will be included 187 The content of the file specified with this option will be included
184 verbatim below the "about" link on the repository index page. Default 188 verbatim below the "about" link on the repository index page. Default
185 value: none. 189 value: none.
186 190
187root-title:: 191root-title::
188 Text printed as heading on the repository index page. Default value: 192 Text printed as heading on the repository index page. Default value:
189 "Git Repository Browser". 193 "Git Repository Browser".
190 194
191snapshots:: 195snapshots::
192 Text which specifies the default (and allowed) set of snapshot formats 196 Text which specifies the default (and allowed) set of snapshot formats
193 supported by cgit. The value is a space-separated list of zero or more 197 supported by cgit. The value is a space-separated list of zero or more
194 of the following values: 198 of the following values:
195 "tar" uncompressed tar-file 199 "tar" uncompressed tar-file
196 "tar.gz"gzip-compressed tar-file 200 "tar.gz"gzip-compressed tar-file
197 "tar.bz2"bzip-compressed tar-file 201 "tar.bz2"bzip-compressed tar-file
198 "zip" zip-file 202 "zip" zip-file
199 Default value: none. 203 Default value: none.
200 204
201summary-branches:: 205summary-branches::
202 Specifies the number of branches to display in the repository "summary" 206 Specifies the number of branches to display in the repository "summary"
203 view. Default value: "10". 207 view. Default value: "10".
204 208
205summary-log:: 209summary-log::
206 Specifies the number of log entries to display in the repository 210 Specifies the number of log entries to display in the repository
207 "summary" view. Default value: "10". 211 "summary" view. Default value: "10".
208 212
209summary-tags:: 213summary-tags::
210 Specifies the number of tags to display in the repository "summary" 214 Specifies the number of tags to display in the repository "summary"
211 view. Default value: "10". 215 view. Default value: "10".
212 216
213virtual-root:: 217virtual-root::
214 Url which, if specified, will be used as root for all cgit links. It 218 Url which, if specified, will be used as root for all cgit links. It
215 will also cause cgit to generate 'virtual urls', i.e. urls like 219 will also cause cgit to generate 'virtual urls', i.e. urls like
216 '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default 220 '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default
217 value: none. 221 value: none.
218 NOTE: cgit has recently learned how to use PATH_INFO to achieve the 222 NOTE: cgit has recently learned how to use PATH_INFO to achieve the
219 same kind of virtual urls, so this option will probably be deprecated. 223 same kind of virtual urls, so this option will probably be deprecated.
220 224
221REPOSITORY SETTINGS 225REPOSITORY SETTINGS
222------------------- 226-------------------
223repo.clone-url:: 227repo.clone-url::
224 A list of space-separated urls which can be used to clone this repo. 228 A list of space-separated urls which can be used to clone this repo.
225 Default value: none. 229 Default value: none.
226 230
227repo.defbranch:: 231repo.defbranch::
228 The name of the default branch for this repository. If no such branch 232 The name of the default branch for this repository. If no such branch
229 exists in the repository, the first branch name (when sorted) is used 233 exists in the repository, the first branch name (when sorted) is used
230 as default instead. Default value: "master". 234 as default instead. Default value: "master".
231 235
232repo.desc:: 236repo.desc::
233 The value to show as repository description. Default value: none. 237 The value to show as repository description. Default value: none.
234 238
235repo.enable-log-filecount:: 239repo.enable-log-filecount::
236 A flag which can be used to disable the global setting 240 A flag which can be used to disable the global setting
237 `enable-log-filecount'. Default value: none. 241 `enable-log-filecount'. Default value: none.
238 242
239repo.enable-log-linecount:: 243repo.enable-log-linecount::
240 A flag which can be used to disable the global setting 244 A flag which can be used to disable the global setting
241 `enable-log-linecount'. Default value: none. 245 `enable-log-linecount'. Default value: none.
242 246
243repo.max-stats:: 247repo.max-stats::
244 Override the default maximum statistics period. Valid values are equal 248 Override the default maximum statistics period. Valid values are equal
245 to the values specified for the global "max-stats" setting. Default 249 to the values specified for the global "max-stats" setting. Default
246 value: none. 250 value: none.
247 251
248repo.name:: 252repo.name::
249 The value to show as repository name. Default value: <repo.url>. 253 The value to show as repository name. Default value: <repo.url>.
250 254
251repo.owner:: 255repo.owner::
252 A value used to identify the owner of the repository. Default value: 256 A value used to identify the owner of the repository. Default value:
253 none. 257 none.
254 258
255repo.path:: 259repo.path::
256 An absolute path to the repository directory. For non-bare repositories 260 An absolute path to the repository directory. For non-bare repositories
257 this is the .git-directory. Default value: none. 261 this is the .git-directory. Default value: none.
258 262
259repo.readme:: 263repo.readme::
260 A path (relative to <repo.path>) which specifies a file to include 264 A path (relative to <repo.path>) which specifies a file to include
261 verbatim as the "About" page for this repo. Default value: none. 265 verbatim as the "About" page for this repo. Default value: none.
262 266
263repo.snapshots:: 267repo.snapshots::
264 A mask of allowed snapshot-formats for this repo, restricted by the 268 A mask of allowed snapshot-formats for this repo, restricted by the
265 "snapshots" global setting. Default value: <snapshots>. 269 "snapshots" global setting. Default value: <snapshots>.
266 270
267repo.url:: 271repo.url::
268 The relative url used to access the repository. This must be the first 272 The relative url used to access the repository. This must be the first
269 setting specified for each repo. Default value: none. 273 setting specified for each repo. Default value: none.
270 274
271 275
272EXAMPLE CGITRC FILE 276EXAMPLE CGITRC FILE
273------------------- 277-------------------
274 278
275.... 279....
276# Enable caching of up to 1000 output entriess 280# Enable caching of up to 1000 output entriess
277cache-size=1000 281cache-size=1000
278 282
279 283
280# Specify some default clone prefixes 284# Specify some default clone prefixes
281clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git 285clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git
282 286
283# Specify the css url 287# Specify the css url
284css=/css/cgit.css 288css=/css/cgit.css
285 289
286 290
287# Show extra links for each repository on the index page 291# Show extra links for each repository on the index page
288enable-index-links=1 292enable-index-links=1
289 293
290 294
291# Show number of affected files per commit on the log pages 295# Show number of affected files per commit on the log pages
292enable-log-filecount=1 296enable-log-filecount=1
293 297
294 298
295# Show number of added/removed lines per commit on the log pages 299# Show number of added/removed lines per commit on the log pages
296enable-log-linecount=1 300enable-log-linecount=1
297 301
298 302
299# Add a cgit favicon 303# Add a cgit favicon
300favicon=/favicon.ico 304favicon=/favicon.ico
301 305
302 306
303# Use a custom logo 307# Use a custom logo
304logo=/img/mylogo.png 308logo=/img/mylogo.png
305 309
306 310
307# Enable statistics per week, month and quarter 311# Enable statistics per week, month and quarter
308max-stats=quarter 312max-stats=quarter
309 313
310 314
311# Set the title and heading of the repository index page 315# Set the title and heading of the repository index page
312root-title=foobar.com git repositories 316root-title=foobar.com git repositories
313 317
314 318
315# Set a subheading for the repository index page 319# Set a subheading for the repository index page
316root-desc=tracking the foobar development 320root-desc=tracking the foobar development
317 321
318 322
319# Include some more info about foobar.com on the index page 323# Include some more info about foobar.com on the index page
320root-readme=/var/www/htdocs/about.html 324root-readme=/var/www/htdocs/about.html
321 325
322 326
323# Allow download of tar.gz, tar.bz2 and zip-files 327# Allow download of tar.gz, tar.bz2 and zip-files
324snapshots=tar.gz tar.bz2 zip 328snapshots=tar.gz tar.bz2 zip
325 329
326 330
327## 331##
332## List of common mimetypes
333##
334
335mimetype.git=image/git
336mimetype.html=text/html
337mimetype.jpg=image/jpeg
338mimetype.jpeg=image/jpeg
339mimetype.pdf=application/pdf
340mimetype.png=image/png
341mimetype.svg=image/svg+xml
342
343
344##
328## List of repositories. 345## List of repositories.
329## PS: Any repositories listed when repo.group is unset will not be 346## PS: Any repositories listed when repo.group is unset will not be
330## displayed under a group heading 347## displayed under a group heading
331## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') 348## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos')
332## and included like this: 349## and included like this:
333## include=/etc/cgitrepos 350## include=/etc/cgitrepos
334## 351##
335 352
336 353
337repo.url=foo 354repo.url=foo
338repo.path=/pub/git/foo.git 355repo.path=/pub/git/foo.git
339repo.desc=the master foo repository 356repo.desc=the master foo repository
340repo.owner=fooman@foobar.com 357repo.owner=fooman@foobar.com
341repo.readme=info/web/about.html 358repo.readme=info/web/about.html
342 359
343 360
344repo.url=bar 361repo.url=bar
345repo.path=/pub/git/bar.git 362repo.path=/pub/git/bar.git
346repo.desc=the bars for your foo 363repo.desc=the bars for your foo
347repo.owner=barman@foobar.com 364repo.owner=barman@foobar.com
348repo.readme=info/web/about.html 365repo.readme=info/web/about.html
349 366
350 367
351# The next repositories will be displayed under the 'extras' heading 368# The next repositories will be displayed under the 'extras' heading
352repo.group=extras 369repo.group=extras
353 370
354 371
355repo.url=baz 372repo.url=baz
356repo.path=/pub/git/baz.git 373repo.path=/pub/git/baz.git
357repo.desc=a set of extensions for bar users 374repo.desc=a set of extensions for bar users
358 375
359repo.url=wiz 376repo.url=wiz
360repo.path=/pub/git/wiz.git 377repo.path=/pub/git/wiz.git
361repo.desc=the wizard of foo 378repo.desc=the wizard of foo
362 379
363 380
364# Add some mirrored repositories 381# Add some mirrored repositories
365repo.group=mirrors 382repo.group=mirrors
366 383
367 384
368repo.url=git 385repo.url=git
369repo.path=/pub/git/git.git 386repo.path=/pub/git/git.git
370repo.desc=the dscm 387repo.desc=the dscm
371 388
372 389
373repo.url=linux 390repo.url=linux
374repo.path=/pub/git/linux.git 391repo.path=/pub/git/linux.git
375repo.desc=the kernel 392repo.desc=the kernel
376 393
377# Disable adhoc downloads of this repo 394# Disable adhoc downloads of this repo
378repo.snapshots=0 395repo.snapshots=0
379 396
380# Disable line-counts for this repo 397# Disable line-counts for this repo
381repo.enable-log-linecount=0 398repo.enable-log-linecount=0
382 399
383# Restrict the max statistics period for this repo 400# Restrict the max statistics period for this repo
384repo.max-stats=month 401repo.max-stats=month
385.... 402....
386 403
387 404
388BUGS 405BUGS
389---- 406----
390Comments currently cannot appear on the same line as a setting; the comment 407Comments currently cannot appear on the same line as a setting; the comment
391will be included as part of the value. E.g. this line: 408will be included as part of the value. E.g. this line:
392 409
393 robots=index # allow indexing 410 robots=index # allow indexing
394 411
395will generate the following html element: 412will generate the following html element:
396 413
397 <meta name='robots' content='index # allow indexing'/> 414 <meta name='robots' content='index # allow indexing'/>
398 415
399 416
400 417
401AUTHOR 418AUTHOR
402------ 419------
403Lars Hjemli <hjemli@gmail.com> 420Lars Hjemli <hjemli@gmail.com>
diff --git a/ui-plain.c b/ui-plain.c
index 93a3a05..27c6dae 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -1,83 +1,93 @@
1/* ui-plain.c: functions for output of plain blobs by path 1/* ui-plain.c: functions for output of plain blobs by path
2 * 2 *
3 * Copyright (C) 2008 Lars Hjemli 3 * Copyright (C) 2008 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13char *curr_rev; 13char *curr_rev;
14char *match_path; 14char *match_path;
15int match; 15int match;
16 16
17static void print_object(const unsigned char *sha1, const char *path) 17static void print_object(const unsigned char *sha1, const char *path)
18{ 18{
19 enum object_type type; 19 enum object_type type;
20 char *buf; 20 char *buf, *ext;
21 unsigned long size; 21 unsigned long size;
22 struct string_list_item *mime;
22 23
23 type = sha1_object_info(sha1, &size); 24 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) { 25 if (type == OBJ_BAD) {
25 html_status(404, "Not found", 0); 26 html_status(404, "Not found", 0);
26 return; 27 return;
27 } 28 }
28 29
29 buf = read_sha1_file(sha1, &type, &size); 30 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) { 31 if (!buf) {
31 html_status(404, "Not found", 0); 32 html_status(404, "Not found", 0);
32 return; 33 return;
33 } 34 }
34 if (buffer_is_binary(buf, size)) 35 ctx.page.mimetype = NULL;
35 ctx.page.mimetype = "application/octet-stream"; 36 ext = strrchr(path, '.');
36 else 37 if (ext && *(++ext)) {
37 ctx.page.mimetype = "text/plain"; 38 mime = string_list_lookup(ext, &ctx.cfg.mimetypes);
39 if (mime)
40 ctx.page.mimetype = (char *)mime->util;
41 }
42 if (!ctx.page.mimetype) {
43 if (buffer_is_binary(buf, size))
44 ctx.page.mimetype = "application/octet-stream";
45 else
46 ctx.page.mimetype = "text/plain";
47 }
38 ctx.page.filename = fmt("%s", path); 48 ctx.page.filename = fmt("%s", path);
39 ctx.page.size = size; 49 ctx.page.size = size;
40 ctx.page.etag = sha1_to_hex(sha1); 50 ctx.page.etag = sha1_to_hex(sha1);
41 cgit_print_http_headers(&ctx); 51 cgit_print_http_headers(&ctx);
42 html_raw(buf, size); 52 html_raw(buf, size);
43 match = 1; 53 match = 1;
44} 54}
45 55
46static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 56static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
47 const char *pathname, unsigned mode, int stage, 57 const char *pathname, unsigned mode, int stage,
48 void *cbdata) 58 void *cbdata)
49{ 59{
50 if (S_ISDIR(mode)) 60 if (S_ISDIR(mode))
51 return READ_TREE_RECURSIVE; 61 return READ_TREE_RECURSIVE;
52 62
53 if (S_ISREG(mode)) 63 if (S_ISREG(mode))
54 print_object(sha1, pathname); 64 print_object(sha1, pathname);
55 65
56 return 0; 66 return 0;
57} 67}
58 68
59void cgit_print_plain(struct cgit_context *ctx) 69void cgit_print_plain(struct cgit_context *ctx)
60{ 70{
61 const char *rev = ctx->qry.sha1; 71 const char *rev = ctx->qry.sha1;
62 unsigned char sha1[20]; 72 unsigned char sha1[20];
63 struct commit *commit; 73 struct commit *commit;
64 const char *paths[] = {ctx->qry.path, NULL}; 74 const char *paths[] = {ctx->qry.path, NULL};
65 75
66 if (!rev) 76 if (!rev)
67 rev = ctx->qry.head; 77 rev = ctx->qry.head;
68 78
69 curr_rev = xstrdup(rev); 79 curr_rev = xstrdup(rev);
70 if (get_sha1(rev, sha1)) { 80 if (get_sha1(rev, sha1)) {
71 html_status(404, "Not found", 0); 81 html_status(404, "Not found", 0);
72 return; 82 return;
73 } 83 }
74 commit = lookup_commit_reference(sha1); 84 commit = lookup_commit_reference(sha1);
75 if (!commit || parse_commit(commit)) { 85 if (!commit || parse_commit(commit)) {
76 html_status(404, "Not found", 0); 86 html_status(404, "Not found", 0);
77 return; 87 return;
78 } 88 }
79 match_path = ctx->qry.path; 89 match_path = ctx->qry.path;
80 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); 90 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL);
81 if (!match) 91 if (!match)
82 html_status(404, "Not found", 0); 92 html_status(404, "Not found", 0);
83} 93}