]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/panel'
authorLars Hjemli <hjemli@gmail.com>
Mon, 23 May 2011 21:29:24 +0000 (23:29 +0200)
committerLars Hjemli <hjemli@gmail.com>
Mon, 23 May 2011 21:29:24 +0000 (23:29 +0200)
1  2 
cmd.c
html.c
ui-commit.c
ui-diff.c

diff --combined cmd.c
index d114eb3fd6dc46a49d2180304b394e3423a430a7,05d5aaf44e70dd987eb151bffa238b33b946aeda..5a3d1574556e5a09510b891482ef38b22b0ca8a6
--- 1/cmd.c
--- 2/cmd.c
+++ b/cmd.c
@@@ -56,7 -56,7 +56,7 @@@ static void commit_fn(struct cgit_conte
  
  static void diff_fn(struct cgit_context *ctx)
  {
-       cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
+       cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1);
  }
  
  static void info_fn(struct cgit_context *ctx)
@@@ -130,31 -130,31 +130,31 @@@ static void tree_fn(struct cgit_contex
        cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
  }
  
 -#define def_cmd(name, want_repo, want_layout, want_vpath) \
 -      {#name, name##_fn, want_repo, want_layout, want_vpath}
 +#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \
 +      {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone}
  
  struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
  {
        static struct cgit_cmd cmds[] = {
 -              def_cmd(HEAD, 1, 0, 0),
 -              def_cmd(atom, 1, 0, 0),
 -              def_cmd(about, 0, 1, 0),
 -              def_cmd(blob, 1, 0, 0),
 -              def_cmd(commit, 1, 1, 1),
 -              def_cmd(diff, 1, 1, 1),
 -              def_cmd(info, 1, 0, 0),
 -              def_cmd(log, 1, 1, 1),
 -              def_cmd(ls_cache, 0, 0, 0),
 -              def_cmd(objects, 1, 0, 0),
 -              def_cmd(patch, 1, 0, 1),
 -              def_cmd(plain, 1, 0, 0),
 -              def_cmd(refs, 1, 1, 0),
 -              def_cmd(repolist, 0, 0, 0),
 -              def_cmd(snapshot, 1, 0, 0),
 -              def_cmd(stats, 1, 1, 1),
 -              def_cmd(summary, 1, 1, 0),
 -              def_cmd(tag, 1, 1, 0),
 -              def_cmd(tree, 1, 1, 1),
 +              def_cmd(HEAD, 1, 0, 0, 1),
 +              def_cmd(atom, 1, 0, 0, 0),
 +              def_cmd(about, 0, 1, 0, 0),
 +              def_cmd(blob, 1, 0, 0, 0),
 +              def_cmd(commit, 1, 1, 1, 0),
 +              def_cmd(diff, 1, 1, 1, 0),
 +              def_cmd(info, 1, 0, 0, 1),
 +              def_cmd(log, 1, 1, 1, 0),
 +              def_cmd(ls_cache, 0, 0, 0, 0),
 +              def_cmd(objects, 1, 0, 0, 1),
 +              def_cmd(patch, 1, 0, 1, 0),
 +              def_cmd(plain, 1, 0, 0, 0),
 +              def_cmd(refs, 1, 1, 0, 0),
 +              def_cmd(repolist, 0, 0, 0, 0),
 +              def_cmd(snapshot, 1, 0, 0, 0),
 +              def_cmd(stats, 1, 1, 1, 0),
 +              def_cmd(summary, 1, 1, 0, 0),
 +              def_cmd(tag, 1, 1, 0, 0),
 +              def_cmd(tree, 1, 1, 1, 0),
        };
        int i;
  
diff --combined html.c
index a0f6db4b04bdca2215d0425f9f85ed70933d08ce,ae1cef983265979144a6e1c6da835fd4746ae630..4a18a574e23cf8820997e0abc4111ac66e5d98e5
--- 1/html.c
--- 2/html.c
+++ b/html.c
@@@ -18,7 -18,7 +18,7 @@@ static const char* url_escape_table[256
        "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
        "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
        "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
 -      "%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
 +      "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
        "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
        "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
@@@ -162,9 -162,9 +162,9 @@@ void html_url_path(const char *txt
        while(t && *t){
                int c = *t;
                const char *e = url_escape_table[c];
 -              if (e && c!='+' && c!='&' && c!='+') {
 +              if (e && c!='+' && c!='&') {
                        html_raw(txt, t - txt);
 -                      html_raw(e, 3);
 +                      html(e);
                        txt = t+1;
                }
                t++;
@@@ -179,11 -179,9 +179,11 @@@ void html_url_arg(const char *txt
        while(t && *t){
                int c = *t;
                const char *e = url_escape_table[c];
 +              if (c == ' ')
 +                      e = "+";
                if (e) {
                        html_raw(txt, t - txt);
 -                      html_raw(e, strlen(e));
 +                      html(e);
                        txt = t+1;
                }
                t++;
@@@ -213,6 -211,14 +213,14 @@@ void html_option(const char *value, con
        html("</option>\n");
  }
  
+ void html_intoption(int value, const char *text, int selected_value)
+ {
+       htmlf("<option value='%d'%s>", value,
+             value == selected_value ? " selected='selected'" : "");
+       html_txt(text);
+       html("</option>");
+ }
  void html_link_open(const char *url, const char *title, const char *class)
  {
        html("<a href='");
@@@ -290,12 -296,12 +298,12 @@@ char *convert_query_hexchar(char *txt
  
  int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
  {
 -      char *t, *txt, *value = NULL, c;
 +      char *o, *t, *txt, *value = NULL, c;
  
        if (!txt_)
                return 0;
  
 -      t = txt = strdup(txt_);
 +      o = t = txt = strdup(txt_);
        if (t == NULL) {
                printf("Out of memory\n");
                exit(1);
        }
        if (t!=txt)
                (*fn)(txt, value);
 +      free(o);
        return 0;
  }
diff --combined ui-commit.c
index 2da9fcf2b356f6ebabe49d814311406b587f8154,536a8e82d5486be05e98f59079ba1c7bfe536d75..a69dec649f05cb8035f415dc395ed6d1f312f921
@@@ -39,7 -39,8 +39,8 @@@ void cgit_print_commit(char *hex, cons
        format_note(NULL, sha1, &notes, PAGE_ENCODING, 0);
  
        load_ref_decorations(DECORATE_FULL_REFS);
+       
+       cgit_print_diff_ctrls();
        html("<table summary='commit info' class='commit-info'>\n");
        html("<tr><th>author</th><td>");
        html_txt(info->author);
        cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
        html(" (");
        cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
-       html(") (");
-       if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
-               cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
-       else
-               cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
        html(")</td></tr>\n");
        html("<tr><th>tree</th><td colspan='2' class='sha1'>");
        tmp = xstrdup(hex);
        html("</table>\n");
        html("<div class='commit-subject'>");
        if (ctx.repo->commit_filter)
 -              cgit_open_filter(ctx.repo->commit_filter);
 +              cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
        html_txt(info->subject);
        if (ctx.repo->commit_filter)
                cgit_close_filter(ctx.repo->commit_filter);
        html("</div>");
        html("<div class='commit-msg'>");
        if (ctx.repo->commit_filter)
 -              cgit_open_filter(ctx.repo->commit_filter);
 +              cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
        html_txt(info->msg);
        if (ctx.repo->commit_filter)
                cgit_close_filter(ctx.repo->commit_filter);
                html("<div class='notes-header'>Notes</div>");
                html("<div class='notes'>");
                if (ctx.repo->commit_filter)
 -                      cgit_open_filter(ctx.repo->commit_filter);
 +                      cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
                html_txt(notes.buf);
                if (ctx.repo->commit_filter)
                        cgit_close_filter(ctx.repo->commit_filter);
                        tmp = sha1_to_hex(commit->parents->item->object.sha1);
                else
                        tmp = NULL;
-               cgit_print_diff(ctx.qry.sha1, tmp, prefix);
+               cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
        }
        strbuf_release(&notes);
        cgit_free_commitinfo(info);
diff --combined ui-diff.c
index d21541bd4d2b79d19222fc9dd09ae14e70d59e51,b7767b3c07a23ea06e3aa3aab103fe3bf765cfe4..868ceec23b813f8dbd39b9eda8249131caa308e3
+++ b/ui-diff.c
@@@ -167,7 -167,7 +167,7 @@@ static void inspect_filepair(struct dif
  void cgit_print_diffstat(const unsigned char *old_sha1,
                         const unsigned char *new_sha1, const char *prefix)
  {
-       int i, save_context = ctx.qry.context;
+       int i;
  
        html("<div class='diffstat-header'>");
        cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
                html_txt(prefix);
                html("')");
        }
-       html(" (");
-       ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
-       cgit_self_link("more", NULL, NULL, &ctx);
-       html("/");
-       ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
-       cgit_self_link("less", NULL, NULL, &ctx);
-       ctx.qry.context = save_context;
-       html(" context)");
-       html(" (");
-       ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
-       cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
-       ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
-       html(" whitespace changes)");
        html("</div>");
        html("<table summary='diffstat' class='diffstat'>");
        max_changes = 0;
@@@ -278,19 -265,6 +265,6 @@@ static void header(unsigned char *sha1
        html("</div>");
  }
  
- static void print_ssdiff_link()
- {
-       if (!strcmp(ctx.qry.page, "diff")) {
-               if (use_ssdiff)
-                       cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
-                                      ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
-               else
-                       cgit_diff_link("Side-by-side diff", NULL, NULL,
-                                      ctx.qry.head, ctx.qry.sha1,
-                                      ctx.qry.sha2, ctx.qry.path, 1);
-       }
- }
  static void filepair_cb(struct diff_filepair *pair)
  {
        unsigned long old_size = 0;
                cgit_ssdiff_footer();
  }
  
- void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
+ void cgit_print_diff_ctrls()
+ {
+       int i, curr;
+       html("<div class='cgit-panel'>");
+       html("<b>diff options</b>");
+       html("<form method='get' action='.'>");
+       cgit_add_hidden_formfields(1, 0, ctx.qry.page);
+       html("<table>");
+       html("<tr><td colspan='2'/></tr>");
+       html("<tr>");
+       html("<td class='label'>context:</td>");
+       html("<td class='ctrl'>");
+       html("<select name='context' onchange='this.form.submit();'>");
+       curr = ctx.qry.context;
+       if (!curr)
+               curr = 3;
+       for (i = 1; i <= 10; i++)
+               html_intoption(i, fmt("%d", i), curr);
+       for (i = 15; i <= 40; i += 5)
+               html_intoption(i, fmt("%d", i), curr);
+       html("</select>");
+       html("</td>");
+       html("</tr><tr>");
+       html("<td class='label'>space:</td>");
+       html("<td class='ctrl'>");
+       html("<select name='ignorews' onchange='this.form.submit();'>");
+       html_intoption(0, "include", ctx.qry.ignorews);
+       html_intoption(1, "ignore", ctx.qry.ignorews);
+       html("</select>");
+       html("</td>");
+       html("</tr><tr>");
+       html("<td class='label'>mode:</td>");
+       html("<td class='ctrl'>");
+       html("<select name='ss' onchange='this.form.submit();'>");
+       curr = ctx.qry.ssdiff;
+       if (!curr && ctx.cfg.ssdiff)
+               curr = 1;
+       html_intoption(0, "unified", curr);
+       html_intoption(1, "ssdiff", curr);
+       html("</select></td></tr>");
+       html("<tr><td/><td class='ctrl'>");
+       html("<noscript><input type='submit' value='reload'/></noscript>");
+       html("</td></tr></table>");
+       html("</form>");
+       html("</div>");
+ }
+ void cgit_print_diff(const char *new_rev, const char *old_rev,
+                    const char *prefix, int show_ctrls)
  {
        enum object_type type;
        unsigned long size;
                return;
        }
        commit = lookup_commit_reference(new_rev_sha1);
 -      if (!commit || parse_commit(commit))
 +      if (!commit || parse_commit(commit)) {
                cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
 +              return;
 +      }
  
        if (old_rev)
                get_sha1(old_rev, old_rev_sha1);
                        return;
                }
                commit2 = lookup_commit_reference(old_rev_sha1);
 -              if (!commit2 || parse_commit(commit2))
 +              if (!commit2 || parse_commit(commit2)) {
                        cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
 +                      return;
 +              }
        }
  
        if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
                use_ssdiff = 1;
  
-       print_ssdiff_link();
+       if (show_ctrls)
+               cgit_print_diff_ctrls();
        cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
  
        if (use_ssdiff) {