summaryrefslogtreecommitdiffabout
path: root/ui-diff.c
authorLars Hjemli <hjemli@gmail.com>2009-01-31 09:40:40 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-01-31 09:40:40 (UTC)
commitc495cf02bac16e459f7c9e1740798646f12c00c5 (patch) (side-by-side diff)
treea36ba3904edd96ffc79fdf420fb10d33117a469f /ui-diff.c
parentd6174b7aab476c2b6a86e59d98cf978d603045f4 (diff)
downloadcgit-c495cf02bac16e459f7c9e1740798646f12c00c5.zip
cgit-c495cf02bac16e459f7c9e1740798646f12c00c5.tar.gz
cgit-c495cf02bac16e459f7c9e1740798646f12c00c5.tar.bz2
Handle binary files in diffs
This teaches all diff-related operations (i.e. ui-log, ui-diff and ui-patch) how to handle binary files. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-diff.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-diff.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 878496d..2196745 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -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");
}