summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c17
-rw-r--r--ui-shared.c2
2 files changed, 9 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c
index b270fdc..2c933dc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,318 +1,317 @@
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 10
11static int cgit_prepare_cache(struct cacheitem *item) 11static int cgit_prepare_cache(struct cacheitem *item)
12{ 12{
13 if (!ctx.repo && ctx.qry.repo) { 13 if (!ctx.repo && ctx.qry.repo) {
14 char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); 14 char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request");
15 cgit_print_docstart(title, item); 15 cgit_print_docstart(title, item);
16 cgit_print_pageheader(title, 0); 16 cgit_print_pageheader(title, 0);
17 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); 17 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo));
18 cgit_print_docend(); 18 cgit_print_docend();
19 return 0; 19 return 0;
20 } 20 }
21 21
22 if (!ctx.repo) { 22 if (!ctx.repo) {
23 item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); 23 item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root));
24 item->ttl = ctx.cfg.cache_root_ttl; 24 item->ttl = ctx.cfg.cache_root_ttl;
25 return 1; 25 return 1;
26 } 26 }
27 27
28 if (!cgit_cmd) { 28 if (!cgit_cmd) {
29 item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, 29 item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root,
30 cache_safe_filename(ctx.repo->url), 30 cache_safe_filename(ctx.repo->url),
31 cache_safe_filename(ctx.qry.raw))); 31 cache_safe_filename(ctx.qry.raw)));
32 item->ttl = ctx.cfg.cache_repo_ttl; 32 item->ttl = ctx.cfg.cache_repo_ttl;
33 } else { 33 } else {
34 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, 34 item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root,
35 cache_safe_filename(ctx.repo->url), 35 cache_safe_filename(ctx.repo->url),
36 ctx.qry.page, 36 ctx.qry.page,
37 cache_safe_filename(ctx.qry.raw))); 37 cache_safe_filename(ctx.qry.raw)));
38 if (ctx.qry.has_symref) 38 if (ctx.qry.has_symref)
39 item->ttl = ctx.cfg.cache_dynamic_ttl; 39 item->ttl = ctx.cfg.cache_dynamic_ttl;
40 else if (ctx.qry.has_sha1) 40 else if (ctx.qry.has_sha1)
41 item->ttl = ctx.cfg.cache_static_ttl; 41 item->ttl = ctx.cfg.cache_static_ttl;
42 else 42 else
43 item->ttl = ctx.cfg.cache_repo_ttl; 43 item->ttl = ctx.cfg.cache_repo_ttl;
44 } 44 }
45 return 1; 45 return 1;
46} 46}
47 47
48struct refmatch { 48struct refmatch {
49 char *req_ref; 49 char *req_ref;
50 char *first_ref; 50 char *first_ref;
51 int match; 51 int match;
52}; 52};
53 53
54int find_current_ref(const char *refname, const unsigned char *sha1, 54int find_current_ref(const char *refname, const unsigned char *sha1,
55 int flags, void *cb_data) 55 int flags, void *cb_data)
56{ 56{
57 struct refmatch *info; 57 struct refmatch *info;
58 58
59 info = (struct refmatch *)cb_data; 59 info = (struct refmatch *)cb_data;
60 if (!strcmp(refname, info->req_ref)) 60 if (!strcmp(refname, info->req_ref))
61 info->match = 1; 61 info->match = 1;
62 if (!info->first_ref) 62 if (!info->first_ref)
63 info->first_ref = xstrdup(refname); 63 info->first_ref = xstrdup(refname);
64 return info->match; 64 return info->match;
65} 65}
66 66
67char *find_default_branch(struct cgit_repo *repo) 67char *find_default_branch(struct cgit_repo *repo)
68{ 68{
69 struct refmatch info; 69 struct refmatch info;
70 70
71 info.req_ref = repo->defbranch; 71 info.req_ref = repo->defbranch;
72 info.first_ref = NULL; 72 info.first_ref = NULL;
73 info.match = 0; 73 info.match = 0;
74 for_each_branch_ref(find_current_ref, &info); 74 for_each_branch_ref(find_current_ref, &info);
75 if (info.match) 75 if (info.match)
76 return info.req_ref; 76 return info.req_ref;
77 else 77 else
78 return info.first_ref; 78 return info.first_ref;
79} 79}
80 80
81static void cgit_print_repo_page(struct cacheitem *item) 81static void cgit_print_repo_page(struct cacheitem *item)
82{ 82{
83 char *title, *tmp; 83 char *title, *tmp;
84 int show_search; 84 int show_search;
85 unsigned char sha1[20]; 85 unsigned char sha1[20];
86 int nongit = 0;
86 87
87 if (chdir(ctx.repo->path)) { 88 setenv("GIT_DIR", ctx.repo->path, 1);
88 title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); 89 setup_git_directory_gently(&nongit);
90 if (nongit) {
91 title = fmt("%s - %s", ctx.cfg.root_title, "config error");
92 tmp = fmt("Not a git repository: '%s'", ctx.repo->path);
93 ctx.repo = NULL;
89 cgit_print_docstart(title, item); 94 cgit_print_docstart(title, item);
90 cgit_print_pageheader(title, 0); 95 cgit_print_pageheader(title, 0);
91 cgit_print_error(fmt("Unable to scan repository: %s", 96 cgit_print_error(tmp);
92 strerror(errno)));
93 cgit_print_docend(); 97 cgit_print_docend();
94 return; 98 return;
95 } 99 }
96 100
97 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); 101 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
98 show_search = 0; 102 show_search = 0;
99 setenv("GIT_DIR", ctx.repo->path, 1);
100 103
101 if (!ctx.qry.head) { 104 if (!ctx.qry.head) {
102 ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); 105 ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
103 ctx.repo->defbranch = ctx.qry.head; 106 ctx.repo->defbranch = ctx.qry.head;
104 } 107 }
105 108
106 if (!ctx.qry.head) { 109 if (!ctx.qry.head) {
107 cgit_print_docstart(title, item); 110 cgit_print_docstart(title, item);
108 cgit_print_pageheader(title, 0); 111 cgit_print_pageheader(title, 0);
109 cgit_print_error("Repository seems to be empty"); 112 cgit_print_error("Repository seems to be empty");
110 cgit_print_docend(); 113 cgit_print_docend();
111 return; 114 return;
112 } 115 }
113 116
114 if (get_sha1(ctx.qry.head, sha1)) { 117 if (get_sha1(ctx.qry.head, sha1)) {
115 tmp = xstrdup(ctx.qry.head); 118 tmp = xstrdup(ctx.qry.head);
116 ctx.qry.head = ctx.repo->defbranch; 119 ctx.qry.head = ctx.repo->defbranch;
117 cgit_print_docstart(title, item); 120 cgit_print_docstart(title, item);
118 cgit_print_pageheader(title, 0); 121 cgit_print_pageheader(title, 0);
119 cgit_print_error(fmt("Invalid branch: %s", tmp)); 122 cgit_print_error(fmt("Invalid branch: %s", tmp));
120 cgit_print_docend(); 123 cgit_print_docend();
121 return; 124 return;
122 } 125 }
123 126
124 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { 127 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) {
125 cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, 128 cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1,
126 cgit_repobasename(ctx.repo->url), 129 cgit_repobasename(ctx.repo->url),
127 ctx.qry.path, 130 ctx.qry.path,
128 ctx.repo->snapshots ); 131 ctx.repo->snapshots );
129 return; 132 return;
130 } 133 }
131 134
132 if (cgit_cmd == CMD_PATCH) { 135 if (cgit_cmd == CMD_PATCH) {
133 cgit_print_patch(ctx.qry.sha1, item); 136 cgit_print_patch(ctx.qry.sha1, item);
134 return; 137 return;
135 } 138 }
136 139
137 if (cgit_cmd == CMD_BLOB) { 140 if (cgit_cmd == CMD_BLOB) {
138 cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); 141 cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path);
139 return; 142 return;
140 } 143 }
141 144
142 show_search = (cgit_cmd == CMD_LOG); 145 show_search = (cgit_cmd == CMD_LOG);
143 cgit_print_docstart(title, item); 146 cgit_print_docstart(title, item);
144 if (!cgit_cmd) { 147 if (!cgit_cmd) {
145 cgit_print_pageheader("summary", show_search); 148 cgit_print_pageheader("summary", show_search);
146 cgit_print_summary(); 149 cgit_print_summary();
147 cgit_print_docend(); 150 cgit_print_docend();
148 return; 151 return;
149 } 152 }
150 153
151 cgit_print_pageheader(ctx.qry.page, show_search); 154 cgit_print_pageheader(ctx.qry.page, show_search);
152 155
153 switch(cgit_cmd) { 156 switch(cgit_cmd) {
154 case CMD_LOG: 157 case CMD_LOG:
155 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, 158 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs,
156 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, 159 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search,
157 ctx.qry.path, 1); 160 ctx.qry.path, 1);
158 break; 161 break;
159 case CMD_TREE: 162 case CMD_TREE:
160 cgit_print_tree(ctx.qry.sha1, ctx.qry.path); 163 cgit_print_tree(ctx.qry.sha1, ctx.qry.path);
161 break; 164 break;
162 case CMD_COMMIT: 165 case CMD_COMMIT:
163 cgit_print_commit(ctx.qry.sha1); 166 cgit_print_commit(ctx.qry.sha1);
164 break; 167 break;
165 case CMD_REFS: 168 case CMD_REFS:
166 cgit_print_refs(); 169 cgit_print_refs();
167 break; 170 break;
168 case CMD_TAG: 171 case CMD_TAG:
169 cgit_print_tag(ctx.qry.sha1); 172 cgit_print_tag(ctx.qry.sha1);
170 break; 173 break;
171 case CMD_DIFF: 174 case CMD_DIFF:
172 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); 175 cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path);
173 break; 176 break;
174 default: 177 default:
175 cgit_print_error("Invalid request"); 178 cgit_print_error("Invalid request");
176 } 179 }
177 cgit_print_docend(); 180 cgit_print_docend();
178} 181}
179 182
180static void cgit_fill_cache(struct cacheitem *item, int use_cache) 183static void cgit_fill_cache(struct cacheitem *item, int use_cache)
181{ 184{
182 static char buf[PATH_MAX];
183 int stdout2; 185 int stdout2;
184 186
185 getcwd(buf, sizeof(buf));
186 item->st.st_mtime = time(NULL); 187 item->st.st_mtime = time(NULL);
187 188
188 if (use_cache) { 189 if (use_cache) {
189 stdout2 = chk_positive(dup(STDOUT_FILENO), 190 stdout2 = chk_positive(dup(STDOUT_FILENO),
190 "Preserving STDOUT"); 191 "Preserving STDOUT");
191 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 192 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
192 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 193 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
193 } 194 }
194 195
195 if (ctx.repo) 196 if (ctx.repo)
196 cgit_print_repo_page(item); 197 cgit_print_repo_page(item);
197 else 198 else
198 cgit_print_repolist(item); 199 cgit_print_repolist(item);
199 200
200 if (use_cache) { 201 if (use_cache) {
201 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 202 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
202 chk_positive(dup2(stdout2, STDOUT_FILENO), 203 chk_positive(dup2(stdout2, STDOUT_FILENO),
203 "Restoring original STDOUT"); 204 "Restoring original STDOUT");
204 chk_zero(close(stdout2), "Closing temporary STDOUT"); 205 chk_zero(close(stdout2), "Closing temporary STDOUT");
205 } 206 }
206
207 chdir(buf);
208} 207}
209 208
210static void cgit_check_cache(struct cacheitem *item) 209static void cgit_check_cache(struct cacheitem *item)
211{ 210{
212 int i = 0; 211 int i = 0;
213 212
214 top: 213 top:
215 if (++i > ctx.cfg.max_lock_attempts) { 214 if (++i > ctx.cfg.max_lock_attempts) {
216 die("cgit_refresh_cache: unable to lock %s: %s", 215 die("cgit_refresh_cache: unable to lock %s: %s",
217 item->name, strerror(errno)); 216 item->name, strerror(errno));
218 } 217 }
219 if (!cache_exist(item)) { 218 if (!cache_exist(item)) {
220 if (!cache_lock(item)) { 219 if (!cache_lock(item)) {
221 sleep(1); 220 sleep(1);
222 goto top; 221 goto top;
223 } 222 }
224 if (!cache_exist(item)) { 223 if (!cache_exist(item)) {
225 cgit_fill_cache(item, 1); 224 cgit_fill_cache(item, 1);
226 cache_unlock(item); 225 cache_unlock(item);
227 } else { 226 } else {
228 cache_cancel_lock(item); 227 cache_cancel_lock(item);
229 } 228 }
230 } else if (cache_expired(item) && cache_lock(item)) { 229 } else if (cache_expired(item) && cache_lock(item)) {
231 if (cache_expired(item)) { 230 if (cache_expired(item)) {
232 cgit_fill_cache(item, 1); 231 cgit_fill_cache(item, 1);
233 cache_unlock(item); 232 cache_unlock(item);
234 } else { 233 } else {
235 cache_cancel_lock(item); 234 cache_cancel_lock(item);
236 } 235 }
237 } 236 }
238} 237}
239 238
240static void cgit_print_cache(struct cacheitem *item) 239static void cgit_print_cache(struct cacheitem *item)
241{ 240{
242 static char buf[4096]; 241 static char buf[4096];
243 ssize_t i; 242 ssize_t i;
244 243
245 int fd = open(item->name, O_RDONLY); 244 int fd = open(item->name, O_RDONLY);
246 if (fd<0) 245 if (fd<0)
247 die("Unable to open cached file %s", item->name); 246 die("Unable to open cached file %s", item->name);
248 247
249 while((i=read(fd, buf, sizeof(buf))) > 0) 248 while((i=read(fd, buf, sizeof(buf))) > 0)
250 write(STDOUT_FILENO, buf, i); 249 write(STDOUT_FILENO, buf, i);
251 250
252 close(fd); 251 close(fd);
253} 252}
254 253
255static void cgit_parse_args(int argc, const char **argv) 254static void cgit_parse_args(int argc, const char **argv)
256{ 255{
257 int i; 256 int i;
258 257
259 for (i = 1; i < argc; i++) { 258 for (i = 1; i < argc; i++) {
260 if (!strncmp(argv[i], "--cache=", 8)) { 259 if (!strncmp(argv[i], "--cache=", 8)) {
261 ctx.cfg.cache_root = xstrdup(argv[i]+8); 260 ctx.cfg.cache_root = xstrdup(argv[i]+8);
262 } 261 }
263 if (!strcmp(argv[i], "--nocache")) { 262 if (!strcmp(argv[i], "--nocache")) {
264 ctx.cfg.nocache = 1; 263 ctx.cfg.nocache = 1;
265 } 264 }
266 if (!strncmp(argv[i], "--query=", 8)) { 265 if (!strncmp(argv[i], "--query=", 8)) {
267 ctx.qry.raw = xstrdup(argv[i]+8); 266 ctx.qry.raw = xstrdup(argv[i]+8);
268 } 267 }
269 if (!strncmp(argv[i], "--repo=", 7)) { 268 if (!strncmp(argv[i], "--repo=", 7)) {
270 ctx.qry.repo = xstrdup(argv[i]+7); 269 ctx.qry.repo = xstrdup(argv[i]+7);
271 } 270 }
272 if (!strncmp(argv[i], "--page=", 7)) { 271 if (!strncmp(argv[i], "--page=", 7)) {
273 ctx.qry.page = xstrdup(argv[i]+7); 272 ctx.qry.page = xstrdup(argv[i]+7);
274 } 273 }
275 if (!strncmp(argv[i], "--head=", 7)) { 274 if (!strncmp(argv[i], "--head=", 7)) {
276 ctx.qry.head = xstrdup(argv[i]+7); 275 ctx.qry.head = xstrdup(argv[i]+7);
277 ctx.qry.has_symref = 1; 276 ctx.qry.has_symref = 1;
278 } 277 }
279 if (!strncmp(argv[i], "--sha1=", 7)) { 278 if (!strncmp(argv[i], "--sha1=", 7)) {
280 ctx.qry.sha1 = xstrdup(argv[i]+7); 279 ctx.qry.sha1 = xstrdup(argv[i]+7);
281 ctx.qry.has_sha1 = 1; 280 ctx.qry.has_sha1 = 1;
282 } 281 }
283 if (!strncmp(argv[i], "--ofs=", 6)) { 282 if (!strncmp(argv[i], "--ofs=", 6)) {
284 ctx.qry.ofs = atoi(argv[i]+6); 283 ctx.qry.ofs = atoi(argv[i]+6);
285 } 284 }
286 } 285 }
287} 286}
288 287
289int main(int argc, const char **argv) 288int main(int argc, const char **argv)
290{ 289{
291 struct cacheitem item; 290 struct cacheitem item;
292 const char *cgit_config_env = getenv("CGIT_CONFIG"); 291 const char *cgit_config_env = getenv("CGIT_CONFIG");
293 292
294 cgit_prepare_context(&ctx); 293 cgit_prepare_context(&ctx);
295 htmlfd = STDOUT_FILENO; 294 htmlfd = STDOUT_FILENO;
296 item.st.st_mtime = time(NULL); 295 item.st.st_mtime = time(NULL);
297 cgit_repolist.length = 0; 296 cgit_repolist.length = 0;
298 cgit_repolist.count = 0; 297 cgit_repolist.count = 0;
299 cgit_repolist.repos = NULL; 298 cgit_repolist.repos = NULL;
300 299
301 cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 300 cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
302 cgit_global_config_cb); 301 cgit_global_config_cb);
303 if (getenv("SCRIPT_NAME")) 302 if (getenv("SCRIPT_NAME"))
304 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); 303 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
305 if (getenv("QUERY_STRING")) 304 if (getenv("QUERY_STRING"))
306 ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); 305 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
307 cgit_parse_args(argc, argv); 306 cgit_parse_args(argc, argv);
308 cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); 307 cgit_parse_query(ctx.qry.raw, cgit_querystring_cb);
309 if (!cgit_prepare_cache(&item)) 308 if (!cgit_prepare_cache(&item))
310 return 0; 309 return 0;
311 if (ctx.cfg.nocache) { 310 if (ctx.cfg.nocache) {
312 cgit_fill_cache(&item, 0); 311 cgit_fill_cache(&item, 0);
313 } else { 312 } else {
314 cgit_check_cache(&item); 313 cgit_check_cache(&item);
315 cgit_print_cache(&item); 314 cgit_print_cache(&item);
316 } 315 }
317 return 0; 316 return 0;
318} 317}
diff --git a/ui-shared.c b/ui-shared.c
index b9f487a..cc1ab8b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -95,476 +95,476 @@ const char *cgit_repobasename(const char *reponame)
95 p = strlen(rvbuf)-1; 95 p = strlen(rvbuf)-1;
96 /* strip trailing slashes */ 96 /* strip trailing slashes */
97 while(p && rvbuf[p]=='/') rvbuf[p--]=0; 97 while(p && rvbuf[p]=='/') rvbuf[p--]=0;
98 /* strip trailing .git */ 98 /* strip trailing .git */
99 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { 99 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
100 p -= 3; rvbuf[p--] = 0; 100 p -= 3; rvbuf[p--] = 0;
101 } 101 }
102 /* strip more trailing slashes if any */ 102 /* strip more trailing slashes if any */
103 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 103 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
104 /* find last slash in the remaining string */ 104 /* find last slash in the remaining string */
105 rv = strrchr(rvbuf,'/'); 105 rv = strrchr(rvbuf,'/');
106 if(rv) 106 if(rv)
107 return ++rv; 107 return ++rv;
108 return rvbuf; 108 return rvbuf;
109} 109}
110 110
111char *cgit_currurl() 111char *cgit_currurl()
112{ 112{
113 if (!ctx.cfg.virtual_root) 113 if (!ctx.cfg.virtual_root)
114 return ctx.cfg.script_name; 114 return ctx.cfg.script_name;
115 else if (ctx.qry.page) 115 else if (ctx.qry.page)
116 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); 116 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
117 else if (ctx.qry.repo) 117 else if (ctx.qry.repo)
118 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); 118 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
119 else 119 else
120 return fmt("%s/", ctx.cfg.virtual_root); 120 return fmt("%s/", ctx.cfg.virtual_root);
121} 121}
122 122
123static char *repolink(char *title, char *class, char *page, char *head, 123static char *repolink(char *title, char *class, char *page, char *head,
124 char *path) 124 char *path)
125{ 125{
126 char *delim = "?"; 126 char *delim = "?";
127 127
128 html("<a"); 128 html("<a");
129 if (title) { 129 if (title) {
130 html(" title='"); 130 html(" title='");
131 html_attr(title); 131 html_attr(title);
132 html("'"); 132 html("'");
133 } 133 }
134 if (class) { 134 if (class) {
135 html(" class='"); 135 html(" class='");
136 html_attr(class); 136 html_attr(class);
137 html("'"); 137 html("'");
138 } 138 }
139 html(" href='"); 139 html(" href='");
140 if (ctx.cfg.virtual_root) { 140 if (ctx.cfg.virtual_root) {
141 html_attr(ctx.cfg.virtual_root); 141 html_attr(ctx.cfg.virtual_root);
142 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 142 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
143 html("/"); 143 html("/");
144 html_attr(ctx.repo->url); 144 html_attr(ctx.repo->url);
145 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 145 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
146 html("/"); 146 html("/");
147 if (page) { 147 if (page) {
148 html(page); 148 html(page);
149 html("/"); 149 html("/");
150 if (path) 150 if (path)
151 html_attr(path); 151 html_attr(path);
152 } 152 }
153 } else { 153 } else {
154 html(ctx.cfg.script_name); 154 html(ctx.cfg.script_name);
155 html("?url="); 155 html("?url=");
156 html_attr(ctx.repo->url); 156 html_attr(ctx.repo->url);
157 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 157 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
158 html("/"); 158 html("/");
159 if (page) { 159 if (page) {
160 html(page); 160 html(page);
161 html("/"); 161 html("/");
162 if (path) 162 if (path)
163 html_attr(path); 163 html_attr(path);
164 } 164 }
165 delim = "&amp;"; 165 delim = "&amp;";
166 } 166 }
167 if (head && strcmp(head, ctx.repo->defbranch)) { 167 if (head && strcmp(head, ctx.repo->defbranch)) {
168 html(delim); 168 html(delim);
169 html("h="); 169 html("h=");
170 html_attr(head); 170 html_attr(head);
171 delim = "&amp;"; 171 delim = "&amp;";
172 } 172 }
173 return fmt("%s", delim); 173 return fmt("%s", delim);
174} 174}
175 175
176static void reporevlink(char *page, char *name, char *title, char *class, 176static void reporevlink(char *page, char *name, char *title, char *class,
177 char *head, char *rev, char *path) 177 char *head, char *rev, char *path)
178{ 178{
179 char *delim; 179 char *delim;
180 180
181 delim = repolink(title, class, page, head, path); 181 delim = repolink(title, class, page, head, path);
182 if (rev && strcmp(rev, ctx.qry.head)) { 182 if (rev && strcmp(rev, ctx.qry.head)) {
183 html(delim); 183 html(delim);
184 html("id="); 184 html("id=");
185 html_attr(rev); 185 html_attr(rev);
186 } 186 }
187 html("'>"); 187 html("'>");
188 html_txt(name); 188 html_txt(name);
189 html("</a>"); 189 html("</a>");
190} 190}
191 191
192void cgit_tree_link(char *name, char *title, char *class, char *head, 192void cgit_tree_link(char *name, char *title, char *class, char *head,
193 char *rev, char *path) 193 char *rev, char *path)
194{ 194{
195 reporevlink("tree", name, title, class, head, rev, path); 195 reporevlink("tree", name, title, class, head, rev, path);
196} 196}
197 197
198void cgit_log_link(char *name, char *title, char *class, char *head, 198void cgit_log_link(char *name, char *title, char *class, char *head,
199 char *rev, char *path, int ofs, char *grep, char *pattern) 199 char *rev, char *path, int ofs, char *grep, char *pattern)
200{ 200{
201 char *delim; 201 char *delim;
202 202
203 delim = repolink(title, class, "log", head, path); 203 delim = repolink(title, class, "log", head, path);
204 if (rev && strcmp(rev, ctx.qry.head)) { 204 if (rev && strcmp(rev, ctx.qry.head)) {
205 html(delim); 205 html(delim);
206 html("id="); 206 html("id=");
207 html_attr(rev); 207 html_attr(rev);
208 delim = "&"; 208 delim = "&";
209 } 209 }
210 if (grep && pattern) { 210 if (grep && pattern) {
211 html(delim); 211 html(delim);
212 html("qt="); 212 html("qt=");
213 html_attr(grep); 213 html_attr(grep);
214 delim = "&"; 214 delim = "&";
215 html(delim); 215 html(delim);
216 html("q="); 216 html("q=");
217 html_attr(pattern); 217 html_attr(pattern);
218 } 218 }
219 if (ofs > 0) { 219 if (ofs > 0) {
220 html(delim); 220 html(delim);
221 html("ofs="); 221 html("ofs=");
222 htmlf("%d", ofs); 222 htmlf("%d", ofs);
223 } 223 }
224 html("'>"); 224 html("'>");
225 html_txt(name); 225 html_txt(name);
226 html("</a>"); 226 html("</a>");
227} 227}
228 228
229void cgit_commit_link(char *name, char *title, char *class, char *head, 229void cgit_commit_link(char *name, char *title, char *class, char *head,
230 char *rev) 230 char *rev)
231{ 231{
232 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 232 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
233 name[ctx.cfg.max_msg_len] = '\0'; 233 name[ctx.cfg.max_msg_len] = '\0';
234 name[ctx.cfg.max_msg_len - 1] = '.'; 234 name[ctx.cfg.max_msg_len - 1] = '.';
235 name[ctx.cfg.max_msg_len - 2] = '.'; 235 name[ctx.cfg.max_msg_len - 2] = '.';
236 name[ctx.cfg.max_msg_len - 3] = '.'; 236 name[ctx.cfg.max_msg_len - 3] = '.';
237 } 237 }
238 reporevlink("commit", name, title, class, head, rev, NULL); 238 reporevlink("commit", name, title, class, head, rev, NULL);
239} 239}
240 240
241void cgit_refs_link(char *name, char *title, char *class, char *head, 241void cgit_refs_link(char *name, char *title, char *class, char *head,
242 char *rev, char *path) 242 char *rev, char *path)
243{ 243{
244 reporevlink("refs", name, title, class, head, rev, path); 244 reporevlink("refs", name, title, class, head, rev, path);
245} 245}
246 246
247void cgit_snapshot_link(char *name, char *title, char *class, char *head, 247void cgit_snapshot_link(char *name, char *title, char *class, char *head,
248 char *rev, char *archivename) 248 char *rev, char *archivename)
249{ 249{
250 reporevlink("snapshot", name, title, class, head, rev, archivename); 250 reporevlink("snapshot", name, title, class, head, rev, archivename);
251} 251}
252 252
253void cgit_diff_link(char *name, char *title, char *class, char *head, 253void cgit_diff_link(char *name, char *title, char *class, char *head,
254 char *new_rev, char *old_rev, char *path) 254 char *new_rev, char *old_rev, char *path)
255{ 255{
256 char *delim; 256 char *delim;
257 257
258 delim = repolink(title, class, "diff", head, path); 258 delim = repolink(title, class, "diff", head, path);
259 if (new_rev && strcmp(new_rev, ctx.qry.head)) { 259 if (new_rev && strcmp(new_rev, ctx.qry.head)) {
260 html(delim); 260 html(delim);
261 html("id="); 261 html("id=");
262 html_attr(new_rev); 262 html_attr(new_rev);
263 delim = "&amp;"; 263 delim = "&amp;";
264 } 264 }
265 if (old_rev) { 265 if (old_rev) {
266 html(delim); 266 html(delim);
267 html("id2="); 267 html("id2=");
268 html_attr(old_rev); 268 html_attr(old_rev);
269 } 269 }
270 html("'>"); 270 html("'>");
271 html_txt(name); 271 html_txt(name);
272 html("</a>"); 272 html("</a>");
273} 273}
274 274
275void cgit_patch_link(char *name, char *title, char *class, char *head, 275void cgit_patch_link(char *name, char *title, char *class, char *head,
276 char *rev) 276 char *rev)
277{ 277{
278 reporevlink("patch", name, title, class, head, rev, NULL); 278 reporevlink("patch", name, title, class, head, rev, NULL);
279} 279}
280 280
281void cgit_object_link(struct object *obj) 281void cgit_object_link(struct object *obj)
282{ 282{
283 char *page, *arg, *url; 283 char *page, *arg, *url;
284 284
285 if (obj->type == OBJ_COMMIT) { 285 if (obj->type == OBJ_COMMIT) {
286 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 286 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
287 ctx.qry.head, sha1_to_hex(obj->sha1)); 287 ctx.qry.head, sha1_to_hex(obj->sha1));
288 return; 288 return;
289 } else if (obj->type == OBJ_TREE) { 289 } else if (obj->type == OBJ_TREE) {
290 page = "tree"; 290 page = "tree";
291 arg = "id"; 291 arg = "id";
292 } else if (obj->type == OBJ_TAG) { 292 } else if (obj->type == OBJ_TAG) {
293 page = "tag"; 293 page = "tag";
294 arg = "id"; 294 arg = "id";
295 } else { 295 } else {
296 page = "blob"; 296 page = "blob";
297 arg = "id"; 297 arg = "id";
298 } 298 }
299 299
300 url = cgit_pageurl(ctx.qry.repo, page, 300 url = cgit_pageurl(ctx.qry.repo, page,
301 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 301 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
302 html_link_open(url, NULL, NULL); 302 html_link_open(url, NULL, NULL);
303 htmlf("%s %s", typename(obj->type), 303 htmlf("%s %s", typename(obj->type),
304 sha1_to_hex(obj->sha1)); 304 sha1_to_hex(obj->sha1));
305 html_link_close(); 305 html_link_close();
306} 306}
307 307
308void cgit_print_date(time_t secs, char *format) 308void cgit_print_date(time_t secs, char *format)
309{ 309{
310 char buf[64]; 310 char buf[64];
311 struct tm *time; 311 struct tm *time;
312 312
313 if (!secs) 313 if (!secs)
314 return; 314 return;
315 time = gmtime(&secs); 315 time = gmtime(&secs);
316 strftime(buf, sizeof(buf)-1, format, time); 316 strftime(buf, sizeof(buf)-1, format, time);
317 html_txt(buf); 317 html_txt(buf);
318} 318}
319 319
320void cgit_print_age(time_t t, time_t max_relative, char *format) 320void cgit_print_age(time_t t, time_t max_relative, char *format)
321{ 321{
322 time_t now, secs; 322 time_t now, secs;
323 323
324 if (!t) 324 if (!t)
325 return; 325 return;
326 time(&now); 326 time(&now);
327 secs = now - t; 327 secs = now - t;
328 328
329 if (secs > max_relative && max_relative >= 0) { 329 if (secs > max_relative && max_relative >= 0) {
330 cgit_print_date(t, format); 330 cgit_print_date(t, format);
331 return; 331 return;
332 } 332 }
333 333
334 if (secs < TM_HOUR * 2) { 334 if (secs < TM_HOUR * 2) {
335 htmlf("<span class='age-mins'>%.0f min.</span>", 335 htmlf("<span class='age-mins'>%.0f min.</span>",
336 secs * 1.0 / TM_MIN); 336 secs * 1.0 / TM_MIN);
337 return; 337 return;
338 } 338 }
339 if (secs < TM_DAY * 2) { 339 if (secs < TM_DAY * 2) {
340 htmlf("<span class='age-hours'>%.0f hours</span>", 340 htmlf("<span class='age-hours'>%.0f hours</span>",
341 secs * 1.0 / TM_HOUR); 341 secs * 1.0 / TM_HOUR);
342 return; 342 return;
343 } 343 }
344 if (secs < TM_WEEK * 2) { 344 if (secs < TM_WEEK * 2) {
345 htmlf("<span class='age-days'>%.0f days</span>", 345 htmlf("<span class='age-days'>%.0f days</span>",
346 secs * 1.0 / TM_DAY); 346 secs * 1.0 / TM_DAY);
347 return; 347 return;
348 } 348 }
349 if (secs < TM_MONTH * 2) { 349 if (secs < TM_MONTH * 2) {
350 htmlf("<span class='age-weeks'>%.0f weeks</span>", 350 htmlf("<span class='age-weeks'>%.0f weeks</span>",
351 secs * 1.0 / TM_WEEK); 351 secs * 1.0 / TM_WEEK);
352 return; 352 return;
353 } 353 }
354 if (secs < TM_YEAR * 2) { 354 if (secs < TM_YEAR * 2) {
355 htmlf("<span class='age-months'>%.0f months</span>", 355 htmlf("<span class='age-months'>%.0f months</span>",
356 secs * 1.0 / TM_MONTH); 356 secs * 1.0 / TM_MONTH);
357 return; 357 return;
358 } 358 }
359 htmlf("<span class='age-years'>%.0f years</span>", 359 htmlf("<span class='age-years'>%.0f years</span>",
360 secs * 1.0 / TM_YEAR); 360 secs * 1.0 / TM_YEAR);
361} 361}
362 362
363void cgit_print_docstart(char *title, struct cacheitem *item) 363void cgit_print_docstart(char *title, struct cacheitem *item)
364{ 364{
365 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 365 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
367 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 367 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
368 ttl_seconds(item->ttl))); 368 ttl_seconds(item->ttl)));
369 html("\n"); 369 html("\n");
370 html(cgit_doctype); 370 html(cgit_doctype);
371 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 371 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
372 html("<head>\n"); 372 html("<head>\n");
373 html("<title>"); 373 html("<title>");
374 html_txt(title); 374 html_txt(title);
375 html("</title>\n"); 375 html("</title>\n");
376 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 376 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
377 if (ctx.cfg.robots && *ctx.cfg.robots) 377 if (ctx.cfg.robots && *ctx.cfg.robots)
378 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); 378 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
379 html("<link rel='stylesheet' type='text/css' href='"); 379 html("<link rel='stylesheet' type='text/css' href='");
380 html_attr(ctx.cfg.css); 380 html_attr(ctx.cfg.css);
381 html("'/>\n"); 381 html("'/>\n");
382 html("</head>\n"); 382 html("</head>\n");
383 html("<body>\n"); 383 html("<body>\n");
384} 384}
385 385
386void cgit_print_docend() 386void cgit_print_docend()
387{ 387{
388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); 388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
389} 389}
390 390
391int print_branch_option(const char *refname, const unsigned char *sha1, 391int print_branch_option(const char *refname, const unsigned char *sha1,
392 int flags, void *cb_data) 392 int flags, void *cb_data)
393{ 393{
394 char *name = (char *)refname; 394 char *name = (char *)refname;
395 html_option(name, name, ctx.qry.head); 395 html_option(name, name, ctx.qry.head);
396 return 0; 396 return 0;
397} 397}
398 398
399int print_archive_ref(const char *refname, const unsigned char *sha1, 399int print_archive_ref(const char *refname, const unsigned char *sha1,
400 int flags, void *cb_data) 400 int flags, void *cb_data)
401{ 401{
402 struct tag *tag; 402 struct tag *tag;
403 struct taginfo *info; 403 struct taginfo *info;
404 struct object *obj; 404 struct object *obj;
405 char buf[256], *url; 405 char buf[256], *url;
406 unsigned char fileid[20]; 406 unsigned char fileid[20];
407 int *header = (int *)cb_data; 407 int *header = (int *)cb_data;
408 408
409 if (prefixcmp(refname, "refs/archives")) 409 if (prefixcmp(refname, "refs/archives"))
410 return 0; 410 return 0;
411 strncpy(buf, refname+14, sizeof(buf)); 411 strncpy(buf, refname+14, sizeof(buf));
412 obj = parse_object(sha1); 412 obj = parse_object(sha1);
413 if (!obj) 413 if (!obj)
414 return 1; 414 return 1;
415 if (obj->type == OBJ_TAG) { 415 if (obj->type == OBJ_TAG) {
416 tag = lookup_tag(sha1); 416 tag = lookup_tag(sha1);
417 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 417 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
418 return 0; 418 return 0;
419 hashcpy(fileid, tag->tagged->sha1); 419 hashcpy(fileid, tag->tagged->sha1);
420 } else if (obj->type != OBJ_BLOB) { 420 } else if (obj->type != OBJ_BLOB) {
421 return 0; 421 return 0;
422 } else { 422 } else {
423 hashcpy(fileid, sha1); 423 hashcpy(fileid, sha1);
424 } 424 }
425 if (!*header) { 425 if (!*header) {
426 html("<h1>download</h1>\n"); 426 html("<h1>download</h1>\n");
427 *header = 1; 427 *header = 1;
428 } 428 }
429 url = cgit_pageurl(ctx.qry.repo, "blob", 429 url = cgit_pageurl(ctx.qry.repo, "blob",
430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
431 buf)); 431 buf));
432 html_link_open(url, NULL, "menu"); 432 html_link_open(url, NULL, "menu");
433 html_txt(strlpart(buf, 20)); 433 html_txt(strlpart(buf, 20));
434 html_link_close(); 434 html_link_close();
435 return 0; 435 return 0;
436} 436}
437 437
438void add_hidden_formfields(int incl_head, int incl_search, char *page) 438void add_hidden_formfields(int incl_head, int incl_search, char *page)
439{ 439{
440 char *url; 440 char *url;
441 441
442 if (!ctx.cfg.virtual_root) { 442 if (!ctx.cfg.virtual_root) {
443 url = fmt("%s/%s", ctx.qry.repo, page); 443 url = fmt("%s/%s", ctx.qry.repo, page);
444 if (ctx.qry.path) 444 if (ctx.qry.path)
445 url = fmt("%s/%s", url, ctx.qry.path); 445 url = fmt("%s/%s", url, ctx.qry.path);
446 html_hidden("url", url); 446 html_hidden("url", url);
447 } 447 }
448 448
449 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) 449 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch))
450 html_hidden("h", ctx.qry.head); 450 html_hidden("h", ctx.qry.head);
451 451
452 if (ctx.qry.sha1) 452 if (ctx.qry.sha1)
453 html_hidden("id", ctx.qry.sha1); 453 html_hidden("id", ctx.qry.sha1);
454 if (ctx.qry.sha2) 454 if (ctx.qry.sha2)
455 html_hidden("id2", ctx.qry.sha2); 455 html_hidden("id2", ctx.qry.sha2);
456 456
457 if (incl_search) { 457 if (incl_search) {
458 if (ctx.qry.grep) 458 if (ctx.qry.grep)
459 html_hidden("qt", ctx.qry.grep); 459 html_hidden("qt", ctx.qry.grep);
460 if (ctx.qry.search) 460 if (ctx.qry.search)
461 html_hidden("q", ctx.qry.search); 461 html_hidden("q", ctx.qry.search);
462 } 462 }
463} 463}
464 464
465void cgit_print_pageheader(char *title, int show_search) 465void cgit_print_pageheader(char *title, int show_search)
466{ 466{
467 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 467 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
468 int header = 0; 468 int header = 0;
469 char *url; 469 char *url;
470 470
471 html("<table id='layout' summary=''>\n"); 471 html("<table id='layout' summary=''>\n");
472 html("<tr><td id='sidebar'>\n"); 472 html("<tr><td id='sidebar'>\n");
473 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
474 html("<tr><td class='sidebar'>\n<a href='"); 474 html("<tr><td class='sidebar'>\n<a href='");
475 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
476 htmlf("'><img src='%s' alt='cgit'/></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
477 ctx.cfg.logo); 477 ctx.cfg.logo);
478 html("</td></tr>\n<tr><td class='sidebar'>\n"); 478 html("</td></tr>\n<tr><td class='sidebar'>\n");
479 if (ctx.qry.repo) { 479 if (ctx.repo) {
480 html("<h1 class='first'>"); 480 html("<h1 class='first'>");
481 html_txt(strrpart(ctx.repo->name, 20)); 481 html_txt(strrpart(ctx.repo->name, 20));
482 html("</h1>\n"); 482 html("</h1>\n");
483 html_txt(ctx.repo->desc); 483 html_txt(ctx.repo->desc);
484 if (ctx.repo->owner) { 484 if (ctx.repo->owner) {
485 html("<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");
486 html_txt(ctx.repo->owner); 486 html_txt(ctx.repo->owner);
487 } 487 }
488 html("<h1>navigate</h1>\n"); 488 html("<h1>navigate</h1>\n");
489 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, 489 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head,
490 NULL, NULL); 490 NULL, NULL);
491 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, 491 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL,
492 0, NULL, NULL); 492 0, NULL, NULL);
493 cgit_tree_link("tree", NULL, "menu", ctx.qry.head, 493 cgit_tree_link("tree", NULL, "menu", ctx.qry.head,
494 ctx.qry.sha1, NULL); 494 ctx.qry.sha1, NULL);
495 cgit_commit_link("commit", NULL, "menu", ctx.qry.head, 495 cgit_commit_link("commit", NULL, "menu", ctx.qry.head,
496 ctx.qry.sha1); 496 ctx.qry.sha1);
497 cgit_diff_link("diff", NULL, "menu", ctx.qry.head, 497 cgit_diff_link("diff", NULL, "menu", ctx.qry.head,
498 ctx.qry.sha1, ctx.qry.sha2, NULL); 498 ctx.qry.sha1, ctx.qry.sha2, NULL);
499 cgit_patch_link("patch", NULL, "menu", ctx.qry.head, 499 cgit_patch_link("patch", NULL, "menu", ctx.qry.head,
500 ctx.qry.sha1); 500 ctx.qry.sha1);
501 501
502 for_each_ref(print_archive_ref, &header); 502 for_each_ref(print_archive_ref, &header);
503 503
504 if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { 504 if (ctx.repo->clone_url || ctx.cfg.clone_prefix) {
505 html("<h1>clone</h1>\n"); 505 html("<h1>clone</h1>\n");
506 if (ctx.repo->clone_url) 506 if (ctx.repo->clone_url)
507 url = ctx.repo->clone_url; 507 url = ctx.repo->clone_url;
508 else 508 else
509 url = fmt("%s%s", ctx.cfg.clone_prefix, 509 url = fmt("%s%s", ctx.cfg.clone_prefix,
510 ctx.repo->url); 510 ctx.repo->url);
511 html("<a class='menu' href='"); 511 html("<a class='menu' href='");
512 html_attr(url); 512 html_attr(url);
513 html("' title='"); 513 html("' title='");
514 html_attr(url); 514 html_attr(url);
515 html("'>\n"); 515 html("'>\n");
516 html_txt(strrpart(url, 20)); 516 html_txt(strrpart(url, 20));
517 html("</a>\n"); 517 html("</a>\n");
518 } 518 }
519 519
520 html("<h1>branch</h1>\n"); 520 html("<h1>branch</h1>\n");
521 html("<form method='get' action=''>\n"); 521 html("<form method='get' action=''>\n");
522 add_hidden_formfields(0, 1, ctx.qry.page); 522 add_hidden_formfields(0, 1, ctx.qry.page);
523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
524 html("<select name='h' onchange='this.form.submit();'>\n"); 524 html("<select name='h' onchange='this.form.submit();'>\n");
525 for_each_branch_ref(print_branch_option, ctx.qry.head); 525 for_each_branch_ref(print_branch_option, ctx.qry.head);
526 html("</select>\n"); 526 html("</select>\n");
527 // html("</td><td>"); 527 // html("</td><td>");
528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
529 // html("</td></tr></table>"); 529 // html("</td></tr></table>");
530 html("</form>\n"); 530 html("</form>\n");
531 531
532 html("<h1>search</h1>\n"); 532 html("<h1>search</h1>\n");
533 html("<form method='get' action='"); 533 html("<form method='get' action='");
534 if (ctx.cfg.virtual_root) 534 if (ctx.cfg.virtual_root)
535 html_attr(cgit_fileurl(ctx.qry.repo, "log", 535 html_attr(cgit_fileurl(ctx.qry.repo, "log",
536 ctx.qry.path, NULL)); 536 ctx.qry.path, NULL));
537 html("'>\n"); 537 html("'>\n");
538 add_hidden_formfields(1, 0, "log"); 538 add_hidden_formfields(1, 0, "log");
539 html("<select name='qt'>\n"); 539 html("<select name='qt'>\n");
540 html_option("grep", "log msg", ctx.qry.grep); 540 html_option("grep", "log msg", ctx.qry.grep);
541 html_option("author", "author", ctx.qry.grep); 541 html_option("author", "author", ctx.qry.grep);
542 html_option("committer", "committer", ctx.qry.grep); 542 html_option("committer", "committer", ctx.qry.grep);
543 html("</select>\n"); 543 html("</select>\n");
544 html("<input class='txt' type='text' name='q' value='"); 544 html("<input class='txt' type='text' name='q' value='");
545 html_attr(ctx.qry.search); 545 html_attr(ctx.qry.search);
546 html("'/>\n"); 546 html("'/>\n");
547 html("</form>\n"); 547 html("</form>\n");
548 } else { 548 } else {
549 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) 549 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info))
550 html(default_info); 550 html(default_info);
551 } 551 }
552 552
553 html("</td></tr></table></td>\n"); 553 html("</td></tr></table></td>\n");
554 554
555 html("<td id='content'>\n"); 555 html("<td id='content'>\n");
556} 556}
557 557
558 558
559void cgit_print_snapshot_start(const char *mimetype, const char *filename, 559void cgit_print_snapshot_start(const char *mimetype, const char *filename,
560 struct cacheitem *item) 560 struct cacheitem *item)
561{ 561{
562 htmlf("Content-Type: %s\n", mimetype); 562 htmlf("Content-Type: %s\n", mimetype);
563 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 563 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
564 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 564 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
565 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 565 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
566 ttl_seconds(item->ttl))); 566 ttl_seconds(item->ttl)));
567 html("\n"); 567 html("\n");
568} 568}
569 569
570/* vim:set sw=8: */ 570/* vim:set sw=8: */