Skip to content
Permalink
Browse files
1015: Webrev can't handle changes with binary files
Reviewed-by: ehelin
  • Loading branch information
erikj79 committed May 17, 2021
1 parent 6182f80 commit 8f3aff2ba4c6b9288f2d487da55e37e869404287
Showing with 98 additions and 64 deletions.
  1. +98 −64 index.html
@@ -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;
}

0 comments on commit 8f3aff2

Please sign in to comment.