]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-diff.c
filters/syntax-highlighting.sh: work around highlight --force bug
[ps-cgit] / ui-diff.c
index d3a3b2c8bd04977232baa77004ec2e7015eb51b6..f8782df260c03a5231ecb740658caff4e3f8a583 100644 (file)
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -34,6 +34,17 @@ static struct fileinfo {
 } *items;
 
 static int use_ssdiff = 0;
+static struct diff_filepair *current_filepair;
+
+struct diff_filespec *cgit_get_current_old_file(void)
+{
+       return current_filepair->one;
+}
+
+struct diff_filespec *cgit_get_current_new_file(void)
+{
+       return current_filepair->two;
+}
 
 static void print_fileinfo(struct fileinfo *info)
 {
@@ -86,13 +97,15 @@ static void print_fileinfo(struct fileinfo *info)
        htmlf("</td><td class='%s'>", class);
        cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
                       ctx.qry.sha2, info->new_path, 0);
-       if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
-               htmlf(" (%s from %s)",
-                     info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
-                     info->old_path);
+       if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) {
+               htmlf(" (%s from ",
+                     info->status == DIFF_STATUS_COPIED ? "copied" : "renamed");
+               html_txt(info->old_path);
+               html(")");
+       }
        html("</td><td class='right'>");
        if (info->binary) {
-               htmlf("bin</td><td class='graph'>%d -> %d bytes",
+               htmlf("bin</td><td class='graph'>%ld -> %ld bytes",
                      info->old_size, info->new_size);
                return;
        }
@@ -127,7 +140,7 @@ static void inspect_filepair(struct diff_filepair *pair)
        lines_added = 0;
        lines_removed = 0;
        cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size,
-                       &binary, 0, count_diff_lines);
+                       &binary, 0, ctx.qry.ignorews, count_diff_lines);
        if (files >= slots) {
                if (slots == 0)
                        slots = 4;
@@ -156,17 +169,34 @@ static void inspect_filepair(struct diff_filepair *pair)
 void cgit_print_diffstat(const unsigned char *old_sha1,
                         const unsigned char *new_sha1, const char *prefix)
 {
-       int i;
+       int i, save_context = ctx.qry.context;
 
        html("<div class='diffstat-header'>");
        cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
                       ctx.qry.sha2, NULL, 0);
-       if (prefix)
-               htmlf(" (limited to '%s')", prefix);
+       if (prefix) {
+               html(" (limited to '");
+               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;
-       cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix);
+       cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix,
+                      ctx.qry.ignorews);
        for(i = 0; i<files; i++)
                print_fileinfo(&items[i]);
        html("</table>");
@@ -270,6 +300,7 @@ static void filepair_cb(struct diff_filepair *pair)
        int binary = 0;
        linediff_fn print_line_fn = print_line;
 
+       current_filepair = pair;
        if (use_ssdiff) {
                cgit_ssdiff_header_begin();
                print_line_fn = cgit_ssdiff_line_cb;
@@ -288,7 +319,8 @@ static void filepair_cb(struct diff_filepair *pair)
                return;
        }
        if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
-                           &new_size, &binary, ctx.qry.context, print_line_fn))
+                           &new_size, &binary, ctx.qry.context,
+                           ctx.qry.ignorews, print_line_fn))
                cgit_print_error("Error running diff");
        if (binary) {
                if (use_ssdiff)
@@ -315,8 +347,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
                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);
@@ -332,12 +366,13 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
                        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;
+       use_ssdiff = ctx.qry.has_ssdiff ? ctx.qry.ssdiff : ctx.cfg.ssdiff;
 
        print_ssdiff_link();
        cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
@@ -348,7 +383,8 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
                html("<table summary='diff' class='diff'>");
                html("<tr><td>");
        }
-       cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
+       cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
+                      ctx.qry.ignorews);
        if (!use_ssdiff)
                html("</td></tr>");
        html("</table>");