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) (side-by-side diff)
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) (show 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.c9
-rw-r--r--ui-shared.h2
-rw-r--r--ui-tag.c2
7 files changed, 16 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index e2d5edb..f49fffa 100644
--- a/cgit.c
+++ b/cgit.c
@@ -78,24 +78,26 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "summary-branches"))
ctx.cfg.summary_branches = atoi(value);
else if (!strcmp(name, "summary-tags"))
ctx.cfg.summary_tags = atoi(value);
else if (!strcmp(name, "agefile"))
ctx.cfg.agefile = xstrdup(value);
else if (!strcmp(name, "renamelimit"))
ctx.cfg.renamelimit = atoi(value);
else if (!strcmp(name, "robots"))
ctx.cfg.robots = xstrdup(value);
else if (!strcmp(name, "clone-prefix"))
ctx.cfg.clone_prefix = xstrdup(value);
+ else if (!strcmp(name, "local-time"))
+ ctx.cfg.local_time = atoi(value);
else if (!strcmp(name, "repo.group"))
ctx.cfg.repo_group = xstrdup(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (!strcmp(name, "repo.name"))
ctx.repo->name = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
ctx.repo->path = trim_end(value, '/');
else if (ctx.repo && !strcmp(name, "repo.clone-url"))
ctx.repo->clone_url = xstrdup(value);
else if (ctx.repo && !strcmp(name, "repo.desc"))
ctx.repo->desc = xstrdup(value);
@@ -158,24 +160,25 @@ static void prepare_context(struct cgit_context *ctx)
memset(ctx, 0, sizeof(ctx));
ctx->cfg.agefile = "info/web/last-modified";
ctx->cfg.nocache = 0;
ctx->cfg.cache_size = 0;
ctx->cfg.cache_dynamic_ttl = 5;
ctx->cfg.cache_max_create_time = 5;
ctx->cfg.cache_repo_ttl = 5;
ctx->cfg.cache_root = CGIT_CACHE_ROOT;
ctx->cfg.cache_root_ttl = 5;
ctx->cfg.cache_static_ttl = -1;
ctx->cfg.css = "/cgit.css";
ctx->cfg.logo = "/git-logo.png";
+ ctx->cfg.local_time = 0;
ctx->cfg.max_repo_count = 50;
ctx->cfg.max_commit_count = 50;
ctx->cfg.max_lock_attempts = 5;
ctx->cfg.max_msg_len = 80;
ctx->cfg.max_repodesc_len = 80;
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
ctx->cfg.summary_branches = 10;
diff --git a/cgit.h b/cgit.h
index 7881aca..b01fa31 100644
--- a/cgit.h
+++ b/cgit.h
@@ -13,25 +13,25 @@
#include <diffcore.h>
#include <refs.h>
#include <revision.h>
#include <log-tree.h>
#include <archive.h>
#include <xdiff/xdiff.h>
#include <utf8.h>
/*
* Dateformats used on misc. pages
*/
-#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
+#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
#define FMT_SHORTDATE "%Y-%m-%d"
/*
* Limits used for relative dates
*/
#define TM_MIN 60
#define TM_HOUR (TM_MIN * 60)
#define TM_DAY (TM_HOUR * 24)
#define TM_WEEK (TM_DAY * 7)
#define TM_YEAR (TM_DAY * 365)
#define TM_MONTH (TM_YEAR / 12.0)
@@ -139,24 +139,25 @@ struct cgit_config {
char *root_readme;
char *script_name;
char *virtual_root;
int cache_size;
int cache_dynamic_ttl;
int cache_max_create_time;
int cache_repo_ttl;
int cache_root_ttl;
int cache_static_ttl;
int enable_index_links;
int enable_log_filecount;
int enable_log_linecount;
+ int local_time;
int max_repo_count;
int max_commit_count;
int max_lock_attempts;
int max_msg_len;
int max_repodesc_len;
int nocache;
int renamelimit;
int snapshots;
int summary_branches;
int summary_log;
int summary_tags;
};
diff --git a/ui-commit.c b/ui-commit.c
index 4bbb391..a6a85a4 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -31,32 +31,32 @@ void cgit_print_commit(char *hex)
if (!commit) {
cgit_print_error(fmt("Bad commit reference: %s", hex));
return;
}
info = cgit_parse_commit(commit);
html("<table summary='commit info' class='commit-info'>\n");
html("<tr><th>author</th><td>");
html_txt(info->author);
html(" ");
html_txt(info->author_email);
html("</td><td class='right'>");
- cgit_print_date(info->author_date, FMT_LONGDATE);
+ cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
html("<tr><th>committer</th><td>");
html_txt(info->committer);
html(" ");
html_txt(info->committer_email);
html("</td><td class='right'>");
- cgit_print_date(info->committer_date, FMT_LONGDATE);
+ cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
html("<tr><th>commit</th><td colspan='2' class='sha1'>");
tmp = sha1_to_hex(commit->object.sha1);
cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
html(" (");
cgit_patch_link("patch", NULL, NULL, NULL, tmp);
html(")</td></tr>\n");
html("<tr><th>tree</th><td colspan='2' class='sha1'>");
tmp = xstrdup(hex);
cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
ctx.qry.head, tmp, NULL);
html("</td></tr>\n");
diff --git a/ui-patch.c b/ui-patch.c
index c1c4ce3..e60877d 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -94,25 +94,25 @@ void cgit_print_patch(char *hex)
if (commit->parents && commit->parents->item)
hashcpy(old_sha1, commit->parents->item->object.sha1);
else
hashclr(old_sha1);
patchname = fmt("%s.patch", sha1_to_hex(sha1));
ctx.page.mimetype = "text/plain";
ctx.page.filename = patchname;
cgit_print_http_headers(&ctx);
htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
htmlf("From: %s%s\n", info->author, info->author_email);
html("Date: ");
- cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n");
+ cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
htmlf("Subject: %s\n\n", info->subject);
if (info->msg && *info->msg) {
htmlf("%s", info->msg);
if (info->msg[strlen(info->msg) - 1] != '\n')
html("\n");
}
html("---\n");
cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL);
html("--\n");
htmlf("cgit %s\n", CGIT_VERSION);
cgit_free_commitinfo(info);
}
diff --git a/ui-shared.c b/ui-shared.c
index 4280a70..197ee37 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -344,47 +344,50 @@ void cgit_object_link(struct object *obj)
page = "blob";
arg = "id";
}
url = cgit_pageurl(ctx.qry.repo, page,
fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
html_link_open(url, NULL, NULL);
htmlf("%s %s", typename(obj->type),
sha1_to_hex(obj->sha1));
html_link_close();
}
-void cgit_print_date(time_t secs, char *format)
+void cgit_print_date(time_t secs, char *format, int local_time)
{
char buf[64];
struct tm *time;
if (!secs)
return;
+ if(local_time)
+ time = localtime(&secs);
+ else
time = gmtime(&secs);
strftime(buf, sizeof(buf)-1, format, time);
html_txt(buf);
}
void cgit_print_age(time_t t, time_t max_relative, char *format)
{
time_t now, secs;
if (!t)
return;
time(&now);
secs = now - t;
if (secs > max_relative && max_relative >= 0) {
- cgit_print_date(t, format);
+ cgit_print_date(t, format, ctx.cfg.local_time);
return;
}
if (secs < TM_HOUR * 2) {
htmlf("<span class='age-mins'>%.0f min.</span>",
secs * 1.0 / TM_MIN);
return;
}
if (secs < TM_DAY * 2) {
htmlf("<span class='age-hours'>%.0f hours</span>",
secs * 1.0 / TM_HOUR);
return;
@@ -444,25 +447,25 @@ void cgit_print_docstart(struct cgit_context *ctx)
}
html("</head>\n");
html("<body>\n");
}
void cgit_print_docend()
{
html("</div>");
if (ctx.cfg.footer)
html_include(ctx.cfg.footer);
else {
html("<div class='footer'>generated ");
- cgit_print_date(time(NULL), FMT_LONGDATE);
+ cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
htmlf(" by cgit %s", cgit_version);
html("</div>\n");
}
html("</body>\n</html>\n");
}
int print_branch_option(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
char *name = (char *)refname;
html_option(name, name, ctx.qry.head);
return 0;
diff --git a/ui-shared.h b/ui-shared.h
index 3005d30..07da4b4 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -18,23 +18,23 @@ extern void cgit_commit_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_patch_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_refs_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_snapshot_link(char *name, char *title, char *class,
char *head, char *rev, char *archivename);
extern void cgit_diff_link(char *name, char *title, char *class, char *head,
char *new_rev, char *old_rev, char *path);
extern void cgit_object_link(struct object *obj);
extern void cgit_print_error(char *msg);
-extern void cgit_print_date(time_t secs, char *format);
+extern void cgit_print_date(time_t secs, char *format, int local_time);
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
extern void cgit_print_http_headers(struct cgit_context *ctx);
extern void cgit_print_docstart(struct cgit_context *ctx);
extern void cgit_print_docend();
extern void cgit_print_pageheader(struct cgit_context *ctx);
extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const char *repo, const char *head,
const char *hex, int snapshots);
#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
@@ -48,25 +48,25 @@ void cgit_print_tag(char *revname)
}
if (obj->type == OBJ_TAG) {
tag = lookup_tag(sha1);
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
cgit_print_error(fmt("Bad tag object: %s", revname));
return;
}
html("<table class='commit-info'>\n");
htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n",
revname, sha1_to_hex(sha1));
if (info->tagger_date > 0) {
html("<tr><td>Tag date</td><td>");
- cgit_print_date(info->tagger_date, FMT_LONGDATE);
+ cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
}
if (info->tagger) {
html("<tr><td>Tagged by</td><td>");
html_txt(info->tagger);
html("</td></tr>\n");
}
html("<tr><td>Tagged object</td><td>");
cgit_object_link(tag->tagged);
html("</td></tr>\n");
html("</table>\n");
print_tag_content(info->msg);