Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1015: Webrev can't handle changes with binary files #16

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -227,10 +227,14 @@
body().removeEventListener("keydown", framesOnKeyDown);
body().style.margin = 0;
if (state.view !== "index") {
if (state.head.content[state.index] === null || state.base.content[state.index] === null) {
const content = fetchFileContent(state);
state.head.content[state.index] = content.head;
state.base.content[state.index] = content.base;
if (!state.comparison.files[state.index].binary) {
if (state.head.content[state.index] === null || state.base.content[state.index] === null) {
const content = fetchFileContent(state);
if (content != null) {
state.head.content[state.index] = content.head;
state.base.content[state.index] = content.base;
}
}
}
}
if (state.view === "index") {
@@ -402,40 +406,50 @@
const p = create("p");
const code = create("code");
if (file.status === "modified" || file.status === "copied" || file.status === "renamed") {
const cdiff = create("a");
cdiff.href = "#cdiff-" + i + "-" + filename;
cdiff.innerHTML = "Cdiffs";
code.append(cdiff, " ");

const udiff = create("a");
udiff.href = "#udiff-" + i + "-" + filename;
udiff.innerHTML = "Udiffs";
code.append(udiff, " ");

const sdiff = create("a");
sdiff.href = "#sdiff-" + i + "-" + filename;
sdiff.innerHTML = "Sdiffs";
code.append(sdiff, " ");

const frames = create("a");
frames.href = "#frames-" + i + "-" + filename;
frames.innerHTML = "Frames";
code.append(frames, " ");

const oldFile = create("a");
oldFile.href = "#old-" + i + "-" + filename;
oldFile.innerHTML = "Old";
code.append(oldFile, " ");

const newFile = create("a");
newFile.href = "#new-" + i + "-" + filename;
newFile.innerHTML = "New";
code.append(newFile, " ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");
if (file.binary) {
code.append("------ ");
code.append("------ ");
code.append("------ ");
code.append("------ ");
code.append("--- ");
code.append("--- ");
code.append("----- ");
} else {
const cdiff = create("a");
cdiff.href = "#cdiff-" + i + "-" + filename;
cdiff.innerHTML = "Cdiffs";
code.append(cdiff, " ");

const udiff = create("a");
udiff.href = "#udiff-" + i + "-" + filename;
udiff.innerHTML = "Udiffs";
code.append(udiff, " ");

const sdiff = create("a");
sdiff.href = "#sdiff-" + i + "-" + filename;
sdiff.innerHTML = "Sdiffs";
code.append(sdiff, " ");

const frames = create("a");
frames.href = "#frames-" + i + "-" + filename;
frames.innerHTML = "Frames";
code.append(frames, " ");

const oldFile = create("a");
oldFile.href = "#old-" + i + "-" + filename;
oldFile.innerHTML = "Old";
code.append(oldFile, " ");

const newFile = create("a");
newFile.href = "#new-" + i + "-" + filename;
newFile.innerHTML = "New";
code.append(newFile, " ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");
}

const rawFile = create("a");
rawFile.href = "https://raw.githubusercontent.com/" + metadata.head.repo.full_name + "/" + metadata.head.sha + "/" + file.filename;
@@ -461,15 +475,20 @@
code.append("------ ");
code.append("--- ");

const newFile = create("a");
newFile.href = "#new-" + i + "-" + filename;
newFile.innerHTML = "New";
code.append(newFile, " ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");
if (file.binary) {
code.append("--- ");
code.append("----- ");
} else {
const newFile = create("a");
newFile.href = "#new-" + i + "-" + filename;
newFile.innerHTML = "New";
code.append(newFile, " ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");
}

const rawFile = create("a");
rawFile.href = "https://raw.githubusercontent.com/" + metadata.head.repo.full_name + "/" + metadata.head.sha + "/" + file.filename;
@@ -489,19 +508,26 @@
code.append("------ ");
code.append("------ ");

const oldFile = create("a");
oldFile.href = "#old-" + i + "-" + filename;
oldFile.innerHTML = "Old";
code.append(oldFile, " ");

code.append("--- ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");

code.append("--- ");
if (file.binary) {
code.append("--- ");
code.append("--- ");
code.append("----- ");
code.append("--- ");
} else {
const oldFile = create("a");
oldFile.href = "#old-" + i + "-" + filename;
oldFile.innerHTML = "Old";
code.append(oldFile, " ");

code.append("--- ");

const patchFile = create("a");
patchFile.href = "#patch-" + i + "-" + filename;
patchFile.innerHTML = "Patch";
code.append(patchFile, " ");

code.append("--- ");
}

p.append(code);

@@ -1477,6 +1503,10 @@

function removeContext(patch) {
const hunks = new Array();
if (patch === null) {
return hunks
}

let srcStart = 0;
let srcLines = new Array();
let dstStart = 0;
@@ -1677,10 +1707,14 @@

// Pre-fetch base and head content for up to 25 files
for (let i = 0; i < Math.min(files.length, 25); i++) {
state.index = i;
const content = fetchFileContent(state);
state.head.content[i] = content.head;
state.base.content[i] = content.base;
if (!state.comparison.files[i].binary) {
state.index = i;
const content = fetchFileContent(state);
if (content != null) {
state.head.content[i] = content.head;
state.base.content[i] = content.base;
}
}
}
state.index = -1;
}