summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c50
-rw-r--r--cgit.h18
-rw-r--r--shared.c3
-rw-r--r--ui-blob.c4
-rw-r--r--ui-patch.c4
-rw-r--r--ui-repolist.c6
-rw-r--r--ui-shared.c112
-rw-r--r--ui-snapshot.c4
8 files changed, 113 insertions, 88 deletions
diff --git a/cgit.c b/cgit.c
index e6b4526..d0f6905 100644
--- a/cgit.c
+++ b/cgit.c
@@ -4,19 +4,22 @@
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 "cmd.h"
10 11
11static int cgit_prepare_cache(struct cacheitem *item) 12static int cgit_prepare_cache(struct cacheitem *item)
12{ 13{
13 if (!ctx.repo && ctx.qry.repo) { 14 if (!ctx.repo && ctx.qry.repo) {
14 char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); 15 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
15 cgit_print_docstart(title, item); 16 "Bad request");
16 cgit_print_pageheader(title, 0); 17 cgit_print_http_headers(&ctx);
18 cgit_print_docstart(&ctx);
19 cgit_print_pageheader(&ctx);
17 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); 20 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo));
18 cgit_print_docend(); 21 cgit_print_docend();
19 return 0; 22 return 0;
20 } 23 }
21 24
22 if (!ctx.repo) { 25 if (!ctx.repo) {
@@ -77,51 +80,55 @@ char *find_default_branch(struct cgit_repo *repo)
77 else 80 else
78 return info.first_ref; 81 return info.first_ref;
79} 82}
80 83
81static void cgit_print_repo_page(struct cacheitem *item) 84static void cgit_print_repo_page(struct cacheitem *item)
82{ 85{
83 char *title, *tmp; 86 char *tmp;
84 int show_search; 87 int show_search;
85 unsigned char sha1[20]; 88 unsigned char sha1[20];
86 int nongit = 0; 89 int nongit = 0;
87 90
88 setenv("GIT_DIR", ctx.repo->path, 1); 91 setenv("GIT_DIR", ctx.repo->path, 1);
89 setup_git_directory_gently(&nongit); 92 setup_git_directory_gently(&nongit);
90 if (nongit) { 93 if (nongit) {
91 title = fmt("%s - %s", ctx.cfg.root_title, "config error"); 94 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
95 "config error");
92 tmp = fmt("Not a git repository: '%s'", ctx.repo->path); 96 tmp = fmt("Not a git repository: '%s'", ctx.repo->path);
93 ctx.repo = NULL; 97 ctx.repo = NULL;
94 cgit_print_docstart(title, item); 98 cgit_print_http_headers(&ctx);
95 cgit_print_pageheader(title, 0); 99 cgit_print_docstart(&ctx);
100 cgit_print_pageheader(&ctx);
96 cgit_print_error(tmp); 101 cgit_print_error(tmp);
97 cgit_print_docend(); 102 cgit_print_docend();
98 return; 103 return;
99 } 104 }
100 105
101 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); 106 ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
102 show_search = 0; 107 show_search = 0;
103 108
104 if (!ctx.qry.head) { 109 if (!ctx.qry.head) {
105 ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); 110 ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
106 ctx.repo->defbranch = ctx.qry.head; 111 ctx.repo->defbranch = ctx.qry.head;
107 } 112 }
108 113
109 if (!ctx.qry.head) { 114 if (!ctx.qry.head) {
110 cgit_print_docstart(title, item); 115 cgit_print_http_headers(&ctx);
111 cgit_print_pageheader(title, 0); 116 cgit_print_docstart(&ctx);
117 cgit_print_pageheader(&ctx);
112 cgit_print_error("Repository seems to be empty"); 118 cgit_print_error("Repository seems to be empty");
113 cgit_print_docend(); 119 cgit_print_docend();
114 return; 120 return;
115 } 121 }
116 122
117 if (get_sha1(ctx.qry.head, sha1)) { 123 if (get_sha1(ctx.qry.head, sha1)) {
118 tmp = xstrdup(ctx.qry.head); 124 tmp = xstrdup(ctx.qry.head);
119 ctx.qry.head = ctx.repo->defbranch; 125 ctx.qry.head = ctx.repo->defbranch;
120 cgit_print_docstart(title, item); 126 cgit_print_http_headers(&ctx);
121 cgit_print_pageheader(title, 0); 127 cgit_print_docstart(&ctx);
128 cgit_print_pageheader(&ctx);
122 cgit_print_error(fmt("Invalid branch: %s", tmp)); 129 cgit_print_error(fmt("Invalid branch: %s", tmp));
123 cgit_print_docend(); 130 cgit_print_docend();
124 return; 131 return;
125 } 132 }
126 133
127 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { 134 if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) {
@@ -140,21 +147,22 @@ static void cgit_print_repo_page(struct cacheitem *item)
140 if (cgit_cmd == CMD_BLOB) { 147 if (cgit_cmd == CMD_BLOB) {
141 cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); 148 cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path);
142 return; 149 return;
143 } 150 }
144 151
145 show_search = (cgit_cmd == CMD_LOG); 152 show_search = (cgit_cmd == CMD_LOG);
146 cgit_print_docstart(title, item); 153 cgit_print_http_headers(&ctx);
154 cgit_print_docstart(&ctx);
147 if (!cgit_cmd) { 155 if (!cgit_cmd) {
148 cgit_print_pageheader("summary", show_search); 156 cgit_print_pageheader(&ctx);
149 cgit_print_summary(); 157 cgit_print_summary();
150 cgit_print_docend(); 158 cgit_print_docend();
151 return; 159 return;
152 } 160 }
153 161
154 cgit_print_pageheader(ctx.qry.page, show_search); 162 cgit_print_pageheader(&ctx);
155 163
156 switch(cgit_cmd) { 164 switch(cgit_cmd) {
157 case CMD_LOG: 165 case CMD_LOG:
158 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, 166 cgit_print_log(ctx.qry.sha1, ctx.qry.ofs,
159 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, 167 ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search,
160 ctx.qry.path, 1); 168 ctx.qry.path, 1);
@@ -177,25 +185,33 @@ static void cgit_print_repo_page(struct cacheitem *item)
177 default: 185 default:
178 cgit_print_error("Invalid request"); 186 cgit_print_error("Invalid request");
179 } 187 }
180 cgit_print_docend(); 188 cgit_print_docend();
181} 189}
182 190
191static long ttl_seconds(long ttl)
192{
193 if (ttl<0)
194 return 60 * 60 * 24 * 365;
195 else
196 return ttl * 60;
197}
198
183static void cgit_fill_cache(struct cacheitem *item, int use_cache) 199static void cgit_fill_cache(struct cacheitem *item, int use_cache)
184{ 200{
185 int stdout2; 201 int stdout2;
186 202
187 item->st.st_mtime = time(NULL);
188
189 if (use_cache) { 203 if (use_cache) {
190 stdout2 = chk_positive(dup(STDOUT_FILENO), 204 stdout2 = chk_positive(dup(STDOUT_FILENO),
191 "Preserving STDOUT"); 205 "Preserving STDOUT");
192 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 206 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
193 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 207 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
194 } 208 }
195 209
210 ctx.page.modified = time(NULL);
211 ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl);
196 if (ctx.repo) 212 if (ctx.repo)
197 cgit_print_repo_page(item); 213 cgit_print_repo_page(item);
198 else 214 else
199 cgit_print_repolist(item); 215 cgit_print_repolist(item);
200 216
201 if (use_cache) { 217 if (use_cache) {
diff --git a/cgit.h b/cgit.h
index 5b7ee1c..8ab8e07 100644
--- a/cgit.h
+++ b/cgit.h
@@ -171,16 +171,26 @@ struct cgit_config {
171 int snapshots; 171 int snapshots;
172 int summary_branches; 172 int summary_branches;
173 int summary_log; 173 int summary_log;
174 int summary_tags; 174 int summary_tags;
175}; 175};
176 176
177struct cgit_page {
178 time_t modified;
179 time_t expires;
180 char *mimetype;
181 char *charset;
182 char *filename;
183 char *title;
184};
185
177struct cgit_context { 186struct cgit_context {
178 struct cgit_query qry; 187 struct cgit_query qry;
179 struct cgit_config cfg; 188 struct cgit_config cfg;
180 struct cgit_repo *repo; 189 struct cgit_repo *repo;
190 struct cgit_page page;
181}; 191};
182 192
183extern const char *cgit_version; 193extern const char *cgit_version;
184 194
185extern struct cgit_repolist cgit_repolist; 195extern struct cgit_repolist cgit_repolist;
186extern struct cgit_context ctx; 196extern struct cgit_context ctx;
@@ -257,18 +267,16 @@ extern void cgit_diff_link(char *name, char *title, char *class, char *head,
257 267
258extern void cgit_object_link(struct object *obj); 268extern void cgit_object_link(struct object *obj);
259 269
260extern void cgit_print_error(char *msg); 270extern void cgit_print_error(char *msg);
261extern void cgit_print_date(time_t secs, char *format); 271extern void cgit_print_date(time_t secs, char *format);
262extern void cgit_print_age(time_t t, time_t max_relative, char *format); 272extern void cgit_print_age(time_t t, time_t max_relative, char *format);
263extern void cgit_print_docstart(char *title, struct cacheitem *item); 273extern void cgit_print_http_headers(struct cgit_context *ctx);
274extern void cgit_print_docstart(struct cgit_context *ctx);
264extern void cgit_print_docend(); 275extern void cgit_print_docend();
265extern void cgit_print_pageheader(char *title, int show_search); 276extern void cgit_print_pageheader(struct cgit_context *ctx);
266extern void cgit_print_snapshot_start(const char *mimetype,
267 const char *filename,
268 struct cacheitem *item);
269extern void cgit_print_filemode(unsigned short mode); 277extern void cgit_print_filemode(unsigned short mode);
270extern void cgit_print_branches(int maxcount); 278extern void cgit_print_branches(int maxcount);
271extern void cgit_print_tags(int maxcount); 279extern void cgit_print_tags(int maxcount);
272 280
273extern void cgit_print_repolist(struct cacheitem *item); 281extern void cgit_print_repolist(struct cacheitem *item);
274extern void cgit_print_summary(); 282extern void cgit_print_summary();
diff --git a/shared.c b/shared.c
index 76e10d0..539d533 100644
--- a/shared.c
+++ b/shared.c
@@ -32,12 +32,15 @@ void cgit_prepare_context(struct cgit_context *ctx)
32 ctx->cfg.max_repodesc_len = 60; 32 ctx->cfg.max_repodesc_len = 60;
33 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 33 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
34 ctx->cfg.renamelimit = -1; 34 ctx->cfg.renamelimit = -1;
35 ctx->cfg.robots = "index, nofollow"; 35 ctx->cfg.robots = "index, nofollow";
36 ctx->cfg.root_title = "Git repository browser"; 36 ctx->cfg.root_title = "Git repository browser";
37 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 37 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
38 ctx->page.mimetype = "text/html";
39 ctx->page.charset = PAGE_ENCODING;
40 ctx->page.filename = NULL;
38} 41}
39 42
40int cgit_get_cmd_index(const char *cmd) 43int cgit_get_cmd_index(const char *cmd)
41{ 44{
42 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 45 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
43 "snapshot", "tag", "refs", "patch", NULL}; 46 "snapshot", "tag", "refs", "patch", NULL};
diff --git a/ui-blob.c b/ui-blob.c
index be4fb88..bd44574 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -32,9 +32,11 @@ void cgit_print_blob(struct cacheitem *item, const char *hex, char *path)
32 if (!buf) { 32 if (!buf) {
33 cgit_print_error(fmt("Error reading object %s", hex)); 33 cgit_print_error(fmt("Error reading object %s", hex));
34 return; 34 return;
35 } 35 }
36 36
37 buf[size] = '\0'; 37 buf[size] = '\0';
38 cgit_print_snapshot_start("text/plain", path, item); 38 ctx.page.mimetype = "text/plain";
39 ctx.page.filename = path;
40 cgit_print_http_headers(&ctx);
39 write(htmlfd, buf, size); 41 write(htmlfd, buf, size);
40} 42}
diff --git a/ui-patch.c b/ui-patch.c
index d93426b..a77f3f6 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -89,13 +89,15 @@ void cgit_print_patch(char *hex, struct cacheitem *item)
89 return; 89 return;
90 } 90 }
91 info = cgit_parse_commit(commit); 91 info = cgit_parse_commit(commit);
92 hashcpy(old_sha1, commit->parents->item->object.sha1); 92 hashcpy(old_sha1, commit->parents->item->object.sha1);
93 93
94 patchname = fmt("%s.patch", sha1_to_hex(sha1)); 94 patchname = fmt("%s.patch", sha1_to_hex(sha1));
95 cgit_print_snapshot_start("text/plain", patchname, item); 95 ctx.page.mimetype = "text/plain";
96 ctx.page.filename = patchname;
97 cgit_print_http_headers(&ctx);
96 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); 98 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
97 htmlf("From: %s%s\n", info->author, info->author_email); 99 htmlf("From: %s%s\n", info->author, info->author_email);
98 html("Date: "); 100 html("Date: ");
99 cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n"); 101 cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n");
100 htmlf("Subject: %s\n\n", info->subject); 102 htmlf("Subject: %s\n\n", info->subject);
101 if (info->msg && *info->msg) { 103 if (info->msg && *info->msg) {
diff --git a/ui-repolist.c b/ui-repolist.c
index cd4e41d..e663585 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -48,14 +48,16 @@ void cgit_print_repolist(struct cacheitem *item)
48 int i, columns = 4; 48 int i, columns = 4;
49 char *last_group = NULL; 49 char *last_group = NULL;
50 50
51 if (ctx.cfg.enable_index_links) 51 if (ctx.cfg.enable_index_links)
52 columns++; 52 columns++;
53 53
54 cgit_print_docstart(ctx.cfg.root_title, item); 54 ctx.page.title = ctx.cfg.root_title;
55 cgit_print_pageheader(ctx.cfg.root_title, 0); 55 cgit_print_http_headers(&ctx);
56 cgit_print_docstart(&ctx);
57 cgit_print_pageheader(&ctx);
56 58
57 html("<table summary='repository list' class='list nowrap'>"); 59 html("<table summary='repository list' class='list nowrap'>");
58 if (ctx.cfg.index_header) { 60 if (ctx.cfg.index_header) {
59 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", 61 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>",
60 columns); 62 columns);
61 html_include(ctx.cfg.index_header); 63 html_include(ctx.cfg.index_header);
diff --git a/ui-shared.c b/ui-shared.c
index 2eff79d..2596023 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -23,20 +23,12 @@ static char *http_date(time_t t)
23 struct tm *tm = gmtime(&t); 23 struct tm *tm = gmtime(&t);
24 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 24 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
25 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 25 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
26 tm->tm_hour, tm->tm_min, tm->tm_sec); 26 tm->tm_hour, tm->tm_min, tm->tm_sec);
27} 27}
28 28
29static long ttl_seconds(long ttl)
30{
31 if (ttl<0)
32 return 60 * 60 * 24 * 365;
33 else
34 return ttl * 60;
35}
36
37void cgit_print_error(char *msg) 29void cgit_print_error(char *msg)
38{ 30{
39 html("<div class='error'>"); 31 html("<div class='error'>");
40 html_txt(msg); 32 html_txt(msg);
41 html("</div>\n"); 33 html("</div>\n");
42} 34}
@@ -358,30 +350,40 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
358 return; 350 return;
359 } 351 }
360 htmlf("<span class='age-years'>%.0f years</span>", 352 htmlf("<span class='age-years'>%.0f years</span>",
361 secs * 1.0 / TM_YEAR); 353 secs * 1.0 / TM_YEAR);
362} 354}
363 355
364void cgit_print_docstart(char *title, struct cacheitem *item) 356void cgit_print_http_headers(struct cgit_context *ctx)
365{ 357{
366 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 358 if (ctx->page.mimetype && ctx->page.charset)
367 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 359 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
368 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 360 ctx->page.charset);
369 ttl_seconds(item->ttl))); 361 else if (ctx->page.mimetype)
362 htmlf("Content-Type: %s\n", ctx->page.mimetype);
363 if (ctx->page.filename)
364 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
365 ctx->page.filename);
366 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
367 htmlf("Expires: %s\n", http_date(ctx->page.expires));
370 html("\n"); 368 html("\n");
369}
370
371void cgit_print_docstart(struct cgit_context *ctx)
372{
371 html(cgit_doctype); 373 html(cgit_doctype);
372 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 374 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
373 html("<head>\n"); 375 html("<head>\n");
374 html("<title>"); 376 html("<title>");
375 html_txt(title); 377 html_txt(ctx->page.title);
376 html("</title>\n"); 378 html("</title>\n");
377 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 379 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
378 if (ctx.cfg.robots && *ctx.cfg.robots) 380 if (ctx->cfg.robots && *ctx->cfg.robots)
379 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); 381 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
380 html("<link rel='stylesheet' type='text/css' href='"); 382 html("<link rel='stylesheet' type='text/css' href='");
381 html_attr(ctx.cfg.css); 383 html_attr(ctx->cfg.css);
382 html("'/>\n"); 384 html("'/>\n");
383 html("</head>\n"); 385 html("</head>\n");
384 html("<body>\n"); 386 html("<body>\n");
385} 387}
386 388
387void cgit_print_docend() 389void cgit_print_docend()
@@ -460,117 +462,105 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
460 html_hidden("qt", ctx.qry.grep); 462 html_hidden("qt", ctx.qry.grep);
461 if (ctx.qry.search) 463 if (ctx.qry.search)
462 html_hidden("q", ctx.qry.search); 464 html_hidden("q", ctx.qry.search);
463 } 465 }
464} 466}
465 467
466void cgit_print_pageheader(char *title, int show_search) 468void cgit_print_pageheader(struct cgit_context *ctx)
467{ 469{
468 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 470 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
469 int header = 0; 471 int header = 0;
470 char *url; 472 char *url;
471 473
472 html("<table id='layout' summary=''>\n"); 474 html("<table id='layout' summary=''>\n");
473 html("<tr><td id='sidebar'>\n"); 475 html("<tr><td id='sidebar'>\n");
474 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 476 html("<table class='sidebar' cellspacing='0' summary=''>\n");
475 html("<tr><td class='sidebar'>\n<a href='"); 477 html("<tr><td class='sidebar'>\n<a href='");
476 html_attr(cgit_rooturl()); 478 html_attr(cgit_rooturl());
477 htmlf("'><img src='%s' alt='cgit'/></a>\n", 479 htmlf("'><img src='%s' alt='cgit'/></a>\n",
478 ctx.cfg.logo); 480 ctx->cfg.logo);
479 html("</td></tr>\n<tr><td class='sidebar'>\n"); 481 html("</td></tr>\n<tr><td class='sidebar'>\n");
480 if (ctx.repo) { 482 if (ctx->repo) {
481 html("<h1 class='first'>"); 483 html("<h1 class='first'>");
482 html_txt(strrpart(ctx.repo->name, 20)); 484 html_txt(strrpart(ctx->repo->name, 20));
483 html("</h1>\n"); 485 html("</h1>\n");
484 html_txt(ctx.repo->desc); 486 html_txt(ctx->repo->desc);
485 if (ctx.repo->owner) { 487 if (ctx->repo->owner) {
486 html("<h1>owner</h1>\n"); 488 html("<h1>owner</h1>\n");
487 html_txt(ctx.repo->owner); 489 html_txt(ctx->repo->owner);
488 } 490 }
489 html("<h1>navigate</h1>\n"); 491 html("<h1>navigate</h1>\n");
490 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, 492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head,
491 NULL, NULL); 493 NULL, NULL);
492 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, 494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL,
493 0, NULL, NULL); 495 0, NULL, NULL);
494 cgit_tree_link("tree", NULL, "menu", ctx.qry.head, 496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head,
495 ctx.qry.sha1, NULL); 497 ctx->qry.sha1, NULL);
496 cgit_commit_link("commit", NULL, "menu", ctx.qry.head, 498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head,
497 ctx.qry.sha1); 499 ctx->qry.sha1);
498 cgit_diff_link("diff", NULL, "menu", ctx.qry.head, 500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head,
499 ctx.qry.sha1, ctx.qry.sha2, NULL); 501 ctx->qry.sha1, ctx->qry.sha2, NULL);
500 cgit_patch_link("patch", NULL, "menu", ctx.qry.head, 502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head,
501 ctx.qry.sha1); 503 ctx->qry.sha1);
502 504
503 for_each_ref(print_archive_ref, &header); 505 for_each_ref(print_archive_ref, &header);
504 506
505 if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { 507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) {
506 html("<h1>clone</h1>\n"); 508 html("<h1>clone</h1>\n");
507 if (ctx.repo->clone_url) 509 if (ctx->repo->clone_url)
508 url = ctx.repo->clone_url; 510 url = ctx->repo->clone_url;
509 else 511 else
510 url = fmt("%s%s", ctx.cfg.clone_prefix, 512 url = fmt("%s%s", ctx->cfg.clone_prefix,
511 ctx.repo->url); 513 ctx->repo->url);
512 html("<a class='menu' href='"); 514 html("<a class='menu' href='");
513 html_attr(url); 515 html_attr(url);
514 html("' title='"); 516 html("' title='");
515 html_attr(url); 517 html_attr(url);
516 html("'>\n"); 518 html("'>\n");
517 html_txt(strrpart(url, 20)); 519 html_txt(strrpart(url, 20));
518 html("</a>\n"); 520 html("</a>\n");
519 } 521 }
520 522
521 html("<h1>branch</h1>\n"); 523 html("<h1>branch</h1>\n");
522 html("<form method='get' action=''>\n"); 524 html("<form method='get' action=''>\n");
523 add_hidden_formfields(0, 1, ctx.qry.page); 525 add_hidden_formfields(0, 1, ctx->qry.page);
524 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 526 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
525 html("<select name='h' onchange='this.form.submit();'>\n"); 527 html("<select name='h' onchange='this.form.submit();'>\n");
526 for_each_branch_ref(print_branch_option, ctx.qry.head); 528 for_each_branch_ref(print_branch_option, ctx->qry.head);
527 html("</select>\n"); 529 html("</select>\n");
528 // html("</td><td>"); 530 // html("</td><td>");
529 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
530 // html("</td></tr></table>"); 532 // html("</td></tr></table>");
531 html("</form>\n"); 533 html("</form>\n");
532 534
533 html("<h1>search</h1>\n"); 535 html("<h1>search</h1>\n");
534 html("<form method='get' action='"); 536 html("<form method='get' action='");
535 if (ctx.cfg.virtual_root) 537 if (ctx->cfg.virtual_root)
536 html_attr(cgit_fileurl(ctx.qry.repo, "log", 538 html_attr(cgit_fileurl(ctx->qry.repo, "log",
537 ctx.qry.path, NULL)); 539 ctx->qry.path, NULL));
538 html("'>\n"); 540 html("'>\n");
539 add_hidden_formfields(1, 0, "log"); 541 add_hidden_formfields(1, 0, "log");
540 html("<select name='qt'>\n"); 542 html("<select name='qt'>\n");
541 html_option("grep", "log msg", ctx.qry.grep); 543 html_option("grep", "log msg", ctx->qry.grep);
542 html_option("author", "author", ctx.qry.grep); 544 html_option("author", "author", ctx->qry.grep);
543 html_option("committer", "committer", ctx.qry.grep); 545 html_option("committer", "committer", ctx->qry.grep);
544 html("</select>\n"); 546 html("</select>\n");
545 html("<input class='txt' type='text' name='q' value='"); 547 html("<input class='txt' type='text' name='q' value='");
546 html_attr(ctx.qry.search); 548 html_attr(ctx->qry.search);
547 html("'/>\n"); 549 html("'/>\n");
548 html("</form>\n"); 550 html("</form>\n");
549 } else { 551 } else {
550 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) 552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info))
551 html(default_info); 553 html(default_info);
552 } 554 }
553 555
554 html("</td></tr></table></td>\n"); 556 html("</td></tr></table></td>\n");
555 557
556 html("<td id='content'>\n"); 558 html("<td id='content'>\n");
557} 559}
558 560
559
560void cgit_print_snapshot_start(const char *mimetype, const char *filename,
561 struct cacheitem *item)
562{
563 htmlf("Content-Type: %s\n", mimetype);
564 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
565 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
566 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
567 ttl_seconds(item->ttl)));
568 html("\n");
569}
570
571void cgit_print_filemode(unsigned short mode) 561void cgit_print_filemode(unsigned short mode)
572{ 562{
573 if (S_ISDIR(mode)) 563 if (S_ISDIR(mode))
574 html("d"); 564 html("d");
575 else if (S_ISLNK(mode)) 565 else if (S_ISLNK(mode))
576 html("l"); 566 html("l");
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 67dbbdd..4449803 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -98,13 +98,15 @@ void cgit_print_snapshot(struct cacheitem *item, const char *head,
98 return;; 98 return;;
99 } 99 }
100 memset(&args,0,sizeof(args)); 100 memset(&args,0,sizeof(args));
101 args.base = fmt("%s/", prefix); 101 args.base = fmt("%s/", prefix);
102 args.tree = commit->tree; 102 args.tree = commit->tree;
103 args.time = commit->date; 103 args.time = commit->date;
104 cgit_print_snapshot_start(sat->mimetype, filename, item); 104 ctx.page.mimetype = xstrdup(sat->mimetype);
105 ctx.page.filename = xstrdup(filename);
106 cgit_print_http_headers(&ctx);
105 (*sat->write_func)(&args); 107 (*sat->write_func)(&args);
106 return; 108 return;
107 } 109 }
108 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 110 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
109} 111}
110 112