X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/f60ffa143cca61e9729ac71033e1a556cf422871..caed6cb:/ui-shared.c
diff --git a/ui-shared.c b/ui-shared.c
index 070971f..bd74f42 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -128,7 +128,7 @@ const char *cgit_repobasename(const char *reponame)
/* strip trailing slashes */
while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
/* strip trailing .git */
- if (p >= 3 && !prefixcmp(&rvbuf[p-3], ".git")) {
+ if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
p -= 3; rvbuf[p--] = 0;
}
/* strip more trailing slashes if any */
@@ -328,8 +328,7 @@ void cgit_log_link(const char *name, const char *title, const char *class,
}
void cgit_commit_link(char *name, const char *title, const char *class,
- const char *head, const char *rev, const char *path,
- int toggle_ssdiff)
+ const char *head, const char *rev, const char *path)
{
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
name[ctx.cfg.max_msg_len] = '\0';
@@ -347,9 +346,9 @@ void cgit_commit_link(char *name, const char *title, const char *class,
html_url_arg(rev);
delim = "&";
}
- if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
+ if (ctx.qry.difftype) {
html(delim);
- html("ss=1");
+ htmlf("dt=%d", ctx.qry.difftype);
delim = "&";
}
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
@@ -386,7 +385,7 @@ void cgit_snapshot_link(const char *name, const char *title, const char *class,
void cgit_diff_link(const char *name, const char *title, const char *class,
const char *head, const char *new_rev, const char *old_rev,
- const char *path, int toggle_ssdiff)
+ const char *path)
{
char *delim;
@@ -403,9 +402,9 @@ void cgit_diff_link(const char *name, const char *title, const char *class,
html_url_arg(old_rev);
delim = "&";
}
- if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
+ if (ctx.qry.difftype) {
html(delim);
- html("ss=1");
+ htmlf("dt=%d", ctx.qry.difftype);
delim = "&";
}
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
@@ -463,7 +462,7 @@ static void cgit_self_link(char *name, const char *title, const char *class)
else if (!strcmp(ctx.qry.page, "commit"))
cgit_commit_link(name, title, class, ctx.qry.head,
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
- ctx.qry.path, 0);
+ ctx.qry.path);
else if (!strcmp(ctx.qry.page, "patch"))
cgit_patch_link(name, title, class, ctx.qry.head,
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
@@ -479,7 +478,7 @@ static void cgit_self_link(char *name, const char *title, const char *class)
else if (!strcmp(ctx.qry.page, "diff"))
cgit_diff_link(name, title, class, ctx.qry.head,
ctx.qry.sha1, ctx.qry.sha2,
- ctx.qry.path, 0);
+ ctx.qry.path);
else if (!strcmp(ctx.qry.page, "stats"))
cgit_stats_link(name, title, class, ctx.qry.head,
ctx.qry.path);
@@ -503,7 +502,7 @@ void cgit_object_link(struct object *obj)
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
- ctx.qry.head, fullrev, NULL, 0);
+ ctx.qry.head, fullrev, NULL);
return;
} else if (obj->type == OBJ_TREE)
page = "tree";
@@ -588,6 +587,23 @@ void cgit_print_date(time_t secs, const char *format, int local_time)
html_txt(buf);
}
+static void print_rel_date(time_t t, double value,
+ const char *class, const char *suffix)
+{
+ char buf[64];
+ struct tm *time;
+
+ if (ctx.cfg.local_time)
+ time = localtime(&t);
+ else
+ time = gmtime(&t);
+ strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time);
+
+ htmlf("%.0f %s", value, suffix);
+}
+
void cgit_print_age(time_t t, time_t max_relative, const char *format)
{
time_t now, secs;
@@ -596,6 +612,8 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
return;
time(&now);
secs = now - t;
+ if (secs < 0)
+ secs = 0;
if (secs > max_relative && max_relative >= 0) {
cgit_print_date(t, format, ctx.cfg.local_time);
@@ -603,32 +621,26 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
}
if (secs < TM_HOUR * 2) {
- htmlf("%.0f min.",
- secs * 1.0 / TM_MIN);
+ print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min.");
return;
}
if (secs < TM_DAY * 2) {
- htmlf("%.0f hours",
- secs * 1.0 / TM_HOUR);
+ print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours");
return;
}
if (secs < TM_WEEK * 2) {
- htmlf("%.0f days",
- secs * 1.0 / TM_DAY);
+ print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days");
return;
}
if (secs < TM_MONTH * 2) {
- htmlf("%.0f weeks",
- secs * 1.0 / TM_WEEK);
+ print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
return;
}
if (secs < TM_YEAR * 2) {
- htmlf("%.0f months",
- secs * 1.0 / TM_MONTH);
+ print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months");
return;
}
- htmlf("%.0f years",
- secs * 1.0 / TM_YEAR);
+ print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years");
}
void cgit_print_http_headers(void)
@@ -659,6 +671,15 @@ void cgit_print_http_headers(void)
exit(0);
}
+static void print_rel_vcs_link(const char *url)
+{
+ html("\n");
+}
+
void cgit_print_docstart(void)
{
if (ctx.cfg.embedded) {
@@ -697,6 +718,8 @@ void cgit_print_docstart(void)
html("' type='application/atom+xml'/>\n");
strbuf_release(&sb);
}
+ if (ctx.repo)
+ cgit_add_clone_urls(print_rel_vcs_link);
if (ctx.cfg.head_include)
html_include(ctx.cfg.head_include);
html("\n");
@@ -726,6 +749,43 @@ void cgit_print_docend()
html("