summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h4
-rw-r--r--shared.c13
-rw-r--r--ui-diff.c26
-rw-r--r--ui-log.c7
-rw-r--r--ui-patch.c9
5 files changed, 52 insertions, 7 deletions
diff --git a/cgit.h b/cgit.h
index 4fe94c6..8b0defa 100644
--- a/cgit.h
+++ b/cgit.h
@@ -16,4 +16,5 @@
#include <log-tree.h>
#include <archive.h>
+#include <xdiff-interface.h>
#include <xdiff/xdiff.h>
#include <utf8.h>
@@ -222,5 +223,6 @@ extern void *cgit_free_commitinfo(struct commitinfo *info);
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);
extern void cgit_diff_tree(const unsigned char *old_sha1,
diff --git a/shared.c b/shared.c
index 578a544..dbb84d8 100644
--- a/shared.c
+++ b/shared.c
@@ -258,6 +258,6 @@ 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)
{
mmfile_t file1, file2;
@@ -269,4 +269,13 @@ int cgit_diff_files(const unsigned char *old_sha1,
return 1;
+ *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));
memset(&emit_params, 0, sizeof(emit_params));
diff --git a/ui-diff.c b/ui-diff.c
index 878496d..2196745 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -28,4 +28,7 @@ static struct fileinfo {
unsigned int added;
unsigned int removed;
+ unsigned long old_size;
+ unsigned long new_size;
+ int binary:1;
} *items;
@@ -87,4 +90,9 @@ static void print_fileinfo(struct fileinfo *info)
info->old_path);
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);
html("</td><td class='graph'>");
@@ -111,8 +119,12 @@ static void count_diff_lines(char *line, int len)
static void inspect_filepair(struct diff_filepair *pair)
{
+ int binary = 0;
+ unsigned long old_size = 0;
+ unsigned long new_size = 0;
files++;
lines_added = 0;
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) {
if (slots == 0)
@@ -131,4 +143,7 @@ static void inspect_filepair(struct diff_filepair *pair)
items[files-1].added = lines_added;
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)
max_changes = lines_added + lines_removed;
@@ -234,4 +249,8 @@ static void header(unsigned char *sha1, char *path1, int mode1,
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,
pair->two->sha1, pair->two->path, pair->two->mode);
@@ -243,6 +262,9 @@ static void filepair_cb(struct diff_filepair *pair)
return;
}
- 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");
}
diff --git a/ui-log.c b/ui-log.c
index 3202848..ba2ab03 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -27,7 +27,12 @@ void count_lines(char *line, int size)
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);
}
diff --git a/ui-patch.c b/ui-patch.c
index 1d77336..5d665d3 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -58,4 +58,8 @@ static void header(unsigned char *sha1, char *path1, int mode1,
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,
pair->two->sha1, pair->two->path, pair->two->mode);
@@ -67,6 +71,9 @@ static void filepair_cb(struct diff_filepair *pair)
return;
}
- 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");
}