]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-shared.c
ui-shared: keep filter repolist page in pagination
[ps-cgit] / ui-shared.c
index 9dde0a39912899c821ff80c318489c86cde8b25b..f8e5bef75852e44b380b0a7a416605d7a7102504 100644 (file)
@@ -144,10 +144,10 @@ static void site_url(const char *page, const char *search, const char *sort, int
 {
        char *delim = "?";
 
 {
        char *delim = "?";
 
-       if (ctx.cfg.virtual_root)
-               html_attr(ctx.cfg.virtual_root);
+       if (!page)
+               html_attr(ctx.qry.url);
        else
        else
-               html_url_path(ctx.cfg.script_name);
+               html_attr(cgit_rooturl());
 
        if (page) {
                htmlf("?p=%s", page);
 
        if (page) {
                htmlf("?p=%s", page);
@@ -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,
 }
 
 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,
 }
 
 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,
 }
 
 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';
 {
        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 = "&";
        }
                html_url_arg(rev);
                delim = "&";
        }
-       if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
+       if (ctx.qry.difftype) {
                html(delim);
                html(delim);
-               html("ss=1");
+               htmlf("dt=%d", ctx.qry.difftype);
                delim = "&";
        }
        if (ctx.qry.context > 0 && ctx.qry.context != 3) {
                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,
 
 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;
 
 {
        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 = "&";
        }
                html_url_arg(old_rev);
                delim = "&";
        }
-       if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
+       if (ctx.qry.difftype) {
                html(delim);
                html(delim);
-               html("ss=1");
+               htmlf("dt=%d", ctx.qry.difftype);
                delim = "&";
        }
        if (ctx.qry.context > 0 && ctx.qry.context != 3) {
                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"))
        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,
        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,
        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,
        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,
        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);
        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,
        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";
                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);
 }
 
        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;
 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) {
        }
 
        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) {
                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) {
                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) {
                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) {
                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;
        }
                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)
 }
 
 void cgit_print_http_headers(void)
@@ -661,6 +671,15 @@ void cgit_print_http_headers(void)
                exit(0);
 }
 
                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) {
 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);
        }
                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");
        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 {
        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");
                        cgit_version);
                cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
                html("</div>\n");
@@ -728,6 +749,31 @@ void cgit_print_docend()
        html("</body>\n</html>\n");
 }
 
        html("</body>\n</html>\n");
 }
 
+static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
+{
+       struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
+       int i;
+
+       for (i = 0; url_list[i]; i++) {
+               strbuf_rtrim(url_list[i]);
+               if (url_list[i]->len == 0)
+                       continue;
+               if (suffix && *suffix)
+                       strbuf_addf(url_list[i], "/%s", suffix);
+               fn(url_list[i]->buf);
+       }
+
+       strbuf_list_free(url_list);
+}
+
+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)
 {
 static int print_branch_option(const char *refname, const unsigned char *sha1,
                               int flags, void *cb_data)
 {
@@ -875,9 +921,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"),
                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,
                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);
                if (ctx.repo->max_stats)
                        cgit_stats_link("stats", NULL, hc("stats"),
                                        ctx.qry.head, ctx.qry.vpath);
@@ -906,7 +952,7 @@ void cgit_print_pageheader(void)
                                  NULL, NULL, 0);
                html("</td><td class='form'>");
                html("<form method='get' action='");
                                  NULL, NULL, 0);
                html("</td><td class='form'>");
                html("<form method='get' action='");
-               html_attr(cgit_rooturl());
+               html_attr(ctx.qry.url);
                html("'>\n");
                html("<input type='text' name='q' size='10' value='");
                html_attr(ctx.qry.search);
                html("'>\n");
                html("<input type='text' name='q' size='10' value='");
                html_attr(ctx.qry.search);