diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java index d7cedbe47c..8f9f1f52bc 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java @@ -14,6 +14,8 @@ package com.google.gerrit.common.data; +import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT; + import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.common.EditList; @@ -28,7 +30,6 @@ import com.google.gerrit.reviewdb.Patch.ChangeType; import org.eclipse.jgit.diff.Edit; import java.util.List; -import static com.google.gerrit.reviewdb.AccountGeneralPreferences.*; public class PatchScript { public static enum DisplayMethod { @@ -48,12 +49,13 @@ public class PatchScript { protected DisplayMethod displayMethodB; protected CommentDetail comments; protected List history; + protected boolean hugeFile; public PatchScript(final Change.Key ck, final ChangeType ct, final String on, final String nn, final List h, final PatchScriptSettings s, final SparseFileContent ca, final SparseFileContent cb, final List e, final DisplayMethod ma, final DisplayMethod mb, - final CommentDetail cd, final List hist) { + final CommentDetail cd, final List hist, final boolean hf) { changeId = ck; changeType = ct; oldName = on; @@ -67,6 +69,7 @@ public class PatchScript { displayMethodB = mb; comments = cd; history = hist; + hugeFile = hf; } protected PatchScript() { @@ -116,6 +119,10 @@ public class PatchScript { settings = s; } + public boolean isHugeFile() { + return hugeFile; + } + public boolean isIgnoreWhitespace() { return settings.getWhitespace() != Whitespace.IGNORE_NONE; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java index d05f2eb48e..3b7c445373 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.java @@ -31,6 +31,7 @@ public interface PatchConstants extends Constants { String patchHeaderNew(); String patchHistoryTitle(); + String disabledOnLargeFiles(); String upToChange(); String linePrev(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties index 7dddd16c54..9826aba61f 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchConstants.properties @@ -13,6 +13,7 @@ noDifference = No Differences patchHeaderOld = Old Version patchHeaderNew = New Version patchHistoryTitle = Patch History +disabledOnLargeFiles = Disabled on very large source files. upToChange = Up to change linePrev = Previous line diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java index 2887726966..4d70acc63f 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java @@ -447,6 +447,7 @@ public abstract class PatchScreen extends Screen implements contentTable.finishDisplay(); } showPatch(hasDifferences); + settingsPanel.setEnableSmallFileFeatures(!script.isHugeFile()); settingsPanel.setEnabled(true); lastScript = script; diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java index 471215b225..1f5815a0cd 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScriptSettingsPanel.java @@ -54,6 +54,7 @@ public class PatchScriptSettingsPanel extends Composite implements } private PatchScriptSettings value; + private boolean enableSmallFileFeatures = true; @UiField ListBox ignoreWhitespace; @@ -126,10 +127,33 @@ public class PatchScriptSettingsPanel extends Composite implements ((FocusWidget) w).setEnabled(on); } } + toggleEnabledStatus(on); } - public CheckBox getSyntaxHighlightingCheckBox() { - return syntaxHighlighting; + public void setEnableSmallFileFeatures(final boolean on) { + enableSmallFileFeatures = on; + if (enableSmallFileFeatures) { + final PrettySettings p = getValue().getPrettySettings(); + + syntaxHighlighting.setValue(p.isSyntaxHighlighting()); + showFullFile.setValue(getValue().getContext() == WHOLE_FILE_CONTEXT); + } else { + syntaxHighlighting.setValue(false); + showFullFile.setValue(false); + } + toggleEnabledStatus(update.isEnabled()); + } + + private void toggleEnabledStatus(boolean on) { + on &= enableSmallFileFeatures; + + syntaxHighlighting.setEnabled(on); + showFullFile.setEnabled(on); + + final String title = + enableSmallFileFeatures ? null : PatchUtil.C.disabledOnLargeFiles(); + syntaxHighlighting.setTitle(title); + showFullFile.setTitle(title); } public CheckBox getReviewedCheckBox() { @@ -144,11 +168,16 @@ public class PatchScriptSettingsPanel extends Composite implements final PrettySettings p = s.getPrettySettings(); setIgnoreWhitespace(s.getWhitespace()); - showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT); + if (enableSmallFileFeatures) { + showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT); + syntaxHighlighting.setValue(p.isSyntaxHighlighting()); + } else { + showFullFile.setValue(false); + syntaxHighlighting.setValue(false); + } tabWidth.setIntValue(p.getTabSize()); colWidth.setIntValue(p.getLineLength()); - syntaxHighlighting.setValue(p.isSyntaxHighlighting()); intralineDifference.setValue(p.isIntralineDifference()); whitespaceErrors.setValue(p.isShowWhiteSpaceErrors()); showTabs.setValue(p.isShowTabs()); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java index fd83b78195..d4cb8ab131 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java @@ -118,7 +118,7 @@ class PatchScriptBuilder { return new PatchScript(change.getKey(), content.getChangeType(), content .getOldName(), content.getNewName(), content.getHeaderLines(), settings, a.dst, b.dst, Collections. emptyList(), - a.displayMethod, b.displayMethod, comments, history); + a.displayMethod, b.displayMethod, comments, history, false); } a.path = oldName(content); @@ -130,6 +130,7 @@ class PatchScriptBuilder { edits = new ArrayList(content.getEdits()); ensureCommentsVisible(comments); + boolean hugeFile = false; if (a.mode == FileMode.GITLINK || b.mode == FileMode.GITLINK) { } else if (a.src == b.src && a.size() <= context @@ -152,6 +153,7 @@ class PatchScriptBuilder { settings.setContext(Math.min(25, context)); settings.getPrettySettings().setSyntaxHighlighting(false); context = settings.getContext(); + hugeFile = true; } else if (settings.getPrettySettings().isSyntaxHighlighting()) { // In order to syntax highlight the file properly we need to @@ -166,7 +168,7 @@ class PatchScriptBuilder { return new PatchScript(change.getKey(), content.getChangeType(), content .getOldName(), content.getNewName(), content.getHeaderLines(), settings, a.dst, b.dst, edits, a.displayMethod, b.displayMethod, - comments, history); + comments, history, hugeFile); } private static String oldName(final PatchListEntry entry) {