Merge branch 'stable-2.8'
* stable-2.8: Allow large patches to function reasonably in diffs
This commit is contained in:
@@ -50,6 +50,7 @@ import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
|||||||
public abstract class PatchScreen extends Screen implements
|
public abstract class PatchScreen extends Screen implements
|
||||||
CommentEditorContainer {
|
CommentEditorContainer {
|
||||||
static final PrettyFactory PRETTY = ClientSideFormatter.FACTORY;
|
static final PrettyFactory PRETTY = ClientSideFormatter.FACTORY;
|
||||||
|
static final short LARGE_FILE_CONTEXT = 100;
|
||||||
|
|
||||||
public static class SideBySide extends PatchScreen {
|
public static class SideBySide extends PatchScreen {
|
||||||
public SideBySide(final Patch.Key id, final int patchIndex,
|
public SideBySide(final Patch.Key id, final int patchIndex,
|
||||||
@@ -460,6 +461,19 @@ public abstract class PatchScreen extends Screen implements
|
|||||||
setToken(Dispatcher.toPatchUnified(idSideA, patchKey));
|
setToken(Dispatcher.toPatchUnified(idSideA, patchKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (script.isHugeFile()) {
|
||||||
|
AccountDiffPreference dp = script.getDiffPrefs();
|
||||||
|
int context = dp.getContext();
|
||||||
|
if (context == AccountDiffPreference.WHOLE_FILE_CONTEXT) {
|
||||||
|
context = Short.MAX_VALUE;
|
||||||
|
} else if (context > Short.MAX_VALUE) {
|
||||||
|
context = Short.MAX_VALUE;
|
||||||
|
}
|
||||||
|
dp.setContext((short) Math.min(context, LARGE_FILE_CONTEXT));
|
||||||
|
dp.setSyntaxHighlighting(false);
|
||||||
|
script.setDiffPrefs(dp);
|
||||||
|
}
|
||||||
|
|
||||||
contentTable.display(patchKey, idSideA, idSideB, script, patchSetDetail);
|
contentTable.display(patchKey, idSideA, idSideB, script, patchSetDetail);
|
||||||
contentTable.display(script.getCommentDetail(), script.isExpandAllComments());
|
contentTable.display(script.getCommentDetail(), script.isExpandAllComments());
|
||||||
contentTable.finishDisplay();
|
contentTable.finishDisplay();
|
||||||
|
@@ -23,6 +23,9 @@ import com.google.gerrit.client.ui.NpIntTextBox;
|
|||||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.dom.client.NodeList;
|
||||||
|
import com.google.gwt.dom.client.OptionElement;
|
||||||
|
import com.google.gwt.dom.client.SelectElement;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||||
@@ -157,6 +160,21 @@ public class PatchScriptSettingsPanel extends Composite {
|
|||||||
} else {
|
} else {
|
||||||
syntaxHighlighting.setValue(false);
|
syntaxHighlighting.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeList<OptionElement> options =
|
||||||
|
context.getElement().<SelectElement>cast().getOptions();
|
||||||
|
// WHOLE_FILE_CONTEXT is the last option in the list.
|
||||||
|
int lastIndex = options.getLength() - 1;
|
||||||
|
OptionElement currOption = options.getItem(lastIndex);
|
||||||
|
if (enableSmallFileFeatures) {
|
||||||
|
currOption.setDisabled(false);
|
||||||
|
} else {
|
||||||
|
currOption.setDisabled(true);
|
||||||
|
if (context.getSelectedIndex() == lastIndex) {
|
||||||
|
// Select the next longest context from WHOLE_FILE_CONTEXT
|
||||||
|
context.setSelectedIndex(lastIndex - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
toggleEnabledStatus(save.isEnabled());
|
toggleEnabledStatus(save.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,6 +52,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
|
|
||||||
private SparseHtmlFile a;
|
private SparseHtmlFile a;
|
||||||
private SparseHtmlFile b;
|
private SparseHtmlFile b;
|
||||||
|
private boolean isHugeFile;
|
||||||
protected boolean isFileCommentBorderRowExist;
|
protected boolean isFileCommentBorderRowExist;
|
||||||
|
|
||||||
protected void createFileCommentEditorOnSideA() {
|
protected void createFileCommentEditorOnSideA() {
|
||||||
@@ -94,6 +95,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
protected void render(final PatchScript script, final PatchSetDetail detail) {
|
protected void render(final PatchScript script, final PatchSetDetail detail) {
|
||||||
final ArrayList<Object> lines = new ArrayList<Object>();
|
final ArrayList<Object> lines = new ArrayList<Object>();
|
||||||
final SafeHtmlBuilder nc = new SafeHtmlBuilder();
|
final SafeHtmlBuilder nc = new SafeHtmlBuilder();
|
||||||
|
isHugeFile = script.isHugeFile();
|
||||||
allocateTableHeader(script, nc);
|
allocateTableHeader(script, nc);
|
||||||
lines.add(null);
|
lines.add(null);
|
||||||
if (!isDisplayBinary) {
|
if (!isDisplayBinary) {
|
||||||
@@ -209,7 +211,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
for (int row = 0; row < lines.size(); row++) {
|
for (int row = 0; row < lines.size(); row++) {
|
||||||
setRowItem(row, lines.get(row));
|
setRowItem(row, lines.get(row));
|
||||||
if (lines.get(row) instanceof SkippedLine) {
|
if (lines.get(row) instanceof SkippedLine) {
|
||||||
createSkipLine(row, (SkippedLine) lines.get(row), script.getA().isWholeFile());
|
createSkipLine(row, (SkippedLine) lines.get(row), isHugeFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -540,18 +542,16 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
|
|
||||||
if (numRows > 0) {
|
if (numRows > 0) {
|
||||||
line.incrementStart(numRows);
|
line.incrementStart(numRows);
|
||||||
// If we got here, we must have the whole file anyway.
|
createSkipLine(row + loopTo, line, isHugeFile);
|
||||||
createSkipLine(row + loopTo, line, true);
|
|
||||||
} else if (numRows < 0) {
|
} else if (numRows < 0) {
|
||||||
line.reduceSize(-numRows);
|
line.reduceSize(-numRows);
|
||||||
// If we got here, we must have the whole file anyway.
|
createSkipLine(row, line, isHugeFile);
|
||||||
createSkipLine(row, line, true);
|
|
||||||
} else {
|
} else {
|
||||||
table.removeRow(row + loopTo);
|
table.removeRow(row + loopTo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSkipLine(int row, SkippedLine line, boolean isWholeFile) {
|
private void createSkipLine(int row, SkippedLine line, boolean isHugeFile) {
|
||||||
FlowPanel p = new FlowPanel();
|
FlowPanel p = new FlowPanel();
|
||||||
InlineLabel l1 = new InlineLabel(" " + PatchUtil.C.patchSkipRegionStart() + " ");
|
InlineLabel l1 = new InlineLabel(" " + PatchUtil.C.patchSkipRegionStart() + " ");
|
||||||
InlineLabel l2 = new InlineLabel(" " + PatchUtil.C.patchSkipRegionEnd() + " ");
|
InlineLabel l2 = new InlineLabel(" " + PatchUtil.C.patchSkipRegionEnd() + " ");
|
||||||
@@ -560,7 +560,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
all.addClickHandler(expandAllListener);
|
all.addClickHandler(expandAllListener);
|
||||||
all.setStyleName(Gerrit.RESOURCES.css().skipLine());
|
all.setStyleName(Gerrit.RESOURCES.css().skipLine());
|
||||||
|
|
||||||
if (line.getSize() > 30 && isWholeFile) {
|
if (line.getSize() > 30) {
|
||||||
// Only show the expand before/after if skipped more than 30 lines.
|
// Only show the expand before/after if skipped more than 30 lines.
|
||||||
Anchor b = new Anchor(PatchUtil.M.expandBefore(NUM_ROWS_TO_EXPAND), true);
|
Anchor b = new Anchor(PatchUtil.M.expandBefore(NUM_ROWS_TO_EXPAND), true);
|
||||||
Anchor a = new Anchor(PatchUtil.M.expandAfter(NUM_ROWS_TO_EXPAND), true);
|
Anchor a = new Anchor(PatchUtil.M.expandAfter(NUM_ROWS_TO_EXPAND), true);
|
||||||
@@ -573,16 +573,16 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
|||||||
|
|
||||||
p.add(b);
|
p.add(b);
|
||||||
p.add(l1);
|
p.add(l1);
|
||||||
|
if (isHugeFile) {
|
||||||
|
p.add(new InlineLabel(" " + line.getSize() + " "));
|
||||||
|
} else {
|
||||||
p.add(all);
|
p.add(all);
|
||||||
|
}
|
||||||
p.add(l2);
|
p.add(l2);
|
||||||
p.add(a);
|
p.add(a);
|
||||||
} else if (isWholeFile) {
|
|
||||||
p.add(l1);
|
|
||||||
p.add(all);
|
|
||||||
p.add(l2);
|
|
||||||
} else {
|
} else {
|
||||||
p.add(l1);
|
p.add(l1);
|
||||||
p.add(new InlineLabel(" " + line.getSize() + " "));
|
p.add(all);
|
||||||
p.add(l2);
|
p.add(l2);
|
||||||
}
|
}
|
||||||
table.setWidget(row, 1, p);
|
table.setWidget(row, 1, p);
|
||||||
|
@@ -193,18 +193,16 @@ class PatchScriptBuilder {
|
|||||||
// IF the file is really large, we disable things to avoid choking
|
// IF the file is really large, we disable things to avoid choking
|
||||||
// the browser client.
|
// the browser client.
|
||||||
//
|
//
|
||||||
diffPrefs.setContext((short) Math.min(25, context));
|
|
||||||
diffPrefs.setSyntaxHighlighting(false);
|
|
||||||
context = diffPrefs.getContext();
|
|
||||||
hugeFile = true;
|
hugeFile = true;
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// In order to expand the skipped common lines or syntax highlight the
|
// In order to expand the skipped common lines or syntax highlight the
|
||||||
// file properly we need to give the client the complete file contents.
|
// file properly we need to give the client the complete file contents.
|
||||||
// So force our context temporarily to the complete file size.
|
// So force our context temporarily to the complete file size.
|
||||||
//
|
//
|
||||||
context = MAX_CONTEXT;
|
context = MAX_CONTEXT;
|
||||||
}
|
|
||||||
packContent(diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE);
|
packContent(diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user