From 40e174d5364910750413d94b5417e57d108190ef Mon Sep 17 00:00:00 2001 From: Ragnar Ouchterlony Date: Sun, 13 Sep 2009 19:36:35 +0200 Subject: First version of side-by-side diff. This constitutes the first prototype of a side-by-side diff. It is not possible to switch between unidiff and side-by-side diff at all at this stage. Signed-off-by: Ragnar Ouchterlony Signed-off-by: Lars Hjemli --- ui-diff.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index 2196745..0c6f8d7 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -9,6 +9,7 @@ #include "cgit.h" #include "html.h" #include "ui-shared.h" +#include "ui-ssdiff.h" unsigned char old_rev_sha1[20]; unsigned char new_rev_sha1[20]; @@ -32,6 +33,7 @@ static struct fileinfo { int binary:1; } *items; +static int use_ssdiff = 0; static void print_fileinfo(struct fileinfo *info) { @@ -244,6 +246,8 @@ static void header(unsigned char *sha1, char *path1, int mode1, html_txt(path2); } html(""); + if (use_ssdiff) + cgit_ssdiff_header(); } static void filepair_cb(struct diff_filepair *pair) @@ -251,9 +255,14 @@ static void filepair_cb(struct diff_filepair *pair) unsigned long old_size = 0; unsigned long new_size = 0; int binary = 0; + linediff_fn print_line_fn = print_line; header(pair->one->sha1, pair->one->path, pair->one->mode, pair->two->sha1, pair->two->path, pair->two->mode); + if (use_ssdiff) { + cgit_ssdiff_header(); + print_line_fn = cgit_ssdiff_line_cb; + } if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { if (S_ISGITLINK(pair->one->mode)) print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); @@ -261,11 +270,13 @@ static void filepair_cb(struct diff_filepair *pair) print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); return; } - if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, - &new_size, &binary, print_line)) + if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + &new_size, &binary, print_line_fn)) cgit_print_error("Error running diff"); if (binary) html("Binary files differ"); + if (use_ssdiff) + cgit_ssdiff_footer(); } void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) -- cgit v1.2.3 From c358aa3dfebf4fc1f3005dd960aa5c1c020eed76 Mon Sep 17 00:00:00 2001 From: Ragnar Ouchterlony Date: Mon, 14 Sep 2009 20:19:02 +0200 Subject: Add possibility to switch between unidiff and side-by-side-diff. A new config option side-by-side-diffs added, defaulting to 0, meaning unidiff. Also a query option (ss) is used toggle this. In the commit page you can switch between the two diff formats by clicking on the link on the "commit"-row, to the right of (patch). In the diff page you can switch by using the link at the start of the page. All commit-links and diff-links will remember the choice. Signed-off-by: Ragnar Ouchterlony Signed-off-by: Lars Hjemli --- ui-diff.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index 0c6f8d7..42e81ac 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -85,7 +85,7 @@ static void print_fileinfo(struct fileinfo *info) } htmlf("", class); cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, - ctx.qry.sha2, info->new_path); + 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", @@ -160,7 +160,7 @@ void cgit_print_diffstat(const unsigned char *old_sha1, html("
"); cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, - ctx.qry.sha2, NULL); + ctx.qry.sha2, NULL, 0); html("
"); html(""); max_changes = 0; @@ -250,6 +250,19 @@ static void header(unsigned char *sha1, char *path1, int mode1, cgit_ssdiff_header(); } +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, NULL, 1); + else + cgit_diff_link("Side-by-side diff", NULL, NULL, + ctx.qry.head, ctx.qry.sha1, + ctx.qry.sha2, NULL, 1); + } +} + static void filepair_cb(struct diff_filepair *pair) { unsigned long old_size = 0; @@ -314,6 +327,11 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi if (!commit2 || parse_commit(commit2)) cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); } + + if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) + use_ssdiff = 1; + + print_ssdiff_link(); cgit_print_diffstat(old_rev_sha1, new_rev_sha1); html("
"); -- cgit v1.2.3 From 207cc34711039329b41345f716bf421a88a6fd0a Mon Sep 17 00:00:00 2001 From: Ragnar Ouchterlony Date: Tue, 15 Sep 2009 19:44:37 +0200 Subject: Polishing of how the side-by-side diff looks. Aligned all different files, so that all side-by-side tables look the same. Also made sure that the tables take up the whole browser width. Also various changes to the css to make things easier on the eye. Signed-off-by: Ragnar Ouchterlony Signed-off-by: Lars Hjemli --- ui-diff.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index 42e81ac..b21c2c1 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -246,8 +246,6 @@ static void header(unsigned char *sha1, char *path1, int mode1, html_txt(path2); } html(""); - if (use_ssdiff) - cgit_ssdiff_header(); } static void print_ssdiff_link() @@ -270,24 +268,26 @@ static void filepair_cb(struct diff_filepair *pair) int binary = 0; linediff_fn print_line_fn = print_line; - header(pair->one->sha1, pair->one->path, pair->one->mode, - pair->two->sha1, pair->two->path, pair->two->mode); if (use_ssdiff) { - cgit_ssdiff_header(); + cgit_ssdiff_header_begin(); print_line_fn = cgit_ssdiff_line_cb; } + header(pair->one->sha1, pair->one->path, pair->one->mode, + pair->two->sha1, pair->two->path, pair->two->mode); + if (use_ssdiff) + cgit_ssdiff_header_end(); if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { if (S_ISGITLINK(pair->one->mode)) - print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); + print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); if (S_ISGITLINK(pair->two->mode)) - print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); + print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); return; } if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, &binary, print_line_fn)) cgit_print_error("Error running diff"); if (binary) - html("Binary files differ"); + print_line_fn(" Binary files differ", 20); if (use_ssdiff) cgit_ssdiff_footer(); } @@ -334,9 +334,14 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi print_ssdiff_link(); cgit_print_diffstat(old_rev_sha1, new_rev_sha1); - html("
"); - html(""); + else + html("Binary files differ"); + } if (use_ssdiff) cgit_ssdiff_footer(); } -- cgit v1.2.3
"); + if (use_ssdiff) { + html(""); + } else { + html("
"); + html(""); + if (!use_ssdiff) + html(""); html("
"); + } cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); - html("
"); } -- cgit v1.2.3 From 4a198e4b8ee62a9a8b5156a46bfce46dc7223fe9 Mon Sep 17 00:00:00 2001 From: Ragnar Ouchterlony Date: Wed, 16 Sep 2009 18:56:26 +0200 Subject: Fixed side-by-side diff bugs related to binary diff and more. The fixed bugs: * "Binary files differ" did not show up either in unidiff or side-by-side-diff. * Subproject diffs did not work for side-by-side diffs. * The ssdiff link on diff pages did not conserve the path. Signed-off-by: Ragnar Ouchterlony Signed-off-by: Lars Hjemli --- ui-diff.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index b21c2c1..a92a768 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -253,11 +253,11 @@ 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, NULL, 1); + 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, NULL, 1); + ctx.qry.sha2, ctx.qry.path, 1); } } @@ -281,13 +281,19 @@ static void filepair_cb(struct diff_filepair *pair) print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); if (S_ISGITLINK(pair->two->mode)) print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); + if (use_ssdiff) + cgit_ssdiff_footer(); return; } if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, &binary, print_line_fn)) cgit_print_error("Error running diff"); - if (binary) - print_line_fn(" Binary files differ", 20); + if (binary) { + if (use_ssdiff) + html("
Binary files differ