summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-02-01 18:29:47 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-02-01 18:29:47 (UTC)
commit5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6 (patch) (side-by-side diff)
tree823678b1c4a907cf0df50067c27fb5b752114df5
parent0b3c746ba80738dbe0885a21406409390936537c (diff)
parent481ce5e298e2dcd7edc1d4a30e523dda2ce58b01 (diff)
downloadcgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.zip
cgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.tar.gz
cgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.tar.bz2
Merge branch 'lh/binary'
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css19
-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
-rw-r--r--ui-tree.c71
7 files changed, 119 insertions, 30 deletions
diff --git a/cgit.css b/cgit.css
index 957d5aa..adfc8ae 100644
--- a/cgit.css
+++ b/cgit.css
@@ -265,2 +265,21 @@ table.blob a.no a:hover {
+table.bin-blob {
+ margin-top: 0.5em;
+ border: solid 1px black;
+}
+
+table.bin-blob th {
+ font-family: monospace;
+ white-space: pre;
+ border: solid 1px #777;
+ padding: 0.5em 1em;
+}
+
+table.bin-blob td {
+ font-family: monospace;
+ white-space: pre;
+ border-left: solid 1px #777;
+ padding: 0em 1em;
+}
+
table.nowrap td {
diff --git a/cgit.h b/cgit.h
index 4942b96..5f7af51 100644
--- a/cgit.h
+++ b/cgit.h
@@ -17,2 +17,3 @@
#include <archive.h>
+#include <xdiff-interface.h>
#include <xdiff/xdiff.h>
@@ -224,3 +225,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);
diff --git a/shared.c b/shared.c
index 578a544..cce0af4 100644
--- a/shared.c
+++ b/shared.c
@@ -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 ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) ||
+ (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) {
+ *binary = 1;
+ return 0;
+ }
+
memset(&diff_params, 0, sizeof(diff_params));
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");
}
diff --git a/ui-log.c b/ui-log.c
index 3202848..ba2ab03 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -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);
}
diff --git a/ui-patch.c b/ui-patch.c
index 1d77336..5d665d3 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -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");
}
diff --git a/ui-tree.c b/ui-tree.c
index c26ba4c..a37a4e5 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -8,2 +8,3 @@
+#include <ctype.h>
#include "cgit.h"
@@ -16,2 +17,44 @@ int header = 0;
+static void print_text_buffer(char *buf, unsigned long size)
+{
+ unsigned long lineno, idx;
+ const char *numberfmt =
+ "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+
+ html("<table summary='blob content' class='blob'>\n");
+ html("<tr><td class='linenumbers'><pre>");
+ idx = 0;
+ lineno = 0;
+ htmlf(numberfmt, ++lineno);
+ while(idx < size - 1) { // skip absolute last newline
+ if (buf[idx] == '\n')
+ htmlf(numberfmt, ++lineno);
+ idx++;
+ }
+ html("</pre></td>\n");
+ html("<td class='lines'><pre><code>");
+ html_txt(buf);
+ html("</code></pre></td></tr></table>\n");
+}
+
+static void print_binary_buffer(char *buf, unsigned long size)
+{
+ unsigned long ofs, idx;
+
+ html("<table summary='blob content' class='bin-blob'>\n");
+ html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
+ for (ofs = 0; ofs < size; ofs += 32, buf += 32) {
+ htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
+ for (idx = 0; idx < 32 && ofs + idx < size; idx++)
+ htmlf("%*s%02x",
+ idx == 16 ? 4 : 1, "",
+ buf[idx] & 0xff);
+ html(" </td><td class='hex'>");
+ for (idx = 0; idx < 32 && ofs + idx < size; idx++)
+ htmlf("%c", isgraph(buf[idx]) ? buf[idx] : '.');
+ html("</td></tr>\n");
+ }
+ html("</table>\n");
+}
+
static void print_object(const unsigned char *sha1, char *path)
@@ -20,4 +63,3 @@ static void print_object(const unsigned char *sha1, char *path)
char *buf;
- unsigned long size, lineno, idx;
- const char *numberfmt = "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+ unsigned long size;
@@ -42,23 +84,6 @@ static void print_object(const unsigned char *sha1, char *path)
- html("<table summary='blob content' class='blob'>\n");
- html("<tr>\n");
-
- html("<td class='linenumbers'><pre>");
- idx = 0;
- lineno = 0;
- htmlf(numberfmt, ++lineno);
- while(idx < size - 1) { // skip absolute last newline
- if (buf[idx] == '\n') {
- htmlf(numberfmt, ++lineno);
- }
- idx++;
- }
- html("</pre></td>\n");
-
- html("<td class='lines'><pre><code>");
- html_txt(buf);
- html("</code></pre></td>\n");
-
- html("</tr>\n");
- html("</table>\n");
+ if (buffer_is_binary(buf, size))
+ print_binary_buffer(buf, size);
+ else
+ print_text_buffer(buf, size);
}