summaryrefslogtreecommitdiffabout
authorStefan Naewe <stefan.naewe@atlas-elektronik.com>2008-08-01 12:54:38 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-08-01 20:09:13 (UTC)
commit0f0ab148c6d444316af10e6b4c7a60630fed45d3 (patch) (unidiff)
treea52c08e648c5d656866cecf78e757f2f85211b19
parenta1266edfe6ec1fd678c8f6b60ffbd21d88ff5a93 (diff)
downloadcgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.zip
cgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.tar.gz
cgit-0f0ab148c6d444316af10e6b4c7a60630fed45d3.tar.bz2
Added `local-time` option to cgitrc
When `local-time` is set, commit, tag and patch timestamps will be printed in the servers timezone. Also, regardless of the value of `local-time`, these timestamps will now always show the timezone. Signed-off-by: Stefan Naewe <stefan.naewe@atlas-elektronik.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h3
-rw-r--r--ui-commit.c4
-rw-r--r--ui-patch.c2
-rw-r--r--ui-shared.c11
-rw-r--r--ui-shared.h2
-rw-r--r--ui-tag.c2
7 files changed, 17 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c
index e2d5edb..f49fffa 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,399 +1,402 @@
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 15
16const char *cgit_version = CGIT_VERSION; 16const char *cgit_version = CGIT_VERSION;
17 17
18void config_cb(const char *name, const char *value) 18void config_cb(const char *name, const char *value)
19{ 19{
20 if (!strcmp(name, "root-title")) 20 if (!strcmp(name, "root-title"))
21 ctx.cfg.root_title = xstrdup(value); 21 ctx.cfg.root_title = xstrdup(value);
22 else if (!strcmp(name, "root-desc")) 22 else if (!strcmp(name, "root-desc"))
23 ctx.cfg.root_desc = xstrdup(value); 23 ctx.cfg.root_desc = xstrdup(value);
24 else if (!strcmp(name, "root-readme")) 24 else if (!strcmp(name, "root-readme"))
25 ctx.cfg.root_readme = xstrdup(value); 25 ctx.cfg.root_readme = xstrdup(value);
26 else if (!strcmp(name, "css")) 26 else if (!strcmp(name, "css"))
27 ctx.cfg.css = xstrdup(value); 27 ctx.cfg.css = xstrdup(value);
28 else if (!strcmp(name, "favicon")) 28 else if (!strcmp(name, "favicon"))
29 ctx.cfg.favicon = xstrdup(value); 29 ctx.cfg.favicon = xstrdup(value);
30 else if (!strcmp(name, "footer")) 30 else if (!strcmp(name, "footer"))
31 ctx.cfg.footer = xstrdup(value); 31 ctx.cfg.footer = xstrdup(value);
32 else if (!strcmp(name, "logo")) 32 else if (!strcmp(name, "logo"))
33 ctx.cfg.logo = xstrdup(value); 33 ctx.cfg.logo = xstrdup(value);
34 else if (!strcmp(name, "index-header")) 34 else if (!strcmp(name, "index-header"))
35 ctx.cfg.index_header = xstrdup(value); 35 ctx.cfg.index_header = xstrdup(value);
36 else if (!strcmp(name, "index-info")) 36 else if (!strcmp(name, "index-info"))
37 ctx.cfg.index_info = xstrdup(value); 37 ctx.cfg.index_info = xstrdup(value);
38 else if (!strcmp(name, "logo-link")) 38 else if (!strcmp(name, "logo-link"))
39 ctx.cfg.logo_link = xstrdup(value); 39 ctx.cfg.logo_link = xstrdup(value);
40 else if (!strcmp(name, "module-link")) 40 else if (!strcmp(name, "module-link"))
41 ctx.cfg.module_link = xstrdup(value); 41 ctx.cfg.module_link = xstrdup(value);
42 else if (!strcmp(name, "virtual-root")) { 42 else if (!strcmp(name, "virtual-root")) {
43 ctx.cfg.virtual_root = trim_end(value, '/'); 43 ctx.cfg.virtual_root = trim_end(value, '/');
44 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 44 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
45 ctx.cfg.virtual_root = ""; 45 ctx.cfg.virtual_root = "";
46 } else if (!strcmp(name, "nocache")) 46 } else if (!strcmp(name, "nocache"))
47 ctx.cfg.nocache = atoi(value); 47 ctx.cfg.nocache = atoi(value);
48 else if (!strcmp(name, "snapshots")) 48 else if (!strcmp(name, "snapshots"))
49 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 49 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
50 else if (!strcmp(name, "enable-index-links")) 50 else if (!strcmp(name, "enable-index-links"))
51 ctx.cfg.enable_index_links = atoi(value); 51 ctx.cfg.enable_index_links = atoi(value);
52 else if (!strcmp(name, "enable-log-filecount")) 52 else if (!strcmp(name, "enable-log-filecount"))
53 ctx.cfg.enable_log_filecount = atoi(value); 53 ctx.cfg.enable_log_filecount = atoi(value);
54 else if (!strcmp(name, "enable-log-linecount")) 54 else if (!strcmp(name, "enable-log-linecount"))
55 ctx.cfg.enable_log_linecount = atoi(value); 55 ctx.cfg.enable_log_linecount = atoi(value);
56 else if (!strcmp(name, "cache-size")) 56 else if (!strcmp(name, "cache-size"))
57 ctx.cfg.cache_size = atoi(value); 57 ctx.cfg.cache_size = atoi(value);
58 else if (!strcmp(name, "cache-root")) 58 else if (!strcmp(name, "cache-root"))
59 ctx.cfg.cache_root = xstrdup(value); 59 ctx.cfg.cache_root = xstrdup(value);
60 else if (!strcmp(name, "cache-root-ttl")) 60 else if (!strcmp(name, "cache-root-ttl"))
61 ctx.cfg.cache_root_ttl = atoi(value); 61 ctx.cfg.cache_root_ttl = atoi(value);
62 else if (!strcmp(name, "cache-repo-ttl")) 62 else if (!strcmp(name, "cache-repo-ttl"))
63 ctx.cfg.cache_repo_ttl = atoi(value); 63 ctx.cfg.cache_repo_ttl = atoi(value);
64 else if (!strcmp(name, "cache-static-ttl")) 64 else if (!strcmp(name, "cache-static-ttl"))
65 ctx.cfg.cache_static_ttl = atoi(value); 65 ctx.cfg.cache_static_ttl = atoi(value);
66 else if (!strcmp(name, "cache-dynamic-ttl")) 66 else if (!strcmp(name, "cache-dynamic-ttl"))
67 ctx.cfg.cache_dynamic_ttl = atoi(value); 67 ctx.cfg.cache_dynamic_ttl = atoi(value);
68 else if (!strcmp(name, "max-message-length")) 68 else if (!strcmp(name, "max-message-length"))
69 ctx.cfg.max_msg_len = atoi(value); 69 ctx.cfg.max_msg_len = atoi(value);
70 else if (!strcmp(name, "max-repodesc-length")) 70 else if (!strcmp(name, "max-repodesc-length"))
71 ctx.cfg.max_repodesc_len = atoi(value); 71 ctx.cfg.max_repodesc_len = atoi(value);
72 else if (!strcmp(name, "max-repo-count")) 72 else if (!strcmp(name, "max-repo-count"))
73 ctx.cfg.max_repo_count = atoi(value); 73 ctx.cfg.max_repo_count = atoi(value);
74 else if (!strcmp(name, "max-commit-count")) 74 else if (!strcmp(name, "max-commit-count"))
75 ctx.cfg.max_commit_count = atoi(value); 75 ctx.cfg.max_commit_count = atoi(value);
76 else if (!strcmp(name, "summary-log")) 76 else if (!strcmp(name, "summary-log"))
77 ctx.cfg.summary_log = atoi(value); 77 ctx.cfg.summary_log = atoi(value);
78 else if (!strcmp(name, "summary-branches")) 78 else if (!strcmp(name, "summary-branches"))
79 ctx.cfg.summary_branches = atoi(value); 79 ctx.cfg.summary_branches = atoi(value);
80 else if (!strcmp(name, "summary-tags")) 80 else if (!strcmp(name, "summary-tags"))
81 ctx.cfg.summary_tags = atoi(value); 81 ctx.cfg.summary_tags = atoi(value);
82 else if (!strcmp(name, "agefile")) 82 else if (!strcmp(name, "agefile"))
83 ctx.cfg.agefile = xstrdup(value); 83 ctx.cfg.agefile = xstrdup(value);
84 else if (!strcmp(name, "renamelimit")) 84 else if (!strcmp(name, "renamelimit"))
85 ctx.cfg.renamelimit = atoi(value); 85 ctx.cfg.renamelimit = atoi(value);
86 else if (!strcmp(name, "robots")) 86 else if (!strcmp(name, "robots"))
87 ctx.cfg.robots = xstrdup(value); 87 ctx.cfg.robots = xstrdup(value);
88 else if (!strcmp(name, "clone-prefix")) 88 else if (!strcmp(name, "clone-prefix"))
89 ctx.cfg.clone_prefix = xstrdup(value); 89 ctx.cfg.clone_prefix = xstrdup(value);
90 else if (!strcmp(name, "local-time"))
91 ctx.cfg.local_time = atoi(value);
90 else if (!strcmp(name, "repo.group")) 92 else if (!strcmp(name, "repo.group"))
91 ctx.cfg.repo_group = xstrdup(value); 93 ctx.cfg.repo_group = xstrdup(value);
92 else if (!strcmp(name, "repo.url")) 94 else if (!strcmp(name, "repo.url"))
93 ctx.repo = cgit_add_repo(value); 95 ctx.repo = cgit_add_repo(value);
94 else if (!strcmp(name, "repo.name")) 96 else if (!strcmp(name, "repo.name"))
95 ctx.repo->name = xstrdup(value); 97 ctx.repo->name = xstrdup(value);
96 else if (ctx.repo && !strcmp(name, "repo.path")) 98 else if (ctx.repo && !strcmp(name, "repo.path"))
97 ctx.repo->path = trim_end(value, '/'); 99 ctx.repo->path = trim_end(value, '/');
98 else if (ctx.repo && !strcmp(name, "repo.clone-url")) 100 else if (ctx.repo && !strcmp(name, "repo.clone-url"))
99 ctx.repo->clone_url = xstrdup(value); 101 ctx.repo->clone_url = xstrdup(value);
100 else if (ctx.repo && !strcmp(name, "repo.desc")) 102 else if (ctx.repo && !strcmp(name, "repo.desc"))
101 ctx.repo->desc = xstrdup(value); 103 ctx.repo->desc = xstrdup(value);
102 else if (ctx.repo && !strcmp(name, "repo.owner")) 104 else if (ctx.repo && !strcmp(name, "repo.owner"))
103 ctx.repo->owner = xstrdup(value); 105 ctx.repo->owner = xstrdup(value);
104 else if (ctx.repo && !strcmp(name, "repo.defbranch")) 106 else if (ctx.repo && !strcmp(name, "repo.defbranch"))
105 ctx.repo->defbranch = xstrdup(value); 107 ctx.repo->defbranch = xstrdup(value);
106 else if (ctx.repo && !strcmp(name, "repo.snapshots")) 108 else if (ctx.repo && !strcmp(name, "repo.snapshots"))
107 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 109 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
108 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) 110 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
109 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 111 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
110 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) 112 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
111 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 113 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
112 else if (ctx.repo && !strcmp(name, "repo.module-link")) 114 else if (ctx.repo && !strcmp(name, "repo.module-link"))
113 ctx.repo->module_link= xstrdup(value); 115 ctx.repo->module_link= xstrdup(value);
114 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 116 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
115 if (*value == '/') 117 if (*value == '/')
116 ctx.repo->readme = xstrdup(value); 118 ctx.repo->readme = xstrdup(value);
117 else 119 else
118 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); 120 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
119 } else if (!strcmp(name, "include")) 121 } else if (!strcmp(name, "include"))
120 parse_configfile(value, config_cb); 122 parse_configfile(value, config_cb);
121} 123}
122 124
123static void querystring_cb(const char *name, const char *value) 125static void querystring_cb(const char *name, const char *value)
124{ 126{
125 if (!strcmp(name,"r")) { 127 if (!strcmp(name,"r")) {
126 ctx.qry.repo = xstrdup(value); 128 ctx.qry.repo = xstrdup(value);
127 ctx.repo = cgit_get_repoinfo(value); 129 ctx.repo = cgit_get_repoinfo(value);
128 } else if (!strcmp(name, "p")) { 130 } else if (!strcmp(name, "p")) {
129 ctx.qry.page = xstrdup(value); 131 ctx.qry.page = xstrdup(value);
130 } else if (!strcmp(name, "url")) { 132 } else if (!strcmp(name, "url")) {
131 cgit_parse_url(value); 133 cgit_parse_url(value);
132 } else if (!strcmp(name, "qt")) { 134 } else if (!strcmp(name, "qt")) {
133 ctx.qry.grep = xstrdup(value); 135 ctx.qry.grep = xstrdup(value);
134 } else if (!strcmp(name, "q")) { 136 } else if (!strcmp(name, "q")) {
135 ctx.qry.search = xstrdup(value); 137 ctx.qry.search = xstrdup(value);
136 } else if (!strcmp(name, "h")) { 138 } else if (!strcmp(name, "h")) {
137 ctx.qry.head = xstrdup(value); 139 ctx.qry.head = xstrdup(value);
138 ctx.qry.has_symref = 1; 140 ctx.qry.has_symref = 1;
139 } else if (!strcmp(name, "id")) { 141 } else if (!strcmp(name, "id")) {
140 ctx.qry.sha1 = xstrdup(value); 142 ctx.qry.sha1 = xstrdup(value);
141 ctx.qry.has_sha1 = 1; 143 ctx.qry.has_sha1 = 1;
142 } else if (!strcmp(name, "id2")) { 144 } else if (!strcmp(name, "id2")) {
143 ctx.qry.sha2 = xstrdup(value); 145 ctx.qry.sha2 = xstrdup(value);
144 ctx.qry.has_sha1 = 1; 146 ctx.qry.has_sha1 = 1;
145 } else if (!strcmp(name, "ofs")) { 147 } else if (!strcmp(name, "ofs")) {
146 ctx.qry.ofs = atoi(value); 148 ctx.qry.ofs = atoi(value);
147 } else if (!strcmp(name, "path")) { 149 } else if (!strcmp(name, "path")) {
148 ctx.qry.path = trim_end(value, '/'); 150 ctx.qry.path = trim_end(value, '/');
149 } else if (!strcmp(name, "name")) { 151 } else if (!strcmp(name, "name")) {
150 ctx.qry.name = xstrdup(value); 152 ctx.qry.name = xstrdup(value);
151 } else if (!strcmp(name, "mimetype")) { 153 } else if (!strcmp(name, "mimetype")) {
152 ctx.qry.mimetype = xstrdup(value); 154 ctx.qry.mimetype = xstrdup(value);
153 } 155 }
154} 156}
155 157
156static void prepare_context(struct cgit_context *ctx) 158static void prepare_context(struct cgit_context *ctx)
157{ 159{
158 memset(ctx, 0, sizeof(ctx)); 160 memset(ctx, 0, sizeof(ctx));
159 ctx->cfg.agefile = "info/web/last-modified"; 161 ctx->cfg.agefile = "info/web/last-modified";
160 ctx->cfg.nocache = 0; 162 ctx->cfg.nocache = 0;
161 ctx->cfg.cache_size = 0; 163 ctx->cfg.cache_size = 0;
162 ctx->cfg.cache_dynamic_ttl = 5; 164 ctx->cfg.cache_dynamic_ttl = 5;
163 ctx->cfg.cache_max_create_time = 5; 165 ctx->cfg.cache_max_create_time = 5;
164 ctx->cfg.cache_repo_ttl = 5; 166 ctx->cfg.cache_repo_ttl = 5;
165 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 167 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
166 ctx->cfg.cache_root_ttl = 5; 168 ctx->cfg.cache_root_ttl = 5;
167 ctx->cfg.cache_static_ttl = -1; 169 ctx->cfg.cache_static_ttl = -1;
168 ctx->cfg.css = "/cgit.css"; 170 ctx->cfg.css = "/cgit.css";
169 ctx->cfg.logo = "/git-logo.png"; 171 ctx->cfg.logo = "/git-logo.png";
172 ctx->cfg.local_time = 0;
170 ctx->cfg.max_repo_count = 50; 173 ctx->cfg.max_repo_count = 50;
171 ctx->cfg.max_commit_count = 50; 174 ctx->cfg.max_commit_count = 50;
172 ctx->cfg.max_lock_attempts = 5; 175 ctx->cfg.max_lock_attempts = 5;
173 ctx->cfg.max_msg_len = 80; 176 ctx->cfg.max_msg_len = 80;
174 ctx->cfg.max_repodesc_len = 80; 177 ctx->cfg.max_repodesc_len = 80;
175 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 178 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
176 ctx->cfg.renamelimit = -1; 179 ctx->cfg.renamelimit = -1;
177 ctx->cfg.robots = "index, nofollow"; 180 ctx->cfg.robots = "index, nofollow";
178 ctx->cfg.root_title = "Git repository browser"; 181 ctx->cfg.root_title = "Git repository browser";
179 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 182 ctx->cfg.root_desc = "a fast webinterface for the git dscm";
180 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 183 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
181 ctx->cfg.summary_branches = 10; 184 ctx->cfg.summary_branches = 10;
182 ctx->cfg.summary_log = 10; 185 ctx->cfg.summary_log = 10;
183 ctx->cfg.summary_tags = 10; 186 ctx->cfg.summary_tags = 10;
184 ctx->page.mimetype = "text/html"; 187 ctx->page.mimetype = "text/html";
185 ctx->page.charset = PAGE_ENCODING; 188 ctx->page.charset = PAGE_ENCODING;
186 ctx->page.filename = NULL; 189 ctx->page.filename = NULL;
187 ctx->page.modified = time(NULL); 190 ctx->page.modified = time(NULL);
188 ctx->page.expires = ctx->page.modified; 191 ctx->page.expires = ctx->page.modified;
189} 192}
190 193
191struct refmatch { 194struct refmatch {
192 char *req_ref; 195 char *req_ref;
193 char *first_ref; 196 char *first_ref;
194 int match; 197 int match;
195}; 198};
196 199
197int find_current_ref(const char *refname, const unsigned char *sha1, 200int find_current_ref(const char *refname, const unsigned char *sha1,
198 int flags, void *cb_data) 201 int flags, void *cb_data)
199{ 202{
200 struct refmatch *info; 203 struct refmatch *info;
201 204
202 info = (struct refmatch *)cb_data; 205 info = (struct refmatch *)cb_data;
203 if (!strcmp(refname, info->req_ref)) 206 if (!strcmp(refname, info->req_ref))
204 info->match = 1; 207 info->match = 1;
205 if (!info->first_ref) 208 if (!info->first_ref)
206 info->first_ref = xstrdup(refname); 209 info->first_ref = xstrdup(refname);
207 return info->match; 210 return info->match;
208} 211}
209 212
210char *find_default_branch(struct cgit_repo *repo) 213char *find_default_branch(struct cgit_repo *repo)
211{ 214{
212 struct refmatch info; 215 struct refmatch info;
213 char *ref; 216 char *ref;
214 217
215 info.req_ref = repo->defbranch; 218 info.req_ref = repo->defbranch;
216 info.first_ref = NULL; 219 info.first_ref = NULL;
217 info.match = 0; 220 info.match = 0;
218 for_each_branch_ref(find_current_ref, &info); 221 for_each_branch_ref(find_current_ref, &info);
219 if (info.match) 222 if (info.match)
220 ref = info.req_ref; 223 ref = info.req_ref;
221 else 224 else
222 ref = info.first_ref; 225 ref = info.first_ref;
223 if (ref) 226 if (ref)
224 ref = xstrdup(ref); 227 ref = xstrdup(ref);
225 return ref; 228 return ref;
226} 229}
227 230
228static int prepare_repo_cmd(struct cgit_context *ctx) 231static int prepare_repo_cmd(struct cgit_context *ctx)
229{ 232{
230 char *tmp; 233 char *tmp;
231 unsigned char sha1[20]; 234 unsigned char sha1[20];
232 int nongit = 0; 235 int nongit = 0;
233 236
234 setenv("GIT_DIR", ctx->repo->path, 1); 237 setenv("GIT_DIR", ctx->repo->path, 1);
235 setup_git_directory_gently(&nongit); 238 setup_git_directory_gently(&nongit);
236 if (nongit) { 239 if (nongit) {
237 ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, 240 ctx->page.title = fmt("%s - %s", ctx->cfg.root_title,
238 "config error"); 241 "config error");
239 tmp = fmt("Not a git repository: '%s'", ctx->repo->path); 242 tmp = fmt("Not a git repository: '%s'", ctx->repo->path);
240 ctx->repo = NULL; 243 ctx->repo = NULL;
241 cgit_print_http_headers(ctx); 244 cgit_print_http_headers(ctx);
242 cgit_print_docstart(ctx); 245 cgit_print_docstart(ctx);
243 cgit_print_pageheader(ctx); 246 cgit_print_pageheader(ctx);
244 cgit_print_error(tmp); 247 cgit_print_error(tmp);
245 cgit_print_docend(); 248 cgit_print_docend();
246 return 1; 249 return 1;
247 } 250 }
248 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); 251 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
249 252
250 if (!ctx->qry.head) { 253 if (!ctx->qry.head) {
251 ctx->qry.head = find_default_branch(ctx->repo); 254 ctx->qry.head = find_default_branch(ctx->repo);
252 ctx->repo->defbranch = ctx->qry.head; 255 ctx->repo->defbranch = ctx->qry.head;
253 } 256 }
254 257
255 if (!ctx->qry.head) { 258 if (!ctx->qry.head) {
256 cgit_print_http_headers(ctx); 259 cgit_print_http_headers(ctx);
257 cgit_print_docstart(ctx); 260 cgit_print_docstart(ctx);
258 cgit_print_pageheader(ctx); 261 cgit_print_pageheader(ctx);
259 cgit_print_error("Repository seems to be empty"); 262 cgit_print_error("Repository seems to be empty");
260 cgit_print_docend(); 263 cgit_print_docend();
261 return 1; 264 return 1;
262 } 265 }
263 266
264 if (get_sha1(ctx->qry.head, sha1)) { 267 if (get_sha1(ctx->qry.head, sha1)) {
265 tmp = xstrdup(ctx->qry.head); 268 tmp = xstrdup(ctx->qry.head);
266 ctx->qry.head = ctx->repo->defbranch; 269 ctx->qry.head = ctx->repo->defbranch;
267 cgit_print_http_headers(ctx); 270 cgit_print_http_headers(ctx);
268 cgit_print_docstart(ctx); 271 cgit_print_docstart(ctx);
269 cgit_print_pageheader(ctx); 272 cgit_print_pageheader(ctx);
270 cgit_print_error(fmt("Invalid branch: %s", tmp)); 273 cgit_print_error(fmt("Invalid branch: %s", tmp));
271 cgit_print_docend(); 274 cgit_print_docend();
272 return 1; 275 return 1;
273 } 276 }
274 return 0; 277 return 0;
275} 278}
276 279
277static void process_request(void *cbdata) 280static void process_request(void *cbdata)
278{ 281{
279 struct cgit_context *ctx = cbdata; 282 struct cgit_context *ctx = cbdata;
280 struct cgit_cmd *cmd; 283 struct cgit_cmd *cmd;
281 284
282 cmd = cgit_get_cmd(ctx); 285 cmd = cgit_get_cmd(ctx);
283 if (!cmd) { 286 if (!cmd) {
284 ctx->page.title = "cgit error"; 287 ctx->page.title = "cgit error";
285 ctx->repo = NULL; 288 ctx->repo = NULL;
286 cgit_print_http_headers(ctx); 289 cgit_print_http_headers(ctx);
287 cgit_print_docstart(ctx); 290 cgit_print_docstart(ctx);
288 cgit_print_pageheader(ctx); 291 cgit_print_pageheader(ctx);
289 cgit_print_error("Invalid request"); 292 cgit_print_error("Invalid request");
290 cgit_print_docend(); 293 cgit_print_docend();
291 return; 294 return;
292 } 295 }
293 296
294 if (cmd->want_repo && !ctx->repo) { 297 if (cmd->want_repo && !ctx->repo) {
295 cgit_print_http_headers(ctx); 298 cgit_print_http_headers(ctx);
296 cgit_print_docstart(ctx); 299 cgit_print_docstart(ctx);
297 cgit_print_pageheader(ctx); 300 cgit_print_pageheader(ctx);
298 cgit_print_error(fmt("No repository selected")); 301 cgit_print_error(fmt("No repository selected"));
299 cgit_print_docend(); 302 cgit_print_docend();
300 return; 303 return;
301 } 304 }
302 305
303 if (ctx->repo && prepare_repo_cmd(ctx)) 306 if (ctx->repo && prepare_repo_cmd(ctx))
304 return; 307 return;
305 308
306 if (cmd->want_layout) { 309 if (cmd->want_layout) {
307 cgit_print_http_headers(ctx); 310 cgit_print_http_headers(ctx);
308 cgit_print_docstart(ctx); 311 cgit_print_docstart(ctx);
309 cgit_print_pageheader(ctx); 312 cgit_print_pageheader(ctx);
310 } 313 }
311 314
312 cmd->fn(ctx); 315 cmd->fn(ctx);
313 316
314 if (cmd->want_layout) 317 if (cmd->want_layout)
315 cgit_print_docend(); 318 cgit_print_docend();
316} 319}
317 320
318static void cgit_parse_args(int argc, const char **argv) 321static void cgit_parse_args(int argc, const char **argv)
319{ 322{
320 int i; 323 int i;
321 324
322 for (i = 1; i < argc; i++) { 325 for (i = 1; i < argc; i++) {
323 if (!strncmp(argv[i], "--cache=", 8)) { 326 if (!strncmp(argv[i], "--cache=", 8)) {
324 ctx.cfg.cache_root = xstrdup(argv[i]+8); 327 ctx.cfg.cache_root = xstrdup(argv[i]+8);
325 } 328 }
326 if (!strcmp(argv[i], "--nocache")) { 329 if (!strcmp(argv[i], "--nocache")) {
327 ctx.cfg.nocache = 1; 330 ctx.cfg.nocache = 1;
328 } 331 }
329 if (!strncmp(argv[i], "--query=", 8)) { 332 if (!strncmp(argv[i], "--query=", 8)) {
330 ctx.qry.raw = xstrdup(argv[i]+8); 333 ctx.qry.raw = xstrdup(argv[i]+8);
331 } 334 }
332 if (!strncmp(argv[i], "--repo=", 7)) { 335 if (!strncmp(argv[i], "--repo=", 7)) {
333 ctx.qry.repo = xstrdup(argv[i]+7); 336 ctx.qry.repo = xstrdup(argv[i]+7);
334 } 337 }
335 if (!strncmp(argv[i], "--page=", 7)) { 338 if (!strncmp(argv[i], "--page=", 7)) {
336 ctx.qry.page = xstrdup(argv[i]+7); 339 ctx.qry.page = xstrdup(argv[i]+7);
337 } 340 }
338 if (!strncmp(argv[i], "--head=", 7)) { 341 if (!strncmp(argv[i], "--head=", 7)) {
339 ctx.qry.head = xstrdup(argv[i]+7); 342 ctx.qry.head = xstrdup(argv[i]+7);
340 ctx.qry.has_symref = 1; 343 ctx.qry.has_symref = 1;
341 } 344 }
342 if (!strncmp(argv[i], "--sha1=", 7)) { 345 if (!strncmp(argv[i], "--sha1=", 7)) {
343 ctx.qry.sha1 = xstrdup(argv[i]+7); 346 ctx.qry.sha1 = xstrdup(argv[i]+7);
344 ctx.qry.has_sha1 = 1; 347 ctx.qry.has_sha1 = 1;
345 } 348 }
346 if (!strncmp(argv[i], "--ofs=", 6)) { 349 if (!strncmp(argv[i], "--ofs=", 6)) {
347 ctx.qry.ofs = atoi(argv[i]+6); 350 ctx.qry.ofs = atoi(argv[i]+6);
348 } 351 }
349 } 352 }
350} 353}
351 354
352static int calc_ttl() 355static int calc_ttl()
353{ 356{
354 if (!ctx.repo) 357 if (!ctx.repo)
355 return ctx.cfg.cache_root_ttl; 358 return ctx.cfg.cache_root_ttl;
356 359
357 if (!ctx.qry.page) 360 if (!ctx.qry.page)
358 return ctx.cfg.cache_repo_ttl; 361 return ctx.cfg.cache_repo_ttl;
359 362
360 if (ctx.qry.has_symref) 363 if (ctx.qry.has_symref)
361 return ctx.cfg.cache_dynamic_ttl; 364 return ctx.cfg.cache_dynamic_ttl;
362 365
363 if (ctx.qry.has_sha1) 366 if (ctx.qry.has_sha1)
364 return ctx.cfg.cache_static_ttl; 367 return ctx.cfg.cache_static_ttl;
365 368
366 return ctx.cfg.cache_repo_ttl; 369 return ctx.cfg.cache_repo_ttl;
367} 370}
368 371
369int main(int argc, const char **argv) 372int main(int argc, const char **argv)
370{ 373{
371 const char *cgit_config_env = getenv("CGIT_CONFIG"); 374 const char *cgit_config_env = getenv("CGIT_CONFIG");
372 int err, ttl; 375 int err, ttl;
373 376
374 prepare_context(&ctx); 377 prepare_context(&ctx);
375 cgit_repolist.length = 0; 378 cgit_repolist.length = 0;
376 cgit_repolist.count = 0; 379 cgit_repolist.count = 0;
377 cgit_repolist.repos = NULL; 380 cgit_repolist.repos = NULL;
378 381
379 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 382 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
380 config_cb); 383 config_cb);
381 ctx.repo = NULL; 384 ctx.repo = NULL;
382 if (getenv("SCRIPT_NAME")) 385 if (getenv("SCRIPT_NAME"))
383 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); 386 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
384 if (getenv("QUERY_STRING")) 387 if (getenv("QUERY_STRING"))
385 ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); 388 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
386 cgit_parse_args(argc, argv); 389 cgit_parse_args(argc, argv);
387 http_parse_querystring(ctx.qry.raw, querystring_cb); 390 http_parse_querystring(ctx.qry.raw, querystring_cb);
388 391
389 ttl = calc_ttl(); 392 ttl = calc_ttl();
390 ctx.page.expires += ttl*60; 393 ctx.page.expires += ttl*60;
391 if (ctx.cfg.nocache) 394 if (ctx.cfg.nocache)
392 ctx.cfg.cache_size = 0; 395 ctx.cfg.cache_size = 0;
393 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 396 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
394 ctx.qry.raw, ttl, process_request, &ctx); 397 ctx.qry.raw, ttl, process_request, &ctx);
395 if (err) 398 if (err)
396 cgit_print_error(fmt("Error processing page: %s (%d)", 399 cgit_print_error(fmt("Error processing page: %s (%d)",
397 strerror(err), err)); 400 strerror(err), err));
398 return err; 401 return err;
399} 402}
diff --git a/cgit.h b/cgit.h
index 7881aca..b01fa31 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,238 +1,239 @@
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 <xdiff/xdiff.h> 18#include <xdiff/xdiff.h>
19#include <utf8.h> 19#include <utf8.h>
20 20
21 21
22/* 22/*
23 * Dateformats used on misc. pages 23 * Dateformats used on misc. pages
24 */ 24 */
25#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" 25#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
26#define FMT_SHORTDATE "%Y-%m-%d" 26#define FMT_SHORTDATE "%Y-%m-%d"
27 27
28 28
29/* 29/*
30 * Limits used for relative dates 30 * Limits used for relative dates
31 */ 31 */
32#define TM_MIN 60 32#define TM_MIN 60
33#define TM_HOUR (TM_MIN * 60) 33#define TM_HOUR (TM_MIN * 60)
34#define TM_DAY (TM_HOUR * 24) 34#define TM_DAY (TM_HOUR * 24)
35#define TM_WEEK (TM_DAY * 7) 35#define TM_WEEK (TM_DAY * 7)
36#define TM_YEAR (TM_DAY * 365) 36#define TM_YEAR (TM_DAY * 365)
37#define TM_MONTH (TM_YEAR / 12.0) 37#define TM_MONTH (TM_YEAR / 12.0)
38 38
39 39
40/* 40/*
41 * Default encoding 41 * Default encoding
42 */ 42 */
43#define PAGE_ENCODING "UTF-8" 43#define PAGE_ENCODING "UTF-8"
44 44
45typedef void (*configfn)(const char *name, const char *value); 45typedef void (*configfn)(const char *name, const char *value);
46typedef void (*filepair_fn)(struct diff_filepair *pair); 46typedef void (*filepair_fn)(struct diff_filepair *pair);
47typedef void (*linediff_fn)(char *line, int len); 47typedef void (*linediff_fn)(char *line, int len);
48 48
49struct cgit_repo { 49struct cgit_repo {
50 char *url; 50 char *url;
51 char *name; 51 char *name;
52 char *path; 52 char *path;
53 char *desc; 53 char *desc;
54 char *owner; 54 char *owner;
55 char *defbranch; 55 char *defbranch;
56 char *group; 56 char *group;
57 char *module_link; 57 char *module_link;
58 char *readme; 58 char *readme;
59 char *clone_url; 59 char *clone_url;
60 int snapshots; 60 int snapshots;
61 int enable_log_filecount; 61 int enable_log_filecount;
62 int enable_log_linecount; 62 int enable_log_linecount;
63}; 63};
64 64
65struct cgit_repolist { 65struct cgit_repolist {
66 int length; 66 int length;
67 int count; 67 int count;
68 struct cgit_repo *repos; 68 struct cgit_repo *repos;
69}; 69};
70 70
71struct commitinfo { 71struct commitinfo {
72 struct commit *commit; 72 struct commit *commit;
73 char *author; 73 char *author;
74 char *author_email; 74 char *author_email;
75 unsigned long author_date; 75 unsigned long author_date;
76 char *committer; 76 char *committer;
77 char *committer_email; 77 char *committer_email;
78 unsigned long committer_date; 78 unsigned long committer_date;
79 char *subject; 79 char *subject;
80 char *msg; 80 char *msg;
81 char *msg_encoding; 81 char *msg_encoding;
82}; 82};
83 83
84struct taginfo { 84struct taginfo {
85 char *tagger; 85 char *tagger;
86 char *tagger_email; 86 char *tagger_email;
87 int tagger_date; 87 int tagger_date;
88 char *msg; 88 char *msg;
89}; 89};
90 90
91struct refinfo { 91struct refinfo {
92 const char *refname; 92 const char *refname;
93 struct object *object; 93 struct object *object;
94 union { 94 union {
95 struct taginfo *tag; 95 struct taginfo *tag;
96 struct commitinfo *commit; 96 struct commitinfo *commit;
97 }; 97 };
98}; 98};
99 99
100struct reflist { 100struct reflist {
101 struct refinfo **refs; 101 struct refinfo **refs;
102 int alloc; 102 int alloc;
103 int count; 103 int count;
104}; 104};
105 105
106struct cgit_query { 106struct cgit_query {
107 int has_symref; 107 int has_symref;
108 int has_sha1; 108 int has_sha1;
109 char *raw; 109 char *raw;
110 char *repo; 110 char *repo;
111 char *page; 111 char *page;
112 char *search; 112 char *search;
113 char *grep; 113 char *grep;
114 char *head; 114 char *head;
115 char *sha1; 115 char *sha1;
116 char *sha2; 116 char *sha2;
117 char *path; 117 char *path;
118 char *name; 118 char *name;
119 char *mimetype; 119 char *mimetype;
120 int ofs; 120 int ofs;
121}; 121};
122 122
123struct cgit_config { 123struct cgit_config {
124 char *agefile; 124 char *agefile;
125 char *cache_root; 125 char *cache_root;
126 char *clone_prefix; 126 char *clone_prefix;
127 char *css; 127 char *css;
128 char *favicon; 128 char *favicon;
129 char *footer; 129 char *footer;
130 char *index_header; 130 char *index_header;
131 char *index_info; 131 char *index_info;
132 char *logo; 132 char *logo;
133 char *logo_link; 133 char *logo_link;
134 char *module_link; 134 char *module_link;
135 char *repo_group; 135 char *repo_group;
136 char *robots; 136 char *robots;
137 char *root_title; 137 char *root_title;
138 char *root_desc; 138 char *root_desc;
139 char *root_readme; 139 char *root_readme;
140 char *script_name; 140 char *script_name;
141 char *virtual_root; 141 char *virtual_root;
142 int cache_size; 142 int cache_size;
143 int cache_dynamic_ttl; 143 int cache_dynamic_ttl;
144 int cache_max_create_time; 144 int cache_max_create_time;
145 int cache_repo_ttl; 145 int cache_repo_ttl;
146 int cache_root_ttl; 146 int cache_root_ttl;
147 int cache_static_ttl; 147 int cache_static_ttl;
148 int enable_index_links; 148 int enable_index_links;
149 int enable_log_filecount; 149 int enable_log_filecount;
150 int enable_log_linecount; 150 int enable_log_linecount;
151 int local_time;
151 int max_repo_count; 152 int max_repo_count;
152 int max_commit_count; 153 int max_commit_count;
153 int max_lock_attempts; 154 int max_lock_attempts;
154 int max_msg_len; 155 int max_msg_len;
155 int max_repodesc_len; 156 int max_repodesc_len;
156 int nocache; 157 int nocache;
157 int renamelimit; 158 int renamelimit;
158 int snapshots; 159 int snapshots;
159 int summary_branches; 160 int summary_branches;
160 int summary_log; 161 int summary_log;
161 int summary_tags; 162 int summary_tags;
162}; 163};
163 164
164struct cgit_page { 165struct cgit_page {
165 time_t modified; 166 time_t modified;
166 time_t expires; 167 time_t expires;
167 char *mimetype; 168 char *mimetype;
168 char *charset; 169 char *charset;
169 char *filename; 170 char *filename;
170 char *title; 171 char *title;
171}; 172};
172 173
173struct cgit_context { 174struct cgit_context {
174 struct cgit_query qry; 175 struct cgit_query qry;
175 struct cgit_config cfg; 176 struct cgit_config cfg;
176 struct cgit_repo *repo; 177 struct cgit_repo *repo;
177 struct cgit_page page; 178 struct cgit_page page;
178}; 179};
179 180
180struct cgit_snapshot_format { 181struct cgit_snapshot_format {
181 const char *suffix; 182 const char *suffix;
182 const char *mimetype; 183 const char *mimetype;
183 write_archive_fn_t write_func; 184 write_archive_fn_t write_func;
184 int bit; 185 int bit;
185}; 186};
186 187
187extern const char *cgit_version; 188extern const char *cgit_version;
188 189
189extern struct cgit_repolist cgit_repolist; 190extern struct cgit_repolist cgit_repolist;
190extern struct cgit_context ctx; 191extern struct cgit_context ctx;
191extern const struct cgit_snapshot_format cgit_snapshot_formats[]; 192extern const struct cgit_snapshot_format cgit_snapshot_formats[];
192 193
193extern struct cgit_repo *cgit_add_repo(const char *url); 194extern struct cgit_repo *cgit_add_repo(const char *url);
194extern struct cgit_repo *cgit_get_repoinfo(const char *url); 195extern struct cgit_repo *cgit_get_repoinfo(const char *url);
195extern void cgit_repo_config_cb(const char *name, const char *value); 196extern void cgit_repo_config_cb(const char *name, const char *value);
196 197
197extern int chk_zero(int result, char *msg); 198extern int chk_zero(int result, char *msg);
198extern int chk_positive(int result, char *msg); 199extern int chk_positive(int result, char *msg);
199extern int chk_non_negative(int result, char *msg); 200extern int chk_non_negative(int result, char *msg);
200 201
201extern char *trim_end(const char *str, char c); 202extern char *trim_end(const char *str, char c);
202extern char *strlpart(char *txt, int maxlen); 203extern char *strlpart(char *txt, int maxlen);
203extern char *strrpart(char *txt, int maxlen); 204extern char *strrpart(char *txt, int maxlen);
204 205
205extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); 206extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
206extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, 207extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
207 int flags, void *cb_data); 208 int flags, void *cb_data);
208 209
209extern void *cgit_free_commitinfo(struct commitinfo *info); 210extern void *cgit_free_commitinfo(struct commitinfo *info);
210 211
211extern int cgit_diff_files(const unsigned char *old_sha1, 212extern int cgit_diff_files(const unsigned char *old_sha1,
212 const unsigned char *new_sha1, 213 const unsigned char *new_sha1,
213 linediff_fn fn); 214 linediff_fn fn);
214 215
215extern void cgit_diff_tree(const unsigned char *old_sha1, 216extern void cgit_diff_tree(const unsigned char *old_sha1,
216 const unsigned char *new_sha1, 217 const unsigned char *new_sha1,
217 filepair_fn fn, const char *prefix); 218 filepair_fn fn, const char *prefix);
218 219
219extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 220extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
220 221
221extern char *fmt(const char *format,...); 222extern char *fmt(const char *format,...);
222 223
223extern struct commitinfo *cgit_parse_commit(struct commit *commit); 224extern struct commitinfo *cgit_parse_commit(struct commit *commit);
224extern struct taginfo *cgit_parse_tag(struct tag *tag); 225extern struct taginfo *cgit_parse_tag(struct tag *tag);
225extern void cgit_parse_url(const char *url); 226extern void cgit_parse_url(const char *url);
226 227
227extern const char *cgit_repobasename(const char *reponame); 228extern const char *cgit_repobasename(const char *reponame);
228 229
229extern int cgit_parse_snapshots_mask(const char *str); 230extern int cgit_parse_snapshots_mask(const char *str);
230 231
231/* libgit.a either links against or compiles its own implementation of 232/* libgit.a either links against or compiles its own implementation of
232 * strcasestr(), and we'd like to reuse it. Simply re-declaring it 233 * strcasestr(), and we'd like to reuse it. Simply re-declaring it
233 * seems to do the trick. 234 * seems to do the trick.
234 */ 235 */
235extern char *strcasestr(const char *haystack, const char *needle); 236extern char *strcasestr(const char *haystack, const char *needle);
236 237
237 238
238#endif /* CGIT_H */ 239#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index 4bbb391..a6a85a4 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -1,102 +1,102 @@
1/* ui-commit.c: generate commit view 1/* ui-commit.c: generate commit view
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 "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12#include "ui-diff.h" 12#include "ui-diff.h"
13 13
14void cgit_print_commit(char *hex) 14void cgit_print_commit(char *hex)
15{ 15{
16 struct commit *commit, *parent; 16 struct commit *commit, *parent;
17 struct commitinfo *info; 17 struct commitinfo *info;
18 struct commit_list *p; 18 struct commit_list *p;
19 unsigned char sha1[20]; 19 unsigned char sha1[20];
20 char *tmp; 20 char *tmp;
21 int parents = 0; 21 int parents = 0;
22 22
23 if (!hex) 23 if (!hex)
24 hex = ctx.qry.head; 24 hex = ctx.qry.head;
25 25
26 if (get_sha1(hex, sha1)) { 26 if (get_sha1(hex, sha1)) {
27 cgit_print_error(fmt("Bad object id: %s", hex)); 27 cgit_print_error(fmt("Bad object id: %s", hex));
28 return; 28 return;
29 } 29 }
30 commit = lookup_commit_reference(sha1); 30 commit = lookup_commit_reference(sha1);
31 if (!commit) { 31 if (!commit) {
32 cgit_print_error(fmt("Bad commit reference: %s", hex)); 32 cgit_print_error(fmt("Bad commit reference: %s", hex));
33 return; 33 return;
34 } 34 }
35 info = cgit_parse_commit(commit); 35 info = cgit_parse_commit(commit);
36 36
37 html("<table summary='commit info' class='commit-info'>\n"); 37 html("<table summary='commit info' class='commit-info'>\n");
38 html("<tr><th>author</th><td>"); 38 html("<tr><th>author</th><td>");
39 html_txt(info->author); 39 html_txt(info->author);
40 html(" "); 40 html(" ");
41 html_txt(info->author_email); 41 html_txt(info->author_email);
42 html("</td><td class='right'>"); 42 html("</td><td class='right'>");
43 cgit_print_date(info->author_date, FMT_LONGDATE); 43 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
44 html("</td></tr>\n"); 44 html("</td></tr>\n");
45 html("<tr><th>committer</th><td>"); 45 html("<tr><th>committer</th><td>");
46 html_txt(info->committer); 46 html_txt(info->committer);
47 html(" "); 47 html(" ");
48 html_txt(info->committer_email); 48 html_txt(info->committer_email);
49 html("</td><td class='right'>"); 49 html("</td><td class='right'>");
50 cgit_print_date(info->committer_date, FMT_LONGDATE); 50 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
51 html("</td></tr>\n"); 51 html("</td></tr>\n");
52 html("<tr><th>commit</th><td colspan='2' class='sha1'>"); 52 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
53 tmp = sha1_to_hex(commit->object.sha1); 53 tmp = sha1_to_hex(commit->object.sha1);
54 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp); 54 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
55 html(" ("); 55 html(" (");
56 cgit_patch_link("patch", NULL, NULL, NULL, tmp); 56 cgit_patch_link("patch", NULL, NULL, NULL, tmp);
57 html(")</td></tr>\n"); 57 html(")</td></tr>\n");
58 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 58 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
59 tmp = xstrdup(hex); 59 tmp = xstrdup(hex);
60 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 60 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
61 ctx.qry.head, tmp, NULL); 61 ctx.qry.head, tmp, NULL);
62 html("</td></tr>\n"); 62 html("</td></tr>\n");
63 for (p = commit->parents; p ; p = p->next) { 63 for (p = commit->parents; p ; p = p->next) {
64 parent = lookup_commit_reference(p->item->object.sha1); 64 parent = lookup_commit_reference(p->item->object.sha1);
65 if (!parent) { 65 if (!parent) {
66 html("<tr><td colspan='3'>"); 66 html("<tr><td colspan='3'>");
67 cgit_print_error("Error reading parent commit"); 67 cgit_print_error("Error reading parent commit");
68 html("</td></tr>"); 68 html("</td></tr>");
69 continue; 69 continue;
70 } 70 }
71 html("<tr><th>parent</th>" 71 html("<tr><th>parent</th>"
72 "<td colspan='2' class='sha1'>"); 72 "<td colspan='2' class='sha1'>");
73 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, 73 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
74 ctx.qry.head, sha1_to_hex(p->item->object.sha1)); 74 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
75 html(" ("); 75 html(" (");
76 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, 76 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
77 sha1_to_hex(p->item->object.sha1), NULL); 77 sha1_to_hex(p->item->object.sha1), NULL);
78 html(")</td></tr>"); 78 html(")</td></tr>");
79 parents++; 79 parents++;
80 } 80 }
81 if (ctx.repo->snapshots) { 81 if (ctx.repo->snapshots) {
82 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 82 html("<tr><th>download</th><td colspan='2' class='sha1'>");
83 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, 83 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
84 hex, ctx.repo->snapshots); 84 hex, ctx.repo->snapshots);
85 html("</td></tr>"); 85 html("</td></tr>");
86 } 86 }
87 html("</table>\n"); 87 html("</table>\n");
88 html("<div class='commit-subject'>"); 88 html("<div class='commit-subject'>");
89 html_txt(info->subject); 89 html_txt(info->subject);
90 html("</div>"); 90 html("</div>");
91 html("<div class='commit-msg'>"); 91 html("<div class='commit-msg'>");
92 html_txt(info->msg); 92 html_txt(info->msg);
93 html("</div>"); 93 html("</div>");
94 if (parents < 3) { 94 if (parents < 3) {
95 if (parents) 95 if (parents)
96 tmp = sha1_to_hex(commit->parents->item->object.sha1); 96 tmp = sha1_to_hex(commit->parents->item->object.sha1);
97 else 97 else
98 tmp = NULL; 98 tmp = NULL;
99 cgit_print_diff(ctx.qry.sha1, tmp, NULL); 99 cgit_print_diff(ctx.qry.sha1, tmp, NULL);
100 } 100 }
101 cgit_free_commitinfo(info); 101 cgit_free_commitinfo(info);
102} 102}
diff --git a/ui-patch.c b/ui-patch.c
index c1c4ce3..e60877d 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -1,118 +1,118 @@
1/* ui-patch.c: generate patch view 1/* ui-patch.c: generate patch view
2 * 2 *
3 * Copyright (C) 2007 Lars Hjemli 3 * Copyright (C) 2007 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
13static void print_line(char *line, int len) 13static void print_line(char *line, int len)
14{ 14{
15 char c = line[len-1]; 15 char c = line[len-1];
16 16
17 line[len-1] = '\0'; 17 line[len-1] = '\0';
18 htmlf("%s\n", line); 18 htmlf("%s\n", line);
19 line[len-1] = c; 19 line[len-1] = c;
20} 20}
21 21
22static void header(unsigned char *sha1, char *path1, int mode1, 22static void header(unsigned char *sha1, char *path1, int mode1,
23 unsigned char *sha2, char *path2, int mode2) 23 unsigned char *sha2, char *path2, int mode2)
24{ 24{
25 char *abbrev1, *abbrev2; 25 char *abbrev1, *abbrev2;
26 int subproject; 26 int subproject;
27 27
28 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); 28 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
29 htmlf("diff --git a/%s b/%s\n", path1, path2); 29 htmlf("diff --git a/%s b/%s\n", path1, path2);
30 30
31 if (is_null_sha1(sha1)) 31 if (is_null_sha1(sha1))
32 path1 = "dev/null"; 32 path1 = "dev/null";
33 if (is_null_sha1(sha2)) 33 if (is_null_sha1(sha2))
34 path2 = "dev/null"; 34 path2 = "dev/null";
35 35
36 if (mode1 == 0) 36 if (mode1 == 0)
37 htmlf("new file mode %.6o\n", mode2); 37 htmlf("new file mode %.6o\n", mode2);
38 38
39 if (mode2 == 0) 39 if (mode2 == 0)
40 htmlf("deleted file mode %.6o\n", mode1); 40 htmlf("deleted file mode %.6o\n", mode1);
41 41
42 if (!subproject) { 42 if (!subproject) {
43 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); 43 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
44 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); 44 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
45 htmlf("index %s..%s", abbrev1, abbrev2); 45 htmlf("index %s..%s", abbrev1, abbrev2);
46 free(abbrev1); 46 free(abbrev1);
47 free(abbrev2); 47 free(abbrev2);
48 if (mode1 != 0 && mode2 != 0) { 48 if (mode1 != 0 && mode2 != 0) {
49 htmlf(" %.6o", mode1); 49 htmlf(" %.6o", mode1);
50 if (mode2 != mode1) 50 if (mode2 != mode1)
51 htmlf("..%.6o", mode2); 51 htmlf("..%.6o", mode2);
52 } 52 }
53 htmlf("\n--- a/%s\n", path1); 53 htmlf("\n--- a/%s\n", path1);
54 htmlf("+++ b/%s\n", path2); 54 htmlf("+++ b/%s\n", path2);
55 } 55 }
56} 56}
57 57
58static void filepair_cb(struct diff_filepair *pair) 58static void filepair_cb(struct diff_filepair *pair)
59{ 59{
60 header(pair->one->sha1, pair->one->path, pair->one->mode, 60 header(pair->one->sha1, pair->one->path, pair->one->mode,
61 pair->two->sha1, pair->two->path, pair->two->mode); 61 pair->two->sha1, pair->two->path, pair->two->mode);
62 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 62 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
63 if (S_ISGITLINK(pair->one->mode)) 63 if (S_ISGITLINK(pair->one->mode))
64 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 64 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
65 if (S_ISGITLINK(pair->two->mode)) 65 if (S_ISGITLINK(pair->two->mode))
66 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 66 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
67 return; 67 return;
68 } 68 }
69 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) 69 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
70 html("Error running diff"); 70 html("Error running diff");
71} 71}
72 72
73void cgit_print_patch(char *hex) 73void cgit_print_patch(char *hex)
74{ 74{
75 struct commit *commit; 75 struct commit *commit;
76 struct commitinfo *info; 76 struct commitinfo *info;
77 unsigned char sha1[20], old_sha1[20]; 77 unsigned char sha1[20], old_sha1[20];
78 char *patchname; 78 char *patchname;
79 79
80 if (!hex) 80 if (!hex)
81 hex = ctx.qry.head; 81 hex = ctx.qry.head;
82 82
83 if (get_sha1(hex, sha1)) { 83 if (get_sha1(hex, sha1)) {
84 cgit_print_error(fmt("Bad object id: %s", hex)); 84 cgit_print_error(fmt("Bad object id: %s", hex));
85 return; 85 return;
86 } 86 }
87 commit = lookup_commit_reference(sha1); 87 commit = lookup_commit_reference(sha1);
88 if (!commit) { 88 if (!commit) {
89 cgit_print_error(fmt("Bad commit reference: %s", hex)); 89 cgit_print_error(fmt("Bad commit reference: %s", hex));
90 return; 90 return;
91 } 91 }
92 info = cgit_parse_commit(commit); 92 info = cgit_parse_commit(commit);
93 93
94 if (commit->parents && commit->parents->item) 94 if (commit->parents && commit->parents->item)
95 hashcpy(old_sha1, commit->parents->item->object.sha1); 95 hashcpy(old_sha1, commit->parents->item->object.sha1);
96 else 96 else
97 hashclr(old_sha1); 97 hashclr(old_sha1);
98 98
99 patchname = fmt("%s.patch", sha1_to_hex(sha1)); 99 patchname = fmt("%s.patch", sha1_to_hex(sha1));
100 ctx.page.mimetype = "text/plain"; 100 ctx.page.mimetype = "text/plain";
101 ctx.page.filename = patchname; 101 ctx.page.filename = patchname;
102 cgit_print_http_headers(&ctx); 102 cgit_print_http_headers(&ctx);
103 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); 103 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
104 htmlf("From: %s%s\n", info->author, info->author_email); 104 htmlf("From: %s%s\n", info->author, info->author_email);
105 html("Date: "); 105 html("Date: ");
106 cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n"); 106 cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
107 htmlf("Subject: %s\n\n", info->subject); 107 htmlf("Subject: %s\n\n", info->subject);
108 if (info->msg && *info->msg) { 108 if (info->msg && *info->msg) {
109 htmlf("%s", info->msg); 109 htmlf("%s", info->msg);
110 if (info->msg[strlen(info->msg) - 1] != '\n') 110 if (info->msg[strlen(info->msg) - 1] != '\n')
111 html("\n"); 111 html("\n");
112 } 112 }
113 html("---\n"); 113 html("---\n");
114 cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); 114 cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL);
115 html("--\n"); 115 html("--\n");
116 htmlf("cgit %s\n", CGIT_VERSION); 116 htmlf("cgit %s\n", CGIT_VERSION);
117 cgit_free_commitinfo(info); 117 cgit_free_commitinfo(info);
118} 118}
diff --git a/ui-shared.c b/ui-shared.c
index 4280a70..197ee37 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,673 +1,676 @@
1/* ui-shared.c: common web output functions 1/* ui-shared.c: common web output functions
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 "cmd.h" 10#include "cmd.h"
11#include "html.h" 11#include "html.h"
12 12
13const char cgit_doctype[] = 13const char cgit_doctype[] =
14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
16 16
17static char *http_date(time_t t) 17static char *http_date(time_t t)
18{ 18{
19 static char day[][4] = 19 static char day[][4] =
20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
21 static char month[][4] = 21 static char month[][4] =
22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
24 struct tm *tm = gmtime(&t); 24 struct tm *tm = gmtime(&t);
25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
27 tm->tm_hour, tm->tm_min, tm->tm_sec); 27 tm->tm_hour, tm->tm_min, tm->tm_sec);
28} 28}
29 29
30void cgit_print_error(char *msg) 30void cgit_print_error(char *msg)
31{ 31{
32 html("<div class='error'>"); 32 html("<div class='error'>");
33 html_txt(msg); 33 html_txt(msg);
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_rooturl() 37char *cgit_rooturl()
38{ 38{
39 if (ctx.cfg.virtual_root) 39 if (ctx.cfg.virtual_root)
40 return fmt("%s/", ctx.cfg.virtual_root); 40 return fmt("%s/", ctx.cfg.virtual_root);
41 else 41 else
42 return ctx.cfg.script_name; 42 return ctx.cfg.script_name;
43} 43}
44 44
45char *cgit_repourl(const char *reponame) 45char *cgit_repourl(const char *reponame)
46{ 46{
47 if (ctx.cfg.virtual_root) { 47 if (ctx.cfg.virtual_root) {
48 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); 48 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
49 } else { 49 } else {
50 return fmt("?r=%s", reponame); 50 return fmt("?r=%s", reponame);
51 } 51 }
52} 52}
53 53
54char *cgit_fileurl(const char *reponame, const char *pagename, 54char *cgit_fileurl(const char *reponame, const char *pagename,
55 const char *filename, const char *query) 55 const char *filename, const char *query)
56{ 56{
57 char *tmp; 57 char *tmp;
58 char *delim; 58 char *delim;
59 59
60 if (ctx.cfg.virtual_root) { 60 if (ctx.cfg.virtual_root) {
61 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, 61 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
62 pagename, (filename ? filename:"")); 62 pagename, (filename ? filename:""));
63 delim = "?"; 63 delim = "?";
64 } else { 64 } else {
65 tmp = fmt("?url=%s/%s/%s", reponame, pagename, 65 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
66 (filename ? filename : "")); 66 (filename ? filename : ""));
67 delim = "&"; 67 delim = "&";
68 } 68 }
69 if (query) 69 if (query)
70 tmp = fmt("%s%s%s", tmp, delim, query); 70 tmp = fmt("%s%s%s", tmp, delim, query);
71 return tmp; 71 return tmp;
72} 72}
73 73
74char *cgit_pageurl(const char *reponame, const char *pagename, 74char *cgit_pageurl(const char *reponame, const char *pagename,
75 const char *query) 75 const char *query)
76{ 76{
77 return cgit_fileurl(reponame,pagename,0,query); 77 return cgit_fileurl(reponame,pagename,0,query);
78} 78}
79 79
80const char *cgit_repobasename(const char *reponame) 80const char *cgit_repobasename(const char *reponame)
81{ 81{
82 /* I assume we don't need to store more than one repo basename */ 82 /* I assume we don't need to store more than one repo basename */
83 static char rvbuf[1024]; 83 static char rvbuf[1024];
84 int p; 84 int p;
85 const char *rv; 85 const char *rv;
86 strncpy(rvbuf,reponame,sizeof(rvbuf)); 86 strncpy(rvbuf,reponame,sizeof(rvbuf));
87 if(rvbuf[sizeof(rvbuf)-1]) 87 if(rvbuf[sizeof(rvbuf)-1])
88 die("cgit_repobasename: truncated repository name '%s'", reponame); 88 die("cgit_repobasename: truncated repository name '%s'", reponame);
89 p = strlen(rvbuf)-1; 89 p = strlen(rvbuf)-1;
90 /* strip trailing slashes */ 90 /* strip trailing slashes */
91 while(p && rvbuf[p]=='/') rvbuf[p--]=0; 91 while(p && rvbuf[p]=='/') rvbuf[p--]=0;
92 /* strip trailing .git */ 92 /* strip trailing .git */
93 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { 93 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
94 p -= 3; rvbuf[p--] = 0; 94 p -= 3; rvbuf[p--] = 0;
95 } 95 }
96 /* strip more trailing slashes if any */ 96 /* strip more trailing slashes if any */
97 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 97 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
98 /* find last slash in the remaining string */ 98 /* find last slash in the remaining string */
99 rv = strrchr(rvbuf,'/'); 99 rv = strrchr(rvbuf,'/');
100 if(rv) 100 if(rv)
101 return ++rv; 101 return ++rv;
102 return rvbuf; 102 return rvbuf;
103} 103}
104 104
105char *cgit_currurl() 105char *cgit_currurl()
106{ 106{
107 if (!ctx.cfg.virtual_root) 107 if (!ctx.cfg.virtual_root)
108 return ctx.cfg.script_name; 108 return ctx.cfg.script_name;
109 else if (ctx.qry.page) 109 else if (ctx.qry.page)
110 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); 110 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
111 else if (ctx.qry.repo) 111 else if (ctx.qry.repo)
112 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); 112 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
113 else 113 else
114 return fmt("%s/", ctx.cfg.virtual_root); 114 return fmt("%s/", ctx.cfg.virtual_root);
115} 115}
116 116
117static void site_url(char *page, char *search, int ofs) 117static void site_url(char *page, char *search, int ofs)
118{ 118{
119 char *delim = "?"; 119 char *delim = "?";
120 120
121 if (ctx.cfg.virtual_root) { 121 if (ctx.cfg.virtual_root) {
122 html_attr(ctx.cfg.virtual_root); 122 html_attr(ctx.cfg.virtual_root);
123 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 123 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
124 html("/"); 124 html("/");
125 } else 125 } else
126 html(ctx.cfg.script_name); 126 html(ctx.cfg.script_name);
127 127
128 if (page) { 128 if (page) {
129 htmlf("?p=%s", page); 129 htmlf("?p=%s", page);
130 delim = "&"; 130 delim = "&";
131 } 131 }
132 if (search) { 132 if (search) {
133 html(delim); 133 html(delim);
134 html("q="); 134 html("q=");
135 html_attr(search); 135 html_attr(search);
136 delim = "&"; 136 delim = "&";
137 } 137 }
138 if (ofs) { 138 if (ofs) {
139 html(delim); 139 html(delim);
140 htmlf("ofs=%d", ofs); 140 htmlf("ofs=%d", ofs);
141 } 141 }
142} 142}
143 143
144static void site_link(char *page, char *name, char *title, char *class, 144static void site_link(char *page, char *name, char *title, char *class,
145 char *search, int ofs) 145 char *search, int ofs)
146{ 146{
147 html("<a"); 147 html("<a");
148 if (title) { 148 if (title) {
149 html(" title='"); 149 html(" title='");
150 html_attr(title); 150 html_attr(title);
151 html("'"); 151 html("'");
152 } 152 }
153 if (class) { 153 if (class) {
154 html(" class='"); 154 html(" class='");
155 html_attr(class); 155 html_attr(class);
156 html("'"); 156 html("'");
157 } 157 }
158 html(" href='"); 158 html(" href='");
159 site_url(page, search, ofs); 159 site_url(page, search, ofs);
160 html("'>"); 160 html("'>");
161 html_txt(name); 161 html_txt(name);
162 html("</a>"); 162 html("</a>");
163} 163}
164 164
165void cgit_index_link(char *name, char *title, char *class, char *pattern, 165void cgit_index_link(char *name, char *title, char *class, char *pattern,
166 int ofs) 166 int ofs)
167{ 167{
168 site_link(NULL, name, title, class, pattern, ofs); 168 site_link(NULL, name, title, class, pattern, ofs);
169} 169}
170 170
171static char *repolink(char *title, char *class, char *page, char *head, 171static char *repolink(char *title, char *class, char *page, char *head,
172 char *path) 172 char *path)
173{ 173{
174 char *delim = "?"; 174 char *delim = "?";
175 175
176 html("<a"); 176 html("<a");
177 if (title) { 177 if (title) {
178 html(" title='"); 178 html(" title='");
179 html_attr(title); 179 html_attr(title);
180 html("'"); 180 html("'");
181 } 181 }
182 if (class) { 182 if (class) {
183 html(" class='"); 183 html(" class='");
184 html_attr(class); 184 html_attr(class);
185 html("'"); 185 html("'");
186 } 186 }
187 html(" href='"); 187 html(" href='");
188 if (ctx.cfg.virtual_root) { 188 if (ctx.cfg.virtual_root) {
189 html_attr(ctx.cfg.virtual_root); 189 html_attr(ctx.cfg.virtual_root);
190 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 190 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
191 html("/"); 191 html("/");
192 html_attr(ctx.repo->url); 192 html_attr(ctx.repo->url);
193 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 193 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
194 html("/"); 194 html("/");
195 if (page) { 195 if (page) {
196 html(page); 196 html(page);
197 html("/"); 197 html("/");
198 if (path) 198 if (path)
199 html_attr(path); 199 html_attr(path);
200 } 200 }
201 } else { 201 } else {
202 html(ctx.cfg.script_name); 202 html(ctx.cfg.script_name);
203 html("?url="); 203 html("?url=");
204 html_attr(ctx.repo->url); 204 html_attr(ctx.repo->url);
205 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 205 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
206 html("/"); 206 html("/");
207 if (page) { 207 if (page) {
208 html(page); 208 html(page);
209 html("/"); 209 html("/");
210 if (path) 210 if (path)
211 html_attr(path); 211 html_attr(path);
212 } 212 }
213 delim = "&amp;"; 213 delim = "&amp;";
214 } 214 }
215 if (head && strcmp(head, ctx.repo->defbranch)) { 215 if (head && strcmp(head, ctx.repo->defbranch)) {
216 html(delim); 216 html(delim);
217 html("h="); 217 html("h=");
218 html_attr(head); 218 html_attr(head);
219 delim = "&amp;"; 219 delim = "&amp;";
220 } 220 }
221 return fmt("%s", delim); 221 return fmt("%s", delim);
222} 222}
223 223
224static void reporevlink(char *page, char *name, char *title, char *class, 224static void reporevlink(char *page, char *name, char *title, char *class,
225 char *head, char *rev, char *path) 225 char *head, char *rev, char *path)
226{ 226{
227 char *delim; 227 char *delim;
228 228
229 delim = repolink(title, class, page, head, path); 229 delim = repolink(title, class, page, head, path);
230 if (rev && strcmp(rev, ctx.qry.head)) { 230 if (rev && strcmp(rev, ctx.qry.head)) {
231 html(delim); 231 html(delim);
232 html("id="); 232 html("id=");
233 html_attr(rev); 233 html_attr(rev);
234 } 234 }
235 html("'>"); 235 html("'>");
236 html_txt(name); 236 html_txt(name);
237 html("</a>"); 237 html("</a>");
238} 238}
239 239
240void cgit_tree_link(char *name, char *title, char *class, char *head, 240void cgit_tree_link(char *name, char *title, char *class, char *head,
241 char *rev, char *path) 241 char *rev, char *path)
242{ 242{
243 reporevlink("tree", name, title, class, head, rev, path); 243 reporevlink("tree", name, title, class, head, rev, path);
244} 244}
245 245
246void cgit_log_link(char *name, char *title, char *class, char *head, 246void cgit_log_link(char *name, char *title, char *class, char *head,
247 char *rev, char *path, int ofs, char *grep, char *pattern) 247 char *rev, char *path, int ofs, char *grep, char *pattern)
248{ 248{
249 char *delim; 249 char *delim;
250 250
251 delim = repolink(title, class, "log", head, path); 251 delim = repolink(title, class, "log", head, path);
252 if (rev && strcmp(rev, ctx.qry.head)) { 252 if (rev && strcmp(rev, ctx.qry.head)) {
253 html(delim); 253 html(delim);
254 html("id="); 254 html("id=");
255 html_attr(rev); 255 html_attr(rev);
256 delim = "&"; 256 delim = "&";
257 } 257 }
258 if (grep && pattern) { 258 if (grep && pattern) {
259 html(delim); 259 html(delim);
260 html("qt="); 260 html("qt=");
261 html_attr(grep); 261 html_attr(grep);
262 delim = "&"; 262 delim = "&";
263 html(delim); 263 html(delim);
264 html("q="); 264 html("q=");
265 html_attr(pattern); 265 html_attr(pattern);
266 } 266 }
267 if (ofs > 0) { 267 if (ofs > 0) {
268 html(delim); 268 html(delim);
269 html("ofs="); 269 html("ofs=");
270 htmlf("%d", ofs); 270 htmlf("%d", ofs);
271 } 271 }
272 html("'>"); 272 html("'>");
273 html_txt(name); 273 html_txt(name);
274 html("</a>"); 274 html("</a>");
275} 275}
276 276
277void cgit_commit_link(char *name, char *title, char *class, char *head, 277void cgit_commit_link(char *name, char *title, char *class, char *head,
278 char *rev) 278 char *rev)
279{ 279{
280 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 280 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
281 name[ctx.cfg.max_msg_len] = '\0'; 281 name[ctx.cfg.max_msg_len] = '\0';
282 name[ctx.cfg.max_msg_len - 1] = '.'; 282 name[ctx.cfg.max_msg_len - 1] = '.';
283 name[ctx.cfg.max_msg_len - 2] = '.'; 283 name[ctx.cfg.max_msg_len - 2] = '.';
284 name[ctx.cfg.max_msg_len - 3] = '.'; 284 name[ctx.cfg.max_msg_len - 3] = '.';
285 } 285 }
286 reporevlink("commit", name, title, class, head, rev, NULL); 286 reporevlink("commit", name, title, class, head, rev, NULL);
287} 287}
288 288
289void cgit_refs_link(char *name, char *title, char *class, char *head, 289void cgit_refs_link(char *name, char *title, char *class, char *head,
290 char *rev, char *path) 290 char *rev, char *path)
291{ 291{
292 reporevlink("refs", name, title, class, head, rev, path); 292 reporevlink("refs", name, title, class, head, rev, path);
293} 293}
294 294
295void cgit_snapshot_link(char *name, char *title, char *class, char *head, 295void cgit_snapshot_link(char *name, char *title, char *class, char *head,
296 char *rev, char *archivename) 296 char *rev, char *archivename)
297{ 297{
298 reporevlink("snapshot", name, title, class, head, rev, archivename); 298 reporevlink("snapshot", name, title, class, head, rev, archivename);
299} 299}
300 300
301void cgit_diff_link(char *name, char *title, char *class, char *head, 301void cgit_diff_link(char *name, char *title, char *class, char *head,
302 char *new_rev, char *old_rev, char *path) 302 char *new_rev, char *old_rev, char *path)
303{ 303{
304 char *delim; 304 char *delim;
305 305
306 delim = repolink(title, class, "diff", head, path); 306 delim = repolink(title, class, "diff", head, path);
307 if (new_rev && strcmp(new_rev, ctx.qry.head)) { 307 if (new_rev && strcmp(new_rev, ctx.qry.head)) {
308 html(delim); 308 html(delim);
309 html("id="); 309 html("id=");
310 html_attr(new_rev); 310 html_attr(new_rev);
311 delim = "&amp;"; 311 delim = "&amp;";
312 } 312 }
313 if (old_rev) { 313 if (old_rev) {
314 html(delim); 314 html(delim);
315 html("id2="); 315 html("id2=");
316 html_attr(old_rev); 316 html_attr(old_rev);
317 } 317 }
318 html("'>"); 318 html("'>");
319 html_txt(name); 319 html_txt(name);
320 html("</a>"); 320 html("</a>");
321} 321}
322 322
323void cgit_patch_link(char *name, char *title, char *class, char *head, 323void cgit_patch_link(char *name, char *title, char *class, char *head,
324 char *rev) 324 char *rev)
325{ 325{
326 reporevlink("patch", name, title, class, head, rev, NULL); 326 reporevlink("patch", name, title, class, head, rev, NULL);
327} 327}
328 328
329void cgit_object_link(struct object *obj) 329void cgit_object_link(struct object *obj)
330{ 330{
331 char *page, *arg, *url; 331 char *page, *arg, *url;
332 332
333 if (obj->type == OBJ_COMMIT) { 333 if (obj->type == OBJ_COMMIT) {
334 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 334 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
335 ctx.qry.head, sha1_to_hex(obj->sha1)); 335 ctx.qry.head, sha1_to_hex(obj->sha1));
336 return; 336 return;
337 } else if (obj->type == OBJ_TREE) { 337 } else if (obj->type == OBJ_TREE) {
338 page = "tree"; 338 page = "tree";
339 arg = "id"; 339 arg = "id";
340 } else if (obj->type == OBJ_TAG) { 340 } else if (obj->type == OBJ_TAG) {
341 page = "tag"; 341 page = "tag";
342 arg = "id"; 342 arg = "id";
343 } else { 343 } else {
344 page = "blob"; 344 page = "blob";
345 arg = "id"; 345 arg = "id";
346 } 346 }
347 347
348 url = cgit_pageurl(ctx.qry.repo, page, 348 url = cgit_pageurl(ctx.qry.repo, page,
349 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 349 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
350 html_link_open(url, NULL, NULL); 350 html_link_open(url, NULL, NULL);
351 htmlf("%s %s", typename(obj->type), 351 htmlf("%s %s", typename(obj->type),
352 sha1_to_hex(obj->sha1)); 352 sha1_to_hex(obj->sha1));
353 html_link_close(); 353 html_link_close();
354} 354}
355 355
356void cgit_print_date(time_t secs, char *format) 356void cgit_print_date(time_t secs, char *format, int local_time)
357{ 357{
358 char buf[64]; 358 char buf[64];
359 struct tm *time; 359 struct tm *time;
360 360
361 if (!secs) 361 if (!secs)
362 return; 362 return;
363 time = gmtime(&secs); 363 if(local_time)
364 time = localtime(&secs);
365 else
366 time = gmtime(&secs);
364 strftime(buf, sizeof(buf)-1, format, time); 367 strftime(buf, sizeof(buf)-1, format, time);
365 html_txt(buf); 368 html_txt(buf);
366} 369}
367 370
368void cgit_print_age(time_t t, time_t max_relative, char *format) 371void cgit_print_age(time_t t, time_t max_relative, char *format)
369{ 372{
370 time_t now, secs; 373 time_t now, secs;
371 374
372 if (!t) 375 if (!t)
373 return; 376 return;
374 time(&now); 377 time(&now);
375 secs = now - t; 378 secs = now - t;
376 379
377 if (secs > max_relative && max_relative >= 0) { 380 if (secs > max_relative && max_relative >= 0) {
378 cgit_print_date(t, format); 381 cgit_print_date(t, format, ctx.cfg.local_time);
379 return; 382 return;
380 } 383 }
381 384
382 if (secs < TM_HOUR * 2) { 385 if (secs < TM_HOUR * 2) {
383 htmlf("<span class='age-mins'>%.0f min.</span>", 386 htmlf("<span class='age-mins'>%.0f min.</span>",
384 secs * 1.0 / TM_MIN); 387 secs * 1.0 / TM_MIN);
385 return; 388 return;
386 } 389 }
387 if (secs < TM_DAY * 2) { 390 if (secs < TM_DAY * 2) {
388 htmlf("<span class='age-hours'>%.0f hours</span>", 391 htmlf("<span class='age-hours'>%.0f hours</span>",
389 secs * 1.0 / TM_HOUR); 392 secs * 1.0 / TM_HOUR);
390 return; 393 return;
391 } 394 }
392 if (secs < TM_WEEK * 2) { 395 if (secs < TM_WEEK * 2) {
393 htmlf("<span class='age-days'>%.0f days</span>", 396 htmlf("<span class='age-days'>%.0f days</span>",
394 secs * 1.0 / TM_DAY); 397 secs * 1.0 / TM_DAY);
395 return; 398 return;
396 } 399 }
397 if (secs < TM_MONTH * 2) { 400 if (secs < TM_MONTH * 2) {
398 htmlf("<span class='age-weeks'>%.0f weeks</span>", 401 htmlf("<span class='age-weeks'>%.0f weeks</span>",
399 secs * 1.0 / TM_WEEK); 402 secs * 1.0 / TM_WEEK);
400 return; 403 return;
401 } 404 }
402 if (secs < TM_YEAR * 2) { 405 if (secs < TM_YEAR * 2) {
403 htmlf("<span class='age-months'>%.0f months</span>", 406 htmlf("<span class='age-months'>%.0f months</span>",
404 secs * 1.0 / TM_MONTH); 407 secs * 1.0 / TM_MONTH);
405 return; 408 return;
406 } 409 }
407 htmlf("<span class='age-years'>%.0f years</span>", 410 htmlf("<span class='age-years'>%.0f years</span>",
408 secs * 1.0 / TM_YEAR); 411 secs * 1.0 / TM_YEAR);
409} 412}
410 413
411void cgit_print_http_headers(struct cgit_context *ctx) 414void cgit_print_http_headers(struct cgit_context *ctx)
412{ 415{
413 if (ctx->page.mimetype && ctx->page.charset) 416 if (ctx->page.mimetype && ctx->page.charset)
414 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 417 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
415 ctx->page.charset); 418 ctx->page.charset);
416 else if (ctx->page.mimetype) 419 else if (ctx->page.mimetype)
417 htmlf("Content-Type: %s\n", ctx->page.mimetype); 420 htmlf("Content-Type: %s\n", ctx->page.mimetype);
418 if (ctx->page.filename) 421 if (ctx->page.filename)
419 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 422 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
420 ctx->page.filename); 423 ctx->page.filename);
421 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 424 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
422 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 425 htmlf("Expires: %s\n", http_date(ctx->page.expires));
423 html("\n"); 426 html("\n");
424} 427}
425 428
426void cgit_print_docstart(struct cgit_context *ctx) 429void cgit_print_docstart(struct cgit_context *ctx)
427{ 430{
428 html(cgit_doctype); 431 html(cgit_doctype);
429 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 432 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
430 html("<head>\n"); 433 html("<head>\n");
431 html("<title>"); 434 html("<title>");
432 html_txt(ctx->page.title); 435 html_txt(ctx->page.title);
433 html("</title>\n"); 436 html("</title>\n");
434 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 437 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
435 if (ctx->cfg.robots && *ctx->cfg.robots) 438 if (ctx->cfg.robots && *ctx->cfg.robots)
436 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 439 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
437 html("<link rel='stylesheet' type='text/css' href='"); 440 html("<link rel='stylesheet' type='text/css' href='");
438 html_attr(ctx->cfg.css); 441 html_attr(ctx->cfg.css);
439 html("'/>\n"); 442 html("'/>\n");
440 if (ctx->cfg.favicon) { 443 if (ctx->cfg.favicon) {
441 html("<link rel='shortcut icon' href='"); 444 html("<link rel='shortcut icon' href='");
442 html_attr(ctx->cfg.favicon); 445 html_attr(ctx->cfg.favicon);
443 html("'/>\n"); 446 html("'/>\n");
444 } 447 }
445 html("</head>\n"); 448 html("</head>\n");
446 html("<body>\n"); 449 html("<body>\n");
447} 450}
448 451
449void cgit_print_docend() 452void cgit_print_docend()
450{ 453{
451 html("</div>"); 454 html("</div>");
452 if (ctx.cfg.footer) 455 if (ctx.cfg.footer)
453 html_include(ctx.cfg.footer); 456 html_include(ctx.cfg.footer);
454 else { 457 else {
455 html("<div class='footer'>generated "); 458 html("<div class='footer'>generated ");
456 cgit_print_date(time(NULL), FMT_LONGDATE); 459 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
457 htmlf(" by cgit %s", cgit_version); 460 htmlf(" by cgit %s", cgit_version);
458 html("</div>\n"); 461 html("</div>\n");
459 } 462 }
460 html("</body>\n</html>\n"); 463 html("</body>\n</html>\n");
461} 464}
462 465
463int print_branch_option(const char *refname, const unsigned char *sha1, 466int print_branch_option(const char *refname, const unsigned char *sha1,
464 int flags, void *cb_data) 467 int flags, void *cb_data)
465{ 468{
466 char *name = (char *)refname; 469 char *name = (char *)refname;
467 html_option(name, name, ctx.qry.head); 470 html_option(name, name, ctx.qry.head);
468 return 0; 471 return 0;
469} 472}
470 473
471int print_archive_ref(const char *refname, const unsigned char *sha1, 474int print_archive_ref(const char *refname, const unsigned char *sha1,
472 int flags, void *cb_data) 475 int flags, void *cb_data)
473{ 476{
474 struct tag *tag; 477 struct tag *tag;
475 struct taginfo *info; 478 struct taginfo *info;
476 struct object *obj; 479 struct object *obj;
477 char buf[256], *url; 480 char buf[256], *url;
478 unsigned char fileid[20]; 481 unsigned char fileid[20];
479 int *header = (int *)cb_data; 482 int *header = (int *)cb_data;
480 483
481 if (prefixcmp(refname, "refs/archives")) 484 if (prefixcmp(refname, "refs/archives"))
482 return 0; 485 return 0;
483 strncpy(buf, refname+14, sizeof(buf)); 486 strncpy(buf, refname+14, sizeof(buf));
484 obj = parse_object(sha1); 487 obj = parse_object(sha1);
485 if (!obj) 488 if (!obj)
486 return 1; 489 return 1;
487 if (obj->type == OBJ_TAG) { 490 if (obj->type == OBJ_TAG) {
488 tag = lookup_tag(sha1); 491 tag = lookup_tag(sha1);
489 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 492 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
490 return 0; 493 return 0;
491 hashcpy(fileid, tag->tagged->sha1); 494 hashcpy(fileid, tag->tagged->sha1);
492 } else if (obj->type != OBJ_BLOB) { 495 } else if (obj->type != OBJ_BLOB) {
493 return 0; 496 return 0;
494 } else { 497 } else {
495 hashcpy(fileid, sha1); 498 hashcpy(fileid, sha1);
496 } 499 }
497 if (!*header) { 500 if (!*header) {
498 html("<h1>download</h1>\n"); 501 html("<h1>download</h1>\n");
499 *header = 1; 502 *header = 1;
500 } 503 }
501 url = cgit_pageurl(ctx.qry.repo, "blob", 504 url = cgit_pageurl(ctx.qry.repo, "blob",
502 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 505 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
503 buf)); 506 buf));
504 html_link_open(url, NULL, "menu"); 507 html_link_open(url, NULL, "menu");
505 html_txt(strlpart(buf, 20)); 508 html_txt(strlpart(buf, 20));
506 html_link_close(); 509 html_link_close();
507 return 0; 510 return 0;
508} 511}
509 512
510void add_hidden_formfields(int incl_head, int incl_search, char *page) 513void add_hidden_formfields(int incl_head, int incl_search, char *page)
511{ 514{
512 char *url; 515 char *url;
513 516
514 if (!ctx.cfg.virtual_root) { 517 if (!ctx.cfg.virtual_root) {
515 url = fmt("%s/%s", ctx.qry.repo, page); 518 url = fmt("%s/%s", ctx.qry.repo, page);
516 if (ctx.qry.path) 519 if (ctx.qry.path)
517 url = fmt("%s/%s", url, ctx.qry.path); 520 url = fmt("%s/%s", url, ctx.qry.path);
518 html_hidden("url", url); 521 html_hidden("url", url);
519 } 522 }
520 523
521 if (incl_head && ctx.qry.head && ctx.repo->defbranch && 524 if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
522 strcmp(ctx.qry.head, ctx.repo->defbranch)) 525 strcmp(ctx.qry.head, ctx.repo->defbranch))
523 html_hidden("h", ctx.qry.head); 526 html_hidden("h", ctx.qry.head);
524 527
525 if (ctx.qry.sha1) 528 if (ctx.qry.sha1)
526 html_hidden("id", ctx.qry.sha1); 529 html_hidden("id", ctx.qry.sha1);
527 if (ctx.qry.sha2) 530 if (ctx.qry.sha2)
528 html_hidden("id2", ctx.qry.sha2); 531 html_hidden("id2", ctx.qry.sha2);
529 532
530 if (incl_search) { 533 if (incl_search) {
531 if (ctx.qry.grep) 534 if (ctx.qry.grep)
532 html_hidden("qt", ctx.qry.grep); 535 html_hidden("qt", ctx.qry.grep);
533 if (ctx.qry.search) 536 if (ctx.qry.search)
534 html_hidden("q", ctx.qry.search); 537 html_hidden("q", ctx.qry.search);
535 } 538 }
536} 539}
537 540
538char *hc(struct cgit_cmd *cmd, const char *page) 541char *hc(struct cgit_cmd *cmd, const char *page)
539{ 542{
540 return (strcmp(cmd->name, page) ? NULL : "active"); 543 return (strcmp(cmd->name, page) ? NULL : "active");
541} 544}
542 545
543void cgit_print_pageheader(struct cgit_context *ctx) 546void cgit_print_pageheader(struct cgit_context *ctx)
544{ 547{
545 struct cgit_cmd *cmd = cgit_get_cmd(ctx); 548 struct cgit_cmd *cmd = cgit_get_cmd(ctx);
546 549
547 html("<table id='header'>\n"); 550 html("<table id='header'>\n");
548 html("<tr>\n"); 551 html("<tr>\n");
549 html("<td class='logo' rowspan='2'><a href='"); 552 html("<td class='logo' rowspan='2'><a href='");
550 if (ctx->cfg.logo_link) 553 if (ctx->cfg.logo_link)
551 html_attr(ctx->cfg.logo_link); 554 html_attr(ctx->cfg.logo_link);
552 else 555 else
553 html_attr(cgit_rooturl()); 556 html_attr(cgit_rooturl());
554 html("'><img src='"); 557 html("'><img src='");
555 html_attr(ctx->cfg.logo); 558 html_attr(ctx->cfg.logo);
556 html("' alt='cgit logo'/></a></td>\n"); 559 html("' alt='cgit logo'/></a></td>\n");
557 560
558 html("<td class='main'>"); 561 html("<td class='main'>");
559 if (ctx->repo) { 562 if (ctx->repo) {
560 cgit_index_link("index", NULL, NULL, NULL, 0); 563 cgit_index_link("index", NULL, NULL, NULL, 0);
561 html(" : "); 564 html(" : ");
562 reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"), 565 reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"),
563 ctx->qry.head, NULL, NULL); 566 ctx->qry.head, NULL, NULL);
564 html("</td><td class='form'>"); 567 html("</td><td class='form'>");
565 html("<form method='get' action=''>\n"); 568 html("<form method='get' action=''>\n");
566 add_hidden_formfields(0, 1, ctx->qry.page); 569 add_hidden_formfields(0, 1, ctx->qry.page);
567 html("<select name='h' onchange='this.form.submit();'>\n"); 570 html("<select name='h' onchange='this.form.submit();'>\n");
568 for_each_branch_ref(print_branch_option, ctx->qry.head); 571 for_each_branch_ref(print_branch_option, ctx->qry.head);
569 html("</select> "); 572 html("</select> ");
570 html("<input type='submit' name='' value='switch'/>"); 573 html("<input type='submit' name='' value='switch'/>");
571 html("</form>"); 574 html("</form>");
572 } else 575 } else
573 html_txt(ctx->cfg.root_title); 576 html_txt(ctx->cfg.root_title);
574 html("</td></tr>\n"); 577 html("</td></tr>\n");
575 578
576 html("<tr><td class='sub'>"); 579 html("<tr><td class='sub'>");
577 if (ctx->repo) { 580 if (ctx->repo) {
578 html_txt(ctx->repo->desc); 581 html_txt(ctx->repo->desc);
579 html("</td><td class='sub right'>"); 582 html("</td><td class='sub right'>");
580 html_txt(ctx->repo->owner); 583 html_txt(ctx->repo->owner);
581 } else { 584 } else {
582 if (ctx->cfg.root_desc) 585 if (ctx->cfg.root_desc)
583 html_txt(ctx->cfg.root_desc); 586 html_txt(ctx->cfg.root_desc);
584 else if (ctx->cfg.index_info) 587 else if (ctx->cfg.index_info)
585 html_include(ctx->cfg.index_info); 588 html_include(ctx->cfg.index_info);
586 } 589 }
587 html("</td></tr></table>\n"); 590 html("</td></tr></table>\n");
588 591
589 html("<table class='tabs'><tr><td>\n"); 592 html("<table class='tabs'><tr><td>\n");
590 if (ctx->repo) { 593 if (ctx->repo) {
591 reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), 594 reporevlink(NULL, "summary", NULL, hc(cmd, "summary"),
592 ctx->qry.head, NULL, NULL); 595 ctx->qry.head, NULL, NULL);
593 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, 596 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
594 ctx->qry.sha1, NULL); 597 ctx->qry.sha1, NULL);
595 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, 598 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
596 NULL, NULL, 0, NULL, NULL); 599 NULL, NULL, 0, NULL, NULL);
597 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, 600 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
598 ctx->qry.sha1, NULL); 601 ctx->qry.sha1, NULL);
599 cgit_commit_link("commit", NULL, hc(cmd, "commit"), 602 cgit_commit_link("commit", NULL, hc(cmd, "commit"),
600 ctx->qry.head, ctx->qry.sha1); 603 ctx->qry.head, ctx->qry.sha1);
601 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, 604 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
602 ctx->qry.sha1, ctx->qry.sha2, NULL); 605 ctx->qry.sha1, ctx->qry.sha2, NULL);
603 if (ctx->repo->readme) 606 if (ctx->repo->readme)
604 reporevlink("about", "about", NULL, 607 reporevlink("about", "about", NULL,
605 hc(cmd, "about"), ctx->qry.head, NULL, 608 hc(cmd, "about"), ctx->qry.head, NULL,
606 NULL); 609 NULL);
607 html("</td><td class='form'>"); 610 html("</td><td class='form'>");
608 html("<form class='right' method='get' action='"); 611 html("<form class='right' method='get' action='");
609 if (ctx->cfg.virtual_root) 612 if (ctx->cfg.virtual_root)
610 html_attr(cgit_fileurl(ctx->qry.repo, "log", 613 html_attr(cgit_fileurl(ctx->qry.repo, "log",
611 ctx->qry.path, NULL)); 614 ctx->qry.path, NULL));
612 html("'>\n"); 615 html("'>\n");
613 add_hidden_formfields(1, 0, "log"); 616 add_hidden_formfields(1, 0, "log");
614 html("<select name='qt'>\n"); 617 html("<select name='qt'>\n");
615 html_option("grep", "log msg", ctx->qry.grep); 618 html_option("grep", "log msg", ctx->qry.grep);
616 html_option("author", "author", ctx->qry.grep); 619 html_option("author", "author", ctx->qry.grep);
617 html_option("committer", "committer", ctx->qry.grep); 620 html_option("committer", "committer", ctx->qry.grep);
618 html("</select>\n"); 621 html("</select>\n");
619 html("<input class='txt' type='text' size='10' name='q' value='"); 622 html("<input class='txt' type='text' size='10' name='q' value='");
620 html_attr(ctx->qry.search); 623 html_attr(ctx->qry.search);
621 html("'/>\n"); 624 html("'/>\n");
622 html("<input type='submit' value='search'/>\n"); 625 html("<input type='submit' value='search'/>\n");
623 html("</form>\n"); 626 html("</form>\n");
624 } else { 627 } else {
625 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); 628 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
626 if (ctx->cfg.root_readme) 629 if (ctx->cfg.root_readme)
627 site_link("about", "about", NULL, hc(cmd, "about"), 630 site_link("about", "about", NULL, hc(cmd, "about"),
628 NULL, 0); 631 NULL, 0);
629 html("</td><td class='form'>"); 632 html("</td><td class='form'>");
630 html("<form method='get' action='"); 633 html("<form method='get' action='");
631 html_attr(cgit_rooturl()); 634 html_attr(cgit_rooturl());
632 html("'>\n"); 635 html("'>\n");
633 html("<input type='text' name='q' size='10' value='"); 636 html("<input type='text' name='q' size='10' value='");
634 html_attr(ctx->qry.search); 637 html_attr(ctx->qry.search);
635 html("'/>\n"); 638 html("'/>\n");
636 html("<input type='submit' value='search'/>\n"); 639 html("<input type='submit' value='search'/>\n");
637 html("</form>"); 640 html("</form>");
638 } 641 }
639 html("</td></tr></table>\n"); 642 html("</td></tr></table>\n");
640 html("<div class='content'>"); 643 html("<div class='content'>");
641} 644}
642 645
643void cgit_print_filemode(unsigned short mode) 646void cgit_print_filemode(unsigned short mode)
644{ 647{
645 if (S_ISDIR(mode)) 648 if (S_ISDIR(mode))
646 html("d"); 649 html("d");
647 else if (S_ISLNK(mode)) 650 else if (S_ISLNK(mode))
648 html("l"); 651 html("l");
649 else if (S_ISGITLINK(mode)) 652 else if (S_ISGITLINK(mode))
650 html("m"); 653 html("m");
651 else 654 else
652 html("-"); 655 html("-");
653 html_fileperm(mode >> 6); 656 html_fileperm(mode >> 6);
654 html_fileperm(mode >> 3); 657 html_fileperm(mode >> 3);
655 html_fileperm(mode); 658 html_fileperm(mode);
656} 659}
657 660
658void cgit_print_snapshot_links(const char *repo, const char *head, 661void cgit_print_snapshot_links(const char *repo, const char *head,
659 const char *hex, int snapshots) 662 const char *hex, int snapshots)
660{ 663{
661 const struct cgit_snapshot_format* f; 664 const struct cgit_snapshot_format* f;
662 char *filename; 665 char *filename;
663 666
664 for (f = cgit_snapshot_formats; f->suffix; f++) { 667 for (f = cgit_snapshot_formats; f->suffix; f++) {
665 if (!(snapshots & f->bit)) 668 if (!(snapshots & f->bit))
666 continue; 669 continue;
667 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, 670 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
668 f->suffix); 671 f->suffix);
669 cgit_snapshot_link(filename, NULL, NULL, (char *)head, 672 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
670 (char *)hex, filename); 673 (char *)hex, filename);
671 html("<br/>"); 674 html("<br/>");
672 } 675 }
673} 676}
diff --git a/ui-shared.h b/ui-shared.h
index 3005d30..07da4b4 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,40 +1,40 @@
1#ifndef UI_SHARED_H 1#ifndef UI_SHARED_H
2#define UI_SHARED_H 2#define UI_SHARED_H
3 3
4extern char *cgit_repourl(const char *reponame); 4extern char *cgit_repourl(const char *reponame);
5extern char *cgit_fileurl(const char *reponame, const char *pagename, 5extern char *cgit_fileurl(const char *reponame, const char *pagename,
6 const char *filename, const char *query); 6 const char *filename, const char *query);
7extern char *cgit_pageurl(const char *reponame, const char *pagename, 7extern char *cgit_pageurl(const char *reponame, const char *pagename,
8 const char *query); 8 const char *query);
9 9
10extern void cgit_index_link(char *name, char *title, char *class, 10extern void cgit_index_link(char *name, char *title, char *class,
11 char *pattern, int ofs); 11 char *pattern, int ofs);
12extern void cgit_tree_link(char *name, char *title, char *class, char *head, 12extern void cgit_tree_link(char *name, char *title, char *class, char *head,
13 char *rev, char *path); 13 char *rev, char *path);
14extern void cgit_log_link(char *name, char *title, char *class, char *head, 14extern void cgit_log_link(char *name, char *title, char *class, char *head,
15 char *rev, char *path, int ofs, char *grep, 15 char *rev, char *path, int ofs, char *grep,
16 char *pattern); 16 char *pattern);
17extern void cgit_commit_link(char *name, char *title, char *class, char *head, 17extern void cgit_commit_link(char *name, char *title, char *class, char *head,
18 char *rev); 18 char *rev);
19extern void cgit_patch_link(char *name, char *title, char *class, char *head, 19extern void cgit_patch_link(char *name, char *title, char *class, char *head,
20 char *rev); 20 char *rev);
21extern void cgit_refs_link(char *name, char *title, char *class, char *head, 21extern void cgit_refs_link(char *name, char *title, char *class, char *head,
22 char *rev, char *path); 22 char *rev, char *path);
23extern void cgit_snapshot_link(char *name, char *title, char *class, 23extern void cgit_snapshot_link(char *name, char *title, char *class,
24 char *head, char *rev, char *archivename); 24 char *head, char *rev, char *archivename);
25extern void cgit_diff_link(char *name, char *title, char *class, char *head, 25extern void cgit_diff_link(char *name, char *title, char *class, char *head,
26 char *new_rev, char *old_rev, char *path); 26 char *new_rev, char *old_rev, char *path);
27extern void cgit_object_link(struct object *obj); 27extern void cgit_object_link(struct object *obj);
28 28
29extern void cgit_print_error(char *msg); 29extern void cgit_print_error(char *msg);
30extern void cgit_print_date(time_t secs, char *format); 30extern void cgit_print_date(time_t secs, char *format, int local_time);
31extern void cgit_print_age(time_t t, time_t max_relative, char *format); 31extern void cgit_print_age(time_t t, time_t max_relative, char *format);
32extern void cgit_print_http_headers(struct cgit_context *ctx); 32extern void cgit_print_http_headers(struct cgit_context *ctx);
33extern void cgit_print_docstart(struct cgit_context *ctx); 33extern void cgit_print_docstart(struct cgit_context *ctx);
34extern void cgit_print_docend(); 34extern void cgit_print_docend();
35extern void cgit_print_pageheader(struct cgit_context *ctx); 35extern void cgit_print_pageheader(struct cgit_context *ctx);
36extern void cgit_print_filemode(unsigned short mode); 36extern void cgit_print_filemode(unsigned short mode);
37extern void cgit_print_snapshot_links(const char *repo, const char *head, 37extern void cgit_print_snapshot_links(const char *repo, const char *head,
38 const char *hex, int snapshots); 38 const char *hex, int snapshots);
39 39
40#endif /* UI_SHARED_H */ 40#endif /* UI_SHARED_H */
diff --git a/ui-tag.c b/ui-tag.c
index ab2c66d..b4db32e 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -1,75 +1,75 @@
1/* ui-tag.c: display a tag 1/* ui-tag.c: display a tag
2 * 2 *
3 * Copyright (C) 2007 Lars Hjemli 3 * Copyright (C) 2007 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
13static void print_tag_content(char *buf) 13static void print_tag_content(char *buf)
14{ 14{
15 char *p; 15 char *p;
16 16
17 if (!buf) 17 if (!buf)
18 return; 18 return;
19 19
20 html("<div class='commit-subject'>"); 20 html("<div class='commit-subject'>");
21 p = strchr(buf, '\n'); 21 p = strchr(buf, '\n');
22 if (p) 22 if (p)
23 *p = '\0'; 23 *p = '\0';
24 html_txt(buf); 24 html_txt(buf);
25 html("</div>"); 25 html("</div>");
26 if (p) { 26 if (p) {
27 html("<div class='commit-msg'>"); 27 html("<div class='commit-msg'>");
28 html_txt(++p); 28 html_txt(++p);
29 html("</div>"); 29 html("</div>");
30 } 30 }
31} 31}
32 32
33void cgit_print_tag(char *revname) 33void cgit_print_tag(char *revname)
34{ 34{
35 unsigned char sha1[20]; 35 unsigned char sha1[20];
36 struct object *obj; 36 struct object *obj;
37 struct tag *tag; 37 struct tag *tag;
38 struct taginfo *info; 38 struct taginfo *info;
39 39
40 if (get_sha1(revname, sha1)) { 40 if (get_sha1(revname, sha1)) {
41 cgit_print_error(fmt("Bad tag reference: %s", revname)); 41 cgit_print_error(fmt("Bad tag reference: %s", revname));
42 return; 42 return;
43 } 43 }
44 obj = parse_object(sha1); 44 obj = parse_object(sha1);
45 if (!obj) { 45 if (!obj) {
46 cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); 46 cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
47 return; 47 return;
48 } 48 }
49 if (obj->type == OBJ_TAG) { 49 if (obj->type == OBJ_TAG) {
50 tag = lookup_tag(sha1); 50 tag = lookup_tag(sha1);
51 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { 51 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
52 cgit_print_error(fmt("Bad tag object: %s", revname)); 52 cgit_print_error(fmt("Bad tag object: %s", revname));
53 return; 53 return;
54 } 54 }
55 html("<table class='commit-info'>\n"); 55 html("<table class='commit-info'>\n");
56 htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n", 56 htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n",
57 revname, sha1_to_hex(sha1)); 57 revname, sha1_to_hex(sha1));
58 if (info->tagger_date > 0) { 58 if (info->tagger_date > 0) {
59 html("<tr><td>Tag date</td><td>"); 59 html("<tr><td>Tag date</td><td>");
60 cgit_print_date(info->tagger_date, FMT_LONGDATE); 60 cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
61 html("</td></tr>\n"); 61 html("</td></tr>\n");
62 } 62 }
63 if (info->tagger) { 63 if (info->tagger) {
64 html("<tr><td>Tagged by</td><td>"); 64 html("<tr><td>Tagged by</td><td>");
65 html_txt(info->tagger); 65 html_txt(info->tagger);
66 html("</td></tr>\n"); 66 html("</td></tr>\n");
67 } 67 }
68 html("<tr><td>Tagged object</td><td>"); 68 html("<tr><td>Tagged object</td><td>");
69 cgit_object_link(tag->tagged); 69 cgit_object_link(tag->tagged);
70 html("</td></tr>\n"); 70 html("</td></tr>\n");
71 html("</table>\n"); 71 html("</table>\n");
72 print_tag_content(info->msg); 72 print_tag_content(info->msg);
73 } 73 }
74 return; 74 return;
75} 75}