Merge branch 'lh/binary'
This commit is contained in:
incheckning
5e447b1ed1
19
cgit.css
19
cgit.css
@ -263,6 +263,25 @@ table.blob a.no a:hover {
|
|||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
table.nowrap td {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
4
cgit.h
4
cgit.h
@ -15,6 +15,7 @@
|
|||||||
#include <revision.h>
|
#include <revision.h>
|
||||||
#include <log-tree.h>
|
#include <log-tree.h>
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
|
#include <xdiff-interface.h>
|
||||||
#include <xdiff/xdiff.h>
|
#include <xdiff/xdiff.h>
|
||||||
#include <utf8.h>
|
#include <utf8.h>
|
||||||
|
|
||||||
@ -222,7 +223,8 @@ extern void *cgit_free_commitinfo(struct commitinfo *info);
|
|||||||
|
|
||||||
extern int cgit_diff_files(const unsigned char *old_sha1,
|
extern int cgit_diff_files(const unsigned char *old_sha1,
|
||||||
const unsigned char *new_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,
|
extern void cgit_diff_tree(const unsigned char *old_sha1,
|
||||||
const unsigned char *new_sha1,
|
const unsigned char *new_sha1,
|
||||||
|
13
shared.c
13
shared.c
@ -257,8 +257,8 @@ int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int cgit_diff_files(const unsigned char *old_sha1,
|
int cgit_diff_files(const unsigned char *old_sha1,
|
||||||
const unsigned char *new_sha1,
|
const unsigned char *new_sha1, unsigned long *old_size,
|
||||||
linediff_fn fn)
|
unsigned long *new_size, int *binary, linediff_fn fn)
|
||||||
{
|
{
|
||||||
mmfile_t file1, file2;
|
mmfile_t file1, file2;
|
||||||
xpparam_t diff_params;
|
xpparam_t diff_params;
|
||||||
@ -268,6 +268,15 @@ int cgit_diff_files(const unsigned char *old_sha1,
|
|||||||
if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1))
|
if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
*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));
|
memset(&diff_params, 0, sizeof(diff_params));
|
||||||
memset(&emit_params, 0, sizeof(emit_params));
|
memset(&emit_params, 0, sizeof(emit_params));
|
||||||
memset(&emit_cb, 0, sizeof(emit_cb));
|
memset(&emit_cb, 0, sizeof(emit_cb));
|
||||||
|
26
ui-diff.c
26
ui-diff.c
@ -27,6 +27,9 @@ static struct fileinfo {
|
|||||||
char *new_path;
|
char *new_path;
|
||||||
unsigned int added;
|
unsigned int added;
|
||||||
unsigned int removed;
|
unsigned int removed;
|
||||||
|
unsigned long old_size;
|
||||||
|
unsigned long new_size;
|
||||||
|
int binary:1;
|
||||||
} *items;
|
} *items;
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +89,11 @@ static void print_fileinfo(struct fileinfo *info)
|
|||||||
info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
|
info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
|
||||||
info->old_path);
|
info->old_path);
|
||||||
html("</td><td class='right'>");
|
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);
|
htmlf("%d", info->added + info->removed);
|
||||||
html("</td><td class='graph'>");
|
html("</td><td class='graph'>");
|
||||||
htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
|
htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
|
||||||
@ -110,10 +118,14 @@ static void count_diff_lines(char *line, int len)
|
|||||||
|
|
||||||
static void inspect_filepair(struct diff_filepair *pair)
|
static void inspect_filepair(struct diff_filepair *pair)
|
||||||
{
|
{
|
||||||
|
int binary = 0;
|
||||||
|
unsigned long old_size = 0;
|
||||||
|
unsigned long new_size = 0;
|
||||||
files++;
|
files++;
|
||||||
lines_added = 0;
|
lines_added = 0;
|
||||||
lines_removed = 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 (files >= slots) {
|
||||||
if (slots == 0)
|
if (slots == 0)
|
||||||
slots = 4;
|
slots = 4;
|
||||||
@ -130,6 +142,9 @@ static void inspect_filepair(struct diff_filepair *pair)
|
|||||||
items[files-1].new_path = xstrdup(pair->two->path);
|
items[files-1].new_path = xstrdup(pair->two->path);
|
||||||
items[files-1].added = lines_added;
|
items[files-1].added = lines_added;
|
||||||
items[files-1].removed = lines_removed;
|
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)
|
if (lines_added + lines_removed > max_changes)
|
||||||
max_changes = lines_added + lines_removed;
|
max_changes = lines_added + lines_removed;
|
||||||
total_adds += lines_added;
|
total_adds += lines_added;
|
||||||
@ -233,6 +248,10 @@ static void header(unsigned char *sha1, char *path1, int mode1,
|
|||||||
|
|
||||||
static void filepair_cb(struct diff_filepair *pair)
|
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,
|
header(pair->one->sha1, pair->one->path, pair->one->mode,
|
||||||
pair->two->sha1, pair->two->path, pair->two->mode);
|
pair->two->sha1, pair->two->path, pair->two->mode);
|
||||||
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
|
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
|
||||||
@ -242,8 +261,11 @@ static void filepair_cb(struct diff_filepair *pair)
|
|||||||
print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
|
print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
|
||||||
return;
|
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");
|
cgit_print_error("Error running diff");
|
||||||
|
if (binary)
|
||||||
|
html("Binary files differ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
|
void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
|
||||||
|
7
ui-log.c
7
ui-log.c
@ -26,9 +26,14 @@ void count_lines(char *line, int size)
|
|||||||
|
|
||||||
void inspect_files(struct diff_filepair *pair)
|
void inspect_files(struct diff_filepair *pair)
|
||||||
{
|
{
|
||||||
|
unsigned long old_size = 0;
|
||||||
|
unsigned long new_size = 0;
|
||||||
|
int binary = 0;
|
||||||
|
|
||||||
files++;
|
files++;
|
||||||
if (ctx.repo->enable_log_linecount)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_commit_decorations(struct commit *commit)
|
void show_commit_decorations(struct commit *commit)
|
||||||
|
@ -57,6 +57,10 @@ static void header(unsigned char *sha1, char *path1, int mode1,
|
|||||||
|
|
||||||
static void filepair_cb(struct diff_filepair *pair)
|
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,
|
header(pair->one->sha1, pair->one->path, pair->one->mode,
|
||||||
pair->two->sha1, pair->two->path, pair->two->mode);
|
pair->two->sha1, pair->two->path, pair->two->mode);
|
||||||
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
|
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
|
||||||
@ -66,8 +70,11 @@ static void filepair_cb(struct diff_filepair *pair)
|
|||||||
print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
|
print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
|
||||||
return;
|
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");
|
html("Error running diff");
|
||||||
|
if (binary)
|
||||||
|
html("Binary files differ\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgit_print_patch(char *hex)
|
void cgit_print_patch(char *hex)
|
||||||
|
71
ui-tree.c
71
ui-tree.c
@ -6,6 +6,7 @@
|
|||||||
* (see COPYING for full license text)
|
* (see COPYING for full license text)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include "cgit.h"
|
#include "cgit.h"
|
||||||
#include "html.h"
|
#include "html.h"
|
||||||
#include "ui-shared.h"
|
#include "ui-shared.h"
|
||||||
@ -14,12 +15,53 @@ char *curr_rev;
|
|||||||
char *match_path;
|
char *match_path;
|
||||||
int header = 0;
|
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)
|
static void print_object(const unsigned char *sha1, char *path)
|
||||||
{
|
{
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
char *buf;
|
char *buf;
|
||||||
unsigned long size, lineno, idx;
|
unsigned long size;
|
||||||
const char *numberfmt = "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
|
|
||||||
|
|
||||||
type = sha1_object_info(sha1, &size);
|
type = sha1_object_info(sha1, &size);
|
||||||
if (type == OBJ_BAD) {
|
if (type == OBJ_BAD) {
|
||||||
@ -40,27 +82,10 @@ static void print_object(const unsigned char *sha1, char *path)
|
|||||||
curr_rev, path);
|
curr_rev, path);
|
||||||
htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
|
htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
|
||||||
|
|
||||||
html("<table summary='blob content' class='blob'>\n");
|
if (buffer_is_binary(buf, size))
|
||||||
html("<tr>\n");
|
print_binary_buffer(buf, size);
|
||||||
|
else
|
||||||
html("<td class='linenumbers'><pre>");
|
print_text_buffer(buf, size);
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Laddar…
Referens i nytt ärende
Block a user