-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | shared.c | 13 | ||||
-rw-r--r-- | ui-diff.c | 26 | ||||
-rw-r--r-- | ui-log.c | 7 | ||||
-rw-r--r-- | ui-patch.c | 9 |
5 files changed, 52 insertions, 7 deletions
@@ -17,2 +17,3 @@ #include <archive.h> +#include <xdiff-interface.h> #include <xdiff/xdiff.h> @@ -223,3 +224,4 @@ extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, - linediff_fn fn); + unsigned long *old_size, unsigned long *new_size, + int *binary, linediff_fn fn); @@ -259,4 +259,4 @@ int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) int cgit_diff_files(const unsigned char *old_sha1, - const unsigned char *new_sha1, - linediff_fn fn) + const unsigned char *new_sha1, unsigned long *old_size, + unsigned long *new_size, int *binary, linediff_fn fn) { @@ -270,2 +270,11 @@ int cgit_diff_files(const unsigned char *old_sha1, + *old_size = file1.size; + *new_size = file2.size; + + if (buffer_is_binary(file1.ptr, file1.size) || + buffer_is_binary(file2.ptr, file2.size)) { + *binary = 1; + return 0; + } + memset(&diff_params, 0, sizeof(diff_params)); @@ -29,2 +29,5 @@ static struct fileinfo { unsigned int removed; + unsigned long old_size; + unsigned long new_size; + int binary:1; } *items; @@ -88,2 +91,7 @@ static void print_fileinfo(struct fileinfo *info) html("</td><td class='right'>"); + if (info->binary) { + htmlf("bin</td><td class='graph'>%d -> %d bytes", + info->old_size, info->new_size); + return; + } htmlf("%d", info->added + info->removed); @@ -112,2 +120,5 @@ static void inspect_filepair(struct diff_filepair *pair) { + int binary = 0; + unsigned long old_size = 0; + unsigned long new_size = 0; files++; @@ -115,3 +126,4 @@ static void inspect_filepair(struct diff_filepair *pair) lines_removed = 0; - cgit_diff_files(pair->one->sha1, pair->two->sha1, count_diff_lines); + cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, + &binary, count_diff_lines); if (files >= slots) { @@ -132,2 +144,5 @@ static void inspect_filepair(struct diff_filepair *pair) items[files-1].removed = lines_removed; + items[files-1].old_size = old_size; + items[files-1].new_size = new_size; + items[files-1].binary = binary; if (lines_added + lines_removed > max_changes) @@ -235,2 +250,6 @@ static void filepair_cb(struct diff_filepair *pair) { + unsigned long old_size = 0; + unsigned long new_size = 0; + int binary = 0; + header(pair->one->sha1, pair->one->path, pair->one->mode, @@ -244,4 +263,7 @@ static void filepair_cb(struct diff_filepair *pair) } - if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) + if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + &new_size, &binary, print_line)) cgit_print_error("Error running diff"); + if (binary) + html("Binary files differ"); } @@ -28,5 +28,10 @@ void inspect_files(struct diff_filepair *pair) { + unsigned long old_size = 0; + unsigned long new_size = 0; + int binary = 0; + files++; if (ctx.repo->enable_log_linecount) - cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); + cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + &new_size, &binary, count_lines); } @@ -59,2 +59,6 @@ static void filepair_cb(struct diff_filepair *pair) { + unsigned long old_size = 0; + unsigned long new_size = 0; + int binary = 0; + header(pair->one->sha1, pair->one->path, pair->one->mode, @@ -68,4 +72,7 @@ static void filepair_cb(struct diff_filepair *pair) } - if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) + if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + &new_size, &binary, print_line)) html("Error running diff"); + if (binary) + html("Binary files differ\n"); } |