]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-shared.c
Add repo.hide and repo.ignore
[ps-cgit] / ui-shared.c
index 1ede2b0bbfa4a55c49311fde04d6a5a7765d8362..d8cc4d7a3d43beaee1a423a22ea9a33d8a5487e5 100644 (file)
@@ -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 */
@@ -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,
@@ -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) {
@@ -444,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,
@@ -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("<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;
@@ -605,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)
@@ -661,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) {
@@ -699,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");
@@ -719,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");
@@ -728,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)
 {
@@ -875,9 +933,9 @@ void cgit_print_pageheader(void)
                cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
                               ctx.qry.sha1, ctx.qry.vpath);
                cgit_commit_link("commit", NULL, hc("commit"),
-                                ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, 0);
+                                ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath);
                cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
-                              ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath, 0);
+                              ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath);
                if (ctx.repo->max_stats)
                        cgit_stats_link("stats", NULL, hc("stats"),
                                        ctx.qry.head, ctx.qry.vpath);