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
@@ -82,16 +82,18 @@ void config_cb(const char *name, const char *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, '/');
@@ -162,16 +164,17 @@ static void prepare_context(struct cgit_context *ctx)
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";
diff --git a/cgit.h b/cgit.h
index 7881aca..b01fa31 100644
--- a/cgit.h
+++ b/cgit.h
@@ -17,17 +17,17 @@
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)
@@ -143,16 +143,17 @@ struct cgit_config {
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;
diff --git a/ui-commit.c b/ui-commit.c
index 4bbb391..a6a85a4 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -35,24 +35,24 @@ void cgit_print_commit(char *hex)
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'>");
diff --git a/ui-patch.c b/ui-patch.c
index c1c4ce3..e60877d 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -98,17 +98,17 @@ void cgit_print_patch(char *hex)
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);
diff --git a/ui-shared.c b/ui-shared.c
index 4280a70..197ee37 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -348,39 +348,42 @@ void cgit_object_link(struct object *obj)
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 }
@@ -448,17 +451,17 @@ void cgit_print_docstart(struct cgit_context *ctx)
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)
diff --git a/ui-shared.h b/ui-shared.h
index 3005d30..07da4b4 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -22,17 +22,17 @@ extern 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);
diff --git a/ui-tag.c b/ui-tag.c
index ab2c66d..b4db32e 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -52,17 +52,17 @@ void cgit_print_tag(char *revname)
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>");