]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-shared.c
Add repo.hide and repo.ignore
[ps-cgit] / ui-shared.c
index 68e0d7cdf40c2573a532af1e80a109106b90b485..d8cc4d7a3d43beaee1a423a22ea9a33d8a5487e5 100644 (file)
@@ -273,9 +273,9 @@ void cgit_summary_link(const char *name, const char *title, const char *class,
 }
 
 void cgit_tag_link(const char *name, const char *title, const char *class,
-                  const char *head, const char *rev)
+                  const char *tag)
 {
-       reporevlink("tag", name, title, class, head, rev, NULL);
+       reporevlink("tag", name, title, class, tag, NULL, NULL);
 }
 
 void cgit_tree_link(const char *name, const char *title, const char *class,
@@ -346,9 +346,9 @@ void cgit_commit_link(char *name, const char *title, const char *class,
                html_url_arg(rev);
                delim = "&";
        }
-       if (ctx.qry.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) {
@@ -402,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) {
+       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) {
@@ -443,8 +443,8 @@ static void cgit_self_link(char *name, const char *title, const char *class)
        else if (!strcmp(ctx.qry.page, "summary"))
                cgit_summary_link(name, title, class, ctx.qry.head);
        else if (!strcmp(ctx.qry.page, "tag"))
-               cgit_tag_link(name, title, class, ctx.qry.head,
-                             ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL);
+               cgit_tag_link(name, title, class, ctx.qry.has_sha1 ?
+                              ctx.qry.sha1 : ctx.qry.head);
        else if (!strcmp(ctx.qry.page, "tree"))
                cgit_tree_link(name, title, class, ctx.qry.head,
                               ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
@@ -587,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("<span class='%s' title='", class);
+       html_attr(buf);
+       htmlf("'>%.0f %s</span>", value, suffix);
+}
+
 void cgit_print_age(time_t t, time_t max_relative, const char *format)
 {
        time_t now, secs;
@@ -604,32 +621,26 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
        }
 
        if (secs < TM_HOUR * 2) {
-               htmlf("<span class='age-mins'>%.0f min.</span>",
-                     secs * 1.0 / TM_MIN);
+               print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min.");
                return;
        }
        if (secs < TM_DAY * 2) {
-               htmlf("<span class='age-hours'>%.0f hours</span>",
-                     secs * 1.0 / TM_HOUR);
+               print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours");
                return;
        }
        if (secs < TM_WEEK * 2) {
-               htmlf("<span class='age-days'>%.0f days</span>",
-                     secs * 1.0 / TM_DAY);
+               print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days");
                return;
        }
        if (secs < TM_MONTH * 2) {
-               htmlf("<span class='age-weeks'>%.0f weeks</span>",
-                     secs * 1.0 / TM_WEEK);
+               print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
                return;
        }
        if (secs < TM_YEAR * 2) {
-               htmlf("<span class='age-months'>%.0f months</span>",
-                     secs * 1.0 / TM_MONTH);
+               print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months");
                return;
        }
-       htmlf("<span class='age-years'>%.0f years</span>",
-             secs * 1.0 / TM_YEAR);
+       print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years");
 }
 
 void cgit_print_http_headers(void)
@@ -660,6 +671,15 @@ void cgit_print_http_headers(void)
                exit(0);
 }
 
+static void print_rel_vcs_link(const char *url)
+{
+       html("<link rel='vcs-git' href='");
+       html_attr(url);
+       html("' title='");
+       html_attr(ctx.repo->name);
+       html(" Git repository'/>\n");
+}
+
 void cgit_print_docstart(void)
 {
        if (ctx.cfg.embedded) {
@@ -698,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("</head>\n");
@@ -718,7 +740,7 @@ void cgit_print_docend()
        if (ctx.cfg.footer)
                html_include(ctx.cfg.footer);
        else {
-               htmlf("<div class='footer'>generated  by cgit %s at ",
+               htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
                        cgit_version);
                cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
                html("</div>\n");
@@ -727,6 +749,43 @@ void cgit_print_docend()
        html("</body>\n</html>\n");
 }
 
+static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
+{
+       struct strbuf buf = STRBUF_INIT;
+       char *h = txt, *t, c;
+
+       while (h && *h) {
+               while (h && *h == ' ')
+                       h++;
+               if (!*h)
+                       break;
+               t = h;
+               while (t && *t && *t != ' ')
+                       t++;
+               c = *t;
+               *t = 0;
+
+               if (suffix && *suffix) {
+                       strbuf_reset(&buf);
+                       strbuf_addf(&buf, "%s/%s", h, suffix);
+                       h = buf.buf;
+               }
+               fn(h);
+               *t = c;
+               h = t;
+       }
+
+       strbuf_release(&buf);
+}
+
+void cgit_add_clone_urls(void (*fn)(const char *))
+{
+       if (ctx.repo->clone_url)
+               add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL);
+       else if (ctx.cfg.clone_prefix)
+               add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
+}
+
 static int print_branch_option(const char *refname, const unsigned char *sha1,
                               int flags, void *cb_data)
 {