Merge changes from topic 'codemirror-customization'
* changes: SideBySide: Allow to activate match brackets Codemirror addon SideBySide: Make cursor blink rate customizable Replace ACCOUNT_DIFF_PREFERENCES table with Git backend (part2)
This commit is contained in:
@@ -1259,6 +1259,7 @@ link:#diff-preferences-info[DiffPreferencesInfo] entity.
|
||||
"ignore_whitespace": "IGNORE_ALL",
|
||||
"intraline_difference": true,
|
||||
"line_length": 100,
|
||||
"cursor_blink_rate": 500,
|
||||
"show_tabs": true,
|
||||
"show_whitespace_errors": true,
|
||||
"syntax_highlighting": true,
|
||||
@@ -1288,6 +1289,7 @@ link:#diff-preferences-input[DiffPreferencesInput] entity.
|
||||
"ignore_whitespace": "IGNORE_ALL",
|
||||
"intraline_difference": true,
|
||||
"line_length": 100,
|
||||
"cursor_blink_rate": 500,
|
||||
"show_line_endings": true,
|
||||
"show_tabs": true,
|
||||
"show_whitespace_errors": true,
|
||||
@@ -1672,6 +1674,9 @@ Allowed values are `IGNORE_NONE`, `IGNORE_TRAILING`,
|
||||
Whether intraline differences should be highlighted.
|
||||
|`line_length` ||
|
||||
Number of characters that should be displayed in one line.
|
||||
|`cursor_blink_rate` ||
|
||||
Half-period in milliseconds used for cursor blinking.
|
||||
Setting it to 0 disables cursor blinking.
|
||||
|`manual_review` |not set if `false`|
|
||||
Whether the 'Reviewed' flag should not be set automatically on a patch
|
||||
when it is viewed.
|
||||
@@ -1704,6 +1709,8 @@ Number of spaces that should be used to display one tab.
|
||||
|'hide_empty_pane' |not set if `false`|
|
||||
Whether empty panes should be hidden. The left pane is empty when a
|
||||
file was added; the right pane is empty when a file was deleted.
|
||||
|`match_brackets` |not set if `false`|
|
||||
Whether matching brackets should be highlighted.
|
||||
|===========================================
|
||||
|
||||
[[diff-preferences-input]]
|
||||
|
||||
@@ -22,20 +22,11 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
@ConfigSuite.Config
|
||||
public static Config readFromGitConfig() {
|
||||
Config cfg = new Config();
|
||||
cfg.setBoolean("user", null, "readPrefsFromGit", true);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDiffPreferencesOfNonExistingAccount_NotFound()
|
||||
throws Exception {
|
||||
@@ -56,6 +47,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(o.context).isEqualTo(d.context);
|
||||
assertThat(o.tabSize).isEqualTo(d.tabSize);
|
||||
assertThat(o.lineLength).isEqualTo(d.lineLength);
|
||||
assertThat(o.cursorBlinkRate).isEqualTo(d.cursorBlinkRate);
|
||||
assertThat(o.expandAllComments).isNull();
|
||||
assertThat(o.intralineDifference).isEqualTo(d.intralineDifference);
|
||||
assertThat(o.manualReview).isNull();
|
||||
@@ -71,6 +63,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(o.hideLineNumbers).isNull();
|
||||
assertThat(o.renderEntireFile).isNull();
|
||||
assertThat(o.hideEmptyPane).isNull();
|
||||
assertThat(o.matchBrackets).isNull();
|
||||
assertThat(o.ignoreWhitespace).isEqualTo(d.ignoreWhitespace);
|
||||
assertThat(o.theme).isEqualTo(d.theme);
|
||||
}
|
||||
@@ -83,6 +76,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
i.context *= -1;
|
||||
i.tabSize *= -1;
|
||||
i.lineLength *= -1;
|
||||
i.cursorBlinkRate = 500;
|
||||
i.theme = Theme.MIDNIGHT;
|
||||
i.ignoreWhitespace = Whitespace.IGNORE_ALL;
|
||||
i.expandAllComments ^= true;
|
||||
@@ -100,6 +94,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
i.hideLineNumbers ^= true;
|
||||
i.renderEntireFile ^= true;
|
||||
i.hideEmptyPane ^= true;
|
||||
i.matchBrackets ^= true;
|
||||
|
||||
RestResponse r = adminSession.put("/accounts/" + admin.email
|
||||
+ "/preferences.diff", i);
|
||||
@@ -110,6 +105,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(o.context).isEqualTo(i.context);
|
||||
assertThat(o.tabSize).isEqualTo(i.tabSize);
|
||||
assertThat(o.lineLength).isEqualTo(i.lineLength);
|
||||
assertThat(o.cursorBlinkRate).isEqualTo(i.cursorBlinkRate);
|
||||
assertThat(o.expandAllComments).isEqualTo(i.expandAllComments);
|
||||
assertThat(o.intralineDifference).isNull();
|
||||
assertThat(o.manualReview).isEqualTo(i.manualReview);
|
||||
@@ -125,6 +121,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(o.hideLineNumbers).isEqualTo(i.hideLineNumbers);
|
||||
assertThat(o.renderEntireFile).isEqualTo(i.renderEntireFile);
|
||||
assertThat(o.hideEmptyPane).isEqualTo(i.hideEmptyPane);
|
||||
assertThat(o.matchBrackets).isEqualTo(i.matchBrackets);
|
||||
assertThat(o.ignoreWhitespace).isEqualTo(i.ignoreWhitespace);
|
||||
assertThat(o.theme).isEqualTo(i.theme);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class DiffPreferencesInfo {
|
||||
public Integer context;
|
||||
public Integer tabSize;
|
||||
public Integer lineLength;
|
||||
public Integer cursorBlinkRate;
|
||||
public Boolean expandAllComments;
|
||||
public Boolean intralineDifference;
|
||||
public Boolean manualReview;
|
||||
@@ -54,6 +55,7 @@ public class DiffPreferencesInfo {
|
||||
public Boolean hideLineNumbers;
|
||||
public Boolean renderEntireFile;
|
||||
public Boolean hideEmptyPane;
|
||||
public Boolean matchBrackets;
|
||||
public Theme theme;
|
||||
public Whitespace ignoreWhitespace;
|
||||
public Boolean retainHeader;
|
||||
@@ -65,6 +67,7 @@ public class DiffPreferencesInfo {
|
||||
i.context = DEFAULT_CONTEXT;
|
||||
i.tabSize = DEFAULT_TAB_SIZE;
|
||||
i.lineLength = DEFAULT_LINE_LENGTH;
|
||||
i.cursorBlinkRate = 0;
|
||||
i.ignoreWhitespace = Whitespace.IGNORE_NONE;
|
||||
i.theme = Theme.DEFAULT;
|
||||
i.expandAllComments = false;
|
||||
@@ -82,6 +85,7 @@ public class DiffPreferencesInfo {
|
||||
i.hideLineNumbers = false;
|
||||
i.renderEntireFile = false;
|
||||
i.hideEmptyPane = false;
|
||||
i.matchBrackets = false;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
p.ignoreWhitespace(in.ignoreWhitespace);
|
||||
p.tabSize(in.tabSize);
|
||||
p.lineLength(in.lineLength);
|
||||
p.cursorBlinkRate(in.cursorBlinkRate);
|
||||
p.context(in.context);
|
||||
p.intralineDifference(in.intralineDifference);
|
||||
p.showLineEndings(in.showLineEndings);
|
||||
@@ -45,6 +46,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
p.retainHeader(in.retainHeader);
|
||||
p.skipUncommented(in.skipUncommented);
|
||||
p.skipDeleted(in.skipDeleted);
|
||||
p.matchBrackets(in.matchBrackets);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
p.context = context();
|
||||
p.tabSize = tabSize();
|
||||
p.lineLength = lineLength();
|
||||
p.cursorBlinkRate = cursorBlinkRate();
|
||||
p.expandAllComments = expandAllComments();
|
||||
p.intralineDifference = intralineDifference();
|
||||
p.manualReview = manualReview();
|
||||
@@ -67,6 +70,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
p.hideLineNumbers = hideLineNumbers();
|
||||
p.renderEntireFile = renderEntireFile();
|
||||
p.hideEmptyPane = hideEmptyPane();
|
||||
p.matchBrackets = matchBrackets();
|
||||
p.theme = theme();
|
||||
p.ignoreWhitespace = ignoreWhitespace();
|
||||
}
|
||||
@@ -105,6 +109,10 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
return get("line_length", 100);
|
||||
}
|
||||
|
||||
public final int cursorBlinkRate() {
|
||||
return get("cursor_blink_rate", 0);
|
||||
}
|
||||
|
||||
public final boolean showLineNumbers() {
|
||||
return !hideLineNumbers();
|
||||
}
|
||||
@@ -116,6 +124,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
public final native void tabSize(int t) /*-{ this.tab_size = t }-*/;
|
||||
public final native void lineLength(int c) /*-{ this.line_length = c }-*/;
|
||||
public final native void context(int c) /*-{ this.context = c }-*/;
|
||||
public final native void cursorBlinkRate(int r) /*-{ this.cursor_blink_rate = r }-*/;
|
||||
public final native void intralineDifference(boolean i) /*-{ this.intraline_difference = i }-*/;
|
||||
public final native void showLineEndings(boolean s) /*-{ this.show_line_endings = s }-*/;
|
||||
public final native void showTabs(boolean s) /*-{ this.show_tabs = s }-*/;
|
||||
@@ -127,10 +136,11 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
public final native void expandAllComments(boolean e) /*-{ this.expand_all_comments = e }-*/;
|
||||
public final native void manualReview(boolean r) /*-{ this.manual_review = r }-*/;
|
||||
public final native void renderEntireFile(boolean r) /*-{ this.render_entire_file = r }-*/;
|
||||
public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/;
|
||||
public final native void retainHeader(boolean r) /*-{ this.retain_header = r }-*/;
|
||||
public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/;
|
||||
public final native void skipUncommented(boolean s) /*-{ this.skip_uncommented = s }-*/;
|
||||
public final native void skipDeleted(boolean s) /*-{ this.skip_deleted = s }-*/;
|
||||
public final native void matchBrackets(boolean m) /*-{ this.match_brackets = m }-*/;
|
||||
public final native boolean intralineDifference() /*-{ return this.intraline_difference || false }-*/;
|
||||
public final native boolean showLineEndings() /*-{ return this.show_line_endings || false }-*/;
|
||||
public final native boolean showTabs() /*-{ return this.show_tabs || false }-*/;
|
||||
@@ -146,6 +156,7 @@ public class DiffPreferences extends JavaScriptObject {
|
||||
public final native boolean retainHeader() /*-{ return this.retain_header || false }-*/;
|
||||
public final native boolean skipUncommented() /*-{ return this.skip_uncommented || false }-*/;
|
||||
public final native boolean skipDeleted() /*-{ return this.skip_deleted || false }-*/;
|
||||
public final native boolean matchBrackets() /*-{ return this.match_brackets || false }-*/;
|
||||
|
||||
private final native void setThemeRaw(String i) /*-{ this.theme = i }-*/;
|
||||
private final native void setIgnoreWhitespaceRaw(String i) /*-{ this.ignore_whitespace = i }-*/;
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
|
||||
package com.google.gerrit.client.diff;
|
||||
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.DEFAULT_CONTEXT;
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.WHOLE_FILE_CONTEXT;
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace.IGNORE_ALL;
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace.IGNORE_LEADING_AND_TRAILING;
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace.IGNORE_NONE;
|
||||
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace.IGNORE_TRAILING;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.DEFAULT_CONTEXT;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.WHOLE_FILE_CONTEXT;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace.IGNORE_ALL;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace.IGNORE_LEADING_AND_TRAILING;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace.IGNORE_NONE;
|
||||
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace.IGNORE_TRAILING;
|
||||
|
||||
import static com.google.gwt.event.dom.client.KeyCodes.KEY_ESCAPE;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
@@ -85,6 +86,7 @@ public class PreferencesBox extends Composite {
|
||||
@UiField NpIntTextBox tabWidth;
|
||||
@UiField NpIntTextBox lineLength;
|
||||
@UiField NpIntTextBox context;
|
||||
@UiField NpIntTextBox cursorBlinkRate;
|
||||
@UiField CheckBox contextEntireFile;
|
||||
@UiField ToggleButton intralineDifference;
|
||||
@UiField ToggleButton syntaxHighlighting;
|
||||
@@ -99,6 +101,7 @@ public class PreferencesBox extends Composite {
|
||||
@UiField ToggleButton manualReview;
|
||||
@UiField ToggleButton expandAllComments;
|
||||
@UiField ToggleButton renderEntireFile;
|
||||
@UiField ToggleButton matchBrackets;
|
||||
@UiField ListBox theme;
|
||||
@UiField Element modeLabel;
|
||||
@UiField ListBox mode;
|
||||
@@ -172,6 +175,7 @@ public class PreferencesBox extends Composite {
|
||||
lineLength.setEnabled(true);
|
||||
lineLength.setIntValue(prefs.lineLength());
|
||||
}
|
||||
cursorBlinkRate.setIntValue(prefs.cursorBlinkRate());
|
||||
syntaxHighlighting.setValue(prefs.syntaxHighlighting());
|
||||
whitespaceErrors.setValue(prefs.showWhitespaceErrors());
|
||||
showTabs.setValue(prefs.showTabs());
|
||||
@@ -189,6 +193,7 @@ public class PreferencesBox extends Composite {
|
||||
autoHideDiffTableHeader.setValue(!prefs.autoHideDiffTableHeader());
|
||||
manualReview.setValue(prefs.manualReview());
|
||||
expandAllComments.setValue(prefs.expandAllComments());
|
||||
matchBrackets.setValue(prefs.matchBrackets());
|
||||
setTheme(prefs.theme());
|
||||
|
||||
if (view == null || view.canRenderEntireFile(prefs)) {
|
||||
@@ -342,6 +347,20 @@ public class PreferencesBox extends Composite {
|
||||
}
|
||||
}
|
||||
|
||||
@UiHandler("cursorBlinkRate")
|
||||
void onCursoBlinkRate(ValueChangeEvent<String> e) {
|
||||
String v = e.getValue();
|
||||
if (v != null && v.length() > 0) {
|
||||
// A negative value hides the cursor entirely:
|
||||
// don't let user shoot himself in the foot.
|
||||
prefs.cursorBlinkRate(Math.max(0, Integer.parseInt(v)));
|
||||
view.getCmFromSide(DisplaySide.A).setOption("cursorBlinkRate",
|
||||
prefs.cursorBlinkRate());
|
||||
view.getCmFromSide(DisplaySide.B).setOption("cursorBlinkRate",
|
||||
prefs.cursorBlinkRate());
|
||||
}
|
||||
}
|
||||
|
||||
@UiHandler("showTabs")
|
||||
void onShowTabs(ValueChangeEvent<Boolean> e) {
|
||||
prefs.showTabs(e.getValue());
|
||||
@@ -465,6 +484,15 @@ public class PreferencesBox extends Composite {
|
||||
}
|
||||
}
|
||||
|
||||
@UiHandler("matchBrackets")
|
||||
void onMatchBrackets(ValueChangeEvent<Boolean> e) {
|
||||
prefs.matchBrackets(e.getValue());
|
||||
view.getCmFromSide(DisplaySide.A).setOption("matchBrackets",
|
||||
prefs.matchBrackets());
|
||||
view.getCmFromSide(DisplaySide.B).setOption("matchBrackets",
|
||||
prefs.matchBrackets());
|
||||
}
|
||||
|
||||
@UiHandler("theme")
|
||||
void onTheme(@SuppressWarnings("unused") ChangeEvent e) {
|
||||
final Theme newTheme = getSelectedTheme();
|
||||
|
||||
@@ -195,6 +195,12 @@ limitations under the License.
|
||||
alignment='RIGHT'/>
|
||||
or <g:CheckBox ui:field='contextEntireFile'>entire file</g:CheckBox></ui:msg></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><ui:msg>Cursor Blink Rate</ui:msg></th>
|
||||
<td><x:NpIntTextBox ui:field='cursorBlinkRate'
|
||||
visibleLength='4'
|
||||
alignment='RIGHT'/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><ui:msg>Intraline Difference</ui:msg></th>
|
||||
<td><g:ToggleButton ui:field='intralineDifference'>
|
||||
@@ -283,6 +289,13 @@ limitations under the License.
|
||||
<g:downFace><ui:msg>Slow</ui:msg></g:downFace>
|
||||
</g:ToggleButton></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><ui:msg>Match Brackets</ui:msg></th>
|
||||
<td><g:ToggleButton ui:field='matchBrackets'>
|
||||
<g:upFace><ui:msg>Off</ui:msg></g:upFace>
|
||||
<g:downFace><ui:msg>On</ui:msg></g:downFace>
|
||||
</g:ToggleButton></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
|
||||
@@ -636,7 +636,7 @@ public class SideBySide extends Screen {
|
||||
Element parent) {
|
||||
return CodeMirror.create(parent, Configuration.create()
|
||||
.set("readOnly", true)
|
||||
.set("cursorBlinkRate", 0)
|
||||
.set("cursorBlinkRate", prefs.cursorBlinkRate())
|
||||
.set("cursorHeight", 0.85)
|
||||
.set("lineNumbers", prefs.showLineNumbers())
|
||||
.set("tabSize", prefs.tabSize())
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.google.gerrit.server.notedb.NotesMigration;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.gwtjsonrpc.server.JsonServlet;
|
||||
import com.google.gwtjsonrpc.server.RPCServletUtils;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -250,8 +249,7 @@ public class HostPageServlet extends HttpServlet {
|
||||
private DiffPreferencesInfo getDiffPreferences(IdentifiedUser user) {
|
||||
try {
|
||||
return getDiff.apply(new AccountResource(user));
|
||||
} catch (AuthException | OrmException | ConfigInvalidException
|
||||
| IOException e) {
|
||||
} catch (AuthException | ConfigInvalidException | IOException e) {
|
||||
log.warn("Cannot query account diff preferences", e);
|
||||
}
|
||||
return DiffPreferencesInfo.defaults();
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.reviewdb.client;
|
||||
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
import com.google.gwtorm.client.Column;
|
||||
|
||||
/** Diff formatting preferences of an account */
|
||||
public class AccountDiffPreference {
|
||||
|
||||
/** Default number of lines of context. */
|
||||
public static final short DEFAULT_CONTEXT = 10;
|
||||
|
||||
/** Context setting to display the entire file. */
|
||||
public static final short WHOLE_FILE_CONTEXT = -1;
|
||||
|
||||
/** Typical valid choices for the default context setting. */
|
||||
public static final short[] CONTEXT_CHOICES =
|
||||
{3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT};
|
||||
|
||||
public static enum Whitespace implements CodedEnum {
|
||||
IGNORE_NONE('N'), //
|
||||
IGNORE_TRAILING('E'), //
|
||||
IGNORE_LEADING_AND_TRAILING('S'), //
|
||||
IGNORE_ALL('A');
|
||||
|
||||
private final char code;
|
||||
|
||||
private Whitespace(final char c) {
|
||||
code = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static Whitespace forCode(final char c) {
|
||||
for (final Whitespace s : Whitespace.values()) {
|
||||
if (s.code == c) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static AccountDiffPreference createDefault(Account.Id accountId) {
|
||||
AccountDiffPreference p = new AccountDiffPreference(accountId);
|
||||
p.setIgnoreWhitespace(Whitespace.IGNORE_NONE);
|
||||
p.setTheme(Theme.DEFAULT);
|
||||
p.setTabSize(8);
|
||||
p.setLineLength(100);
|
||||
p.setSyntaxHighlighting(true);
|
||||
p.setShowWhitespaceErrors(true);
|
||||
p.setShowLineEndings(true);
|
||||
p.setIntralineDifference(true);
|
||||
p.setShowTabs(true);
|
||||
p.setContext(DEFAULT_CONTEXT);
|
||||
p.setManualReview(false);
|
||||
p.setHideEmptyPane(false);
|
||||
p.setAutoHideDiffTableHeader(true);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Column(id = 1, name = Column.NONE)
|
||||
protected Account.Id accountId;
|
||||
|
||||
@Column(id = 2)
|
||||
protected char ignoreWhitespace;
|
||||
|
||||
@Column(id = 3)
|
||||
protected int tabSize;
|
||||
|
||||
@Column(id = 4)
|
||||
protected int lineLength;
|
||||
|
||||
@Column(id = 5)
|
||||
protected boolean syntaxHighlighting;
|
||||
|
||||
@Column(id = 6)
|
||||
protected boolean showWhitespaceErrors;
|
||||
|
||||
@Column(id = 7)
|
||||
protected boolean intralineDifference;
|
||||
|
||||
@Column(id = 8)
|
||||
protected boolean showTabs;
|
||||
|
||||
/** Number of lines of context when viewing a patch. */
|
||||
@Column(id = 9)
|
||||
protected short context;
|
||||
|
||||
@Column(id = 10)
|
||||
protected boolean skipDeleted;
|
||||
|
||||
@Column(id = 11)
|
||||
protected boolean skipUncommented;
|
||||
|
||||
@Column(id = 12)
|
||||
protected boolean expandAllComments;
|
||||
|
||||
@Column(id = 13)
|
||||
protected boolean retainHeader;
|
||||
|
||||
@Column(id = 14)
|
||||
protected boolean manualReview;
|
||||
|
||||
@Column(id = 15)
|
||||
protected boolean showLineEndings;
|
||||
|
||||
@Column(id = 16)
|
||||
protected boolean hideTopMenu;
|
||||
|
||||
@Column(id = 17)
|
||||
protected boolean hideLineNumbers;
|
||||
|
||||
@Column(id = 18)
|
||||
protected boolean renderEntireFile;
|
||||
|
||||
@Column(id = 19, length = 20, notNull = false)
|
||||
protected String theme;
|
||||
|
||||
@Column(id = 20)
|
||||
protected boolean hideEmptyPane;
|
||||
|
||||
@Column(id = 21)
|
||||
protected boolean autoHideDiffTableHeader;
|
||||
|
||||
protected AccountDiffPreference() {
|
||||
}
|
||||
|
||||
public AccountDiffPreference(Account.Id accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public AccountDiffPreference(AccountDiffPreference p) {
|
||||
this.accountId = p.accountId;
|
||||
this.ignoreWhitespace = p.ignoreWhitespace;
|
||||
this.tabSize = p.tabSize;
|
||||
this.lineLength = p.lineLength;
|
||||
this.syntaxHighlighting = p.syntaxHighlighting;
|
||||
this.showWhitespaceErrors = p.showWhitespaceErrors;
|
||||
this.showLineEndings = p.showLineEndings;
|
||||
this.intralineDifference = p.intralineDifference;
|
||||
this.showTabs = p.showTabs;
|
||||
this.skipDeleted = p.skipDeleted;
|
||||
this.skipUncommented = p.skipUncommented;
|
||||
this.expandAllComments = p.expandAllComments;
|
||||
this.context = p.context;
|
||||
this.retainHeader = p.retainHeader;
|
||||
this.manualReview = p.manualReview;
|
||||
this.hideTopMenu = p.hideTopMenu;
|
||||
this.hideLineNumbers = p.hideLineNumbers;
|
||||
this.renderEntireFile = p.renderEntireFile;
|
||||
this.hideEmptyPane = p.hideEmptyPane;
|
||||
this.autoHideDiffTableHeader = p.autoHideDiffTableHeader;
|
||||
}
|
||||
|
||||
public Account.Id getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public Whitespace getIgnoreWhitespace() {
|
||||
return Whitespace.forCode(ignoreWhitespace);
|
||||
}
|
||||
|
||||
public void setIgnoreWhitespace(Whitespace ignoreWhitespace) {
|
||||
this.ignoreWhitespace = ignoreWhitespace.getCode();
|
||||
}
|
||||
|
||||
public int getTabSize() {
|
||||
return tabSize;
|
||||
}
|
||||
|
||||
public void setTabSize(int tabSize) {
|
||||
this.tabSize = tabSize;
|
||||
}
|
||||
|
||||
public int getLineLength() {
|
||||
return lineLength;
|
||||
}
|
||||
|
||||
public void setLineLength(int lineLength) {
|
||||
this.lineLength = lineLength;
|
||||
}
|
||||
|
||||
public boolean isSyntaxHighlighting() {
|
||||
return syntaxHighlighting;
|
||||
}
|
||||
|
||||
public void setSyntaxHighlighting(boolean syntaxHighlighting) {
|
||||
this.syntaxHighlighting = syntaxHighlighting;
|
||||
}
|
||||
|
||||
public boolean isShowWhitespaceErrors() {
|
||||
return showWhitespaceErrors;
|
||||
}
|
||||
|
||||
public void setShowWhitespaceErrors(boolean showWhitespaceErrors) {
|
||||
this.showWhitespaceErrors = showWhitespaceErrors;
|
||||
}
|
||||
|
||||
public boolean isShowLineEndings() {
|
||||
return showLineEndings;
|
||||
}
|
||||
|
||||
public void setShowLineEndings(boolean showLineEndings) {
|
||||
this.showLineEndings = showLineEndings;
|
||||
}
|
||||
|
||||
public boolean isIntralineDifference() {
|
||||
return intralineDifference;
|
||||
}
|
||||
|
||||
public void setIntralineDifference(boolean intralineDifference) {
|
||||
this.intralineDifference = intralineDifference;
|
||||
}
|
||||
|
||||
public boolean isShowTabs() {
|
||||
return showTabs;
|
||||
}
|
||||
|
||||
public void setShowTabs(boolean showTabs) {
|
||||
this.showTabs = showTabs;
|
||||
}
|
||||
|
||||
/** Get the number of lines of context when viewing a patch. */
|
||||
public short getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** Set the number of lines of context when viewing a patch. */
|
||||
public void setContext(final short context) {
|
||||
assert 0 <= context || context == WHOLE_FILE_CONTEXT;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public boolean isSkipDeleted() {
|
||||
return skipDeleted;
|
||||
}
|
||||
|
||||
public void setSkipDeleted(boolean skip) {
|
||||
skipDeleted = skip;
|
||||
}
|
||||
|
||||
public boolean isSkipUncommented() {
|
||||
return skipUncommented;
|
||||
}
|
||||
|
||||
public void setSkipUncommented(boolean skip) {
|
||||
skipUncommented = skip;
|
||||
}
|
||||
|
||||
public boolean isExpandAllComments() {
|
||||
return expandAllComments;
|
||||
}
|
||||
|
||||
public void setExpandAllComments(boolean expand) {
|
||||
expandAllComments = expand;
|
||||
}
|
||||
|
||||
public boolean isRetainHeader() {
|
||||
return retainHeader;
|
||||
}
|
||||
|
||||
public void setRetainHeader(boolean retain) {
|
||||
retainHeader = retain;
|
||||
}
|
||||
|
||||
public boolean isManualReview() {
|
||||
return manualReview;
|
||||
}
|
||||
|
||||
public void setManualReview(boolean manual) {
|
||||
manualReview = manual;
|
||||
}
|
||||
|
||||
public boolean isHideTopMenu() {
|
||||
return hideTopMenu;
|
||||
}
|
||||
|
||||
public void setHideTopMenu(boolean hide) {
|
||||
hideTopMenu = hide;
|
||||
}
|
||||
|
||||
public boolean isHideLineNumbers() {
|
||||
return hideLineNumbers;
|
||||
}
|
||||
|
||||
public void setHideLineNumbers(boolean hide) {
|
||||
hideLineNumbers = hide;
|
||||
}
|
||||
|
||||
public boolean isRenderEntireFile() {
|
||||
return renderEntireFile;
|
||||
}
|
||||
|
||||
public void setRenderEntireFile(boolean render) {
|
||||
renderEntireFile = render;
|
||||
}
|
||||
|
||||
public Theme getTheme() {
|
||||
return theme != null ? Theme.valueOf(theme) : null;
|
||||
}
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
this.theme = theme != null ? theme.name() : null;
|
||||
}
|
||||
|
||||
public boolean isHideEmptyPane() {
|
||||
return hideEmptyPane;
|
||||
}
|
||||
|
||||
public void setHideEmptyPane(boolean hideEmptyPane) {
|
||||
this.hideEmptyPane = hideEmptyPane;
|
||||
}
|
||||
|
||||
public void setAutoHideDiffTableHeader(boolean hide) {
|
||||
autoHideDiffTableHeader = hide;
|
||||
}
|
||||
|
||||
public boolean isAutoHideDiffTableHeader() {
|
||||
return autoHideDiffTableHeader;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.reviewdb.server;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gwtorm.server.Access;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.PrimaryKey;
|
||||
|
||||
public interface AccountDiffPreferenceAccess extends Access<AccountDiffPreference, Account.Id> {
|
||||
|
||||
@Override
|
||||
@PrimaryKey("accountId")
|
||||
AccountDiffPreference get(Account.Id key) throws OrmException;
|
||||
|
||||
}
|
||||
@@ -68,8 +68,7 @@ public interface ReviewDb extends Schema {
|
||||
@Relation(id = 13)
|
||||
AccountGroupMemberAuditAccess accountGroupMembersAudit();
|
||||
|
||||
@Relation(id = 17)
|
||||
AccountDiffPreferenceAccess accountDiffPreferences();
|
||||
//Deleted @Relation(id = 17)
|
||||
|
||||
@Relation(id = 18)
|
||||
StarredChangeAccess starredChanges();
|
||||
|
||||
@@ -20,22 +20,16 @@ import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.UserConfigSections;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -43,36 +37,28 @@ import java.io.IOException;
|
||||
@Singleton
|
||||
public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<AllUsersName> allUsersName;
|
||||
private final GitRepositoryManager gitMgr;
|
||||
private final boolean readFromGit;
|
||||
|
||||
@Inject
|
||||
GetDiffPreferences(Provider<CurrentUser> self,
|
||||
Provider<ReviewDb> db,
|
||||
@GerritServerConfig Config cfg,
|
||||
Provider<AllUsersName> allUsersName,
|
||||
GitRepositoryManager gitMgr) {
|
||||
this.self = self;
|
||||
this.db = db;
|
||||
this.allUsersName = allUsersName;
|
||||
this.gitMgr = gitMgr;
|
||||
readFromGit = cfg.getBoolean("user", null, "readPrefsFromGit", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo apply(AccountResource rsrc)
|
||||
throws AuthException, OrmException, ConfigInvalidException, IOException {
|
||||
throws AuthException, ConfigInvalidException, IOException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("restricted to administrator");
|
||||
}
|
||||
|
||||
Account.Id userId = rsrc.getUser().getAccountId();
|
||||
return readFromGit
|
||||
? readFromGit(userId, gitMgr, allUsersName.get(), null)
|
||||
: readFromDb(userId);
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return readFromGit(id, gitMgr, allUsersName.get(), null);
|
||||
}
|
||||
|
||||
static DiffPreferencesInfo readFromGit(Account.Id id,
|
||||
@@ -89,65 +75,4 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
return prefs;
|
||||
}
|
||||
}
|
||||
|
||||
private DiffPreferencesInfo readFromDb(Account.Id id)
|
||||
throws OrmException {
|
||||
AccountDiffPreference a = db.get().accountDiffPreferences().get(id);
|
||||
return nullify(initFromDb(a));
|
||||
}
|
||||
|
||||
static DiffPreferencesInfo initFromDb(AccountDiffPreference a) {
|
||||
DiffPreferencesInfo prefs = DiffPreferencesInfo.defaults();
|
||||
if (a != null) {
|
||||
prefs.context = (int)a.getContext();
|
||||
prefs.expandAllComments = a.isExpandAllComments();
|
||||
prefs.hideLineNumbers = a.isHideLineNumbers();
|
||||
prefs.hideTopMenu = a.isHideTopMenu();
|
||||
prefs.ignoreWhitespace = PatchListKey.WHITESPACE_TYPES.inverse().get(
|
||||
a.getIgnoreWhitespace().getCode());
|
||||
prefs.intralineDifference = a.isIntralineDifference();
|
||||
prefs.lineLength = a.getLineLength();
|
||||
prefs.manualReview = a.isManualReview();
|
||||
prefs.renderEntireFile = a.isRenderEntireFile();
|
||||
prefs.retainHeader = a.isRetainHeader();
|
||||
prefs.showLineEndings = a.isShowLineEndings();
|
||||
prefs.showTabs = a.isShowTabs();
|
||||
prefs.showWhitespaceErrors = a.isShowWhitespaceErrors();
|
||||
prefs.skipDeleted = a.isSkipDeleted();
|
||||
prefs.skipUncommented = a.isSkipUncommented();
|
||||
prefs.syntaxHighlighting = a.isSyntaxHighlighting();
|
||||
prefs.tabSize = a.getTabSize();
|
||||
prefs.theme = a.getTheme();
|
||||
prefs.hideEmptyPane = a.isHideEmptyPane();
|
||||
prefs.autoHideDiffTableHeader = a.isAutoHideDiffTableHeader();
|
||||
}
|
||||
|
||||
return prefs;
|
||||
}
|
||||
|
||||
private static DiffPreferencesInfo nullify(DiffPreferencesInfo prefs) {
|
||||
prefs.expandAllComments = b(prefs.expandAllComments);
|
||||
prefs.hideLineNumbers = b(prefs.hideLineNumbers);
|
||||
prefs.hideTopMenu = b(prefs.hideTopMenu);
|
||||
prefs.intralineDifference = b(prefs.intralineDifference);
|
||||
prefs.manualReview = b(prefs.manualReview);
|
||||
prefs.renderEntireFile = b(prefs.renderEntireFile);
|
||||
prefs.retainHeader = b(prefs.retainHeader);
|
||||
prefs.showLineEndings = b(prefs.showLineEndings);
|
||||
prefs.showTabs = b(prefs.showTabs);
|
||||
prefs.showWhitespaceErrors = b(prefs.showWhitespaceErrors);
|
||||
prefs.skipDeleted = b(prefs.skipDeleted);
|
||||
prefs.skipUncommented = b(prefs.skipUncommented);
|
||||
prefs.syntaxHighlighting = b(prefs.syntaxHighlighting);
|
||||
prefs.hideEmptyPane = b(prefs.hideEmptyPane);
|
||||
prefs.autoHideDiffTableHeader = b(prefs.autoHideDiffTableHeader);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
private static Boolean b(Boolean b) {
|
||||
if (b == null) {
|
||||
return null;
|
||||
}
|
||||
return b ? Boolean.TRUE : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import static com.google.gerrit.server.account.GetDiffPreferences.initFromDb;
|
||||
import static com.google.gerrit.server.account.GetDiffPreferences.readFromGit;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.loadSection;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||
@@ -24,16 +23,11 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.UserConfigSections;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -41,34 +35,26 @@ import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Singleton
|
||||
public class SetDiffPreferences implements
|
||||
RestModifyView<AccountResource, DiffPreferencesInfo> {
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<MetaDataUpdate.User> metaDataUpdateFactory;
|
||||
private final AllUsersName allUsersName;
|
||||
private final GitRepositoryManager gitMgr;
|
||||
private final boolean readFromGit;
|
||||
|
||||
@Inject
|
||||
SetDiffPreferences(Provider<CurrentUser> self,
|
||||
Provider<ReviewDb> db,
|
||||
@GerritServerConfig Config cfg,
|
||||
Provider<MetaDataUpdate.User> metaDataUpdateFactory,
|
||||
AllUsersName allUsersName,
|
||||
GitRepositoryManager gitMgr) {
|
||||
this.self = self;
|
||||
this.db = db;
|
||||
this.metaDataUpdateFactory = metaDataUpdateFactory;
|
||||
this.allUsersName = allUsersName;
|
||||
this.gitMgr = gitMgr;
|
||||
readFromGit = cfg.getBoolean("user", null, "readPrefsFromGit", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,40 +70,23 @@ public class SetDiffPreferences implements
|
||||
throw new BadRequestException("input must be provided");
|
||||
}
|
||||
|
||||
Account.Id userId = rsrc.getUser().getAccountId();
|
||||
DiffPreferencesInfo n = readFromGit
|
||||
? readFromGit(userId, gitMgr, allUsersName, in)
|
||||
: merge(initFromDb(db.get().accountDiffPreferences().get(userId)), in);
|
||||
DiffPreferencesInfo out = writeToGit(n, userId);
|
||||
writeToDb(n, userId);
|
||||
return out;
|
||||
}
|
||||
|
||||
private void writeToDb(DiffPreferencesInfo in, Account.Id id)
|
||||
throws OrmException {
|
||||
db.get().accounts().beginTransaction(id);
|
||||
try {
|
||||
AccountDiffPreference p = db.get().accountDiffPreferences().get(id);
|
||||
p = initAccountDiffPreferences(p, in, id);
|
||||
db.get().accountDiffPreferences().upsert(Collections.singleton(p));
|
||||
db.get().commit();
|
||||
} finally {
|
||||
db.get().rollback();
|
||||
}
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return writeToGit(readFromGit(id, gitMgr, allUsersName, in), id);
|
||||
}
|
||||
|
||||
private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in,
|
||||
Account.Id useId) throws RepositoryNotFoundException, IOException,
|
||||
Account.Id userId) throws RepositoryNotFoundException, IOException,
|
||||
ConfigInvalidException {
|
||||
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
|
||||
|
||||
VersionedAccountPreferences prefs;
|
||||
DiffPreferencesInfo out = new DiffPreferencesInfo();
|
||||
try {
|
||||
prefs = VersionedAccountPreferences.forUser(useId);
|
||||
VersionedAccountPreferences prefs = VersionedAccountPreferences.forUser(
|
||||
userId);
|
||||
prefs.load(md);
|
||||
DiffPreferencesInfo defaults = DiffPreferencesInfo.defaults();
|
||||
storeSection(prefs.getConfig(), UserConfigSections.DIFF, null, in,
|
||||
DiffPreferencesInfo.defaults());
|
||||
defaults);
|
||||
prefs.commit(md);
|
||||
loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out,
|
||||
DiffPreferencesInfo.defaults(), null);
|
||||
@@ -126,112 +95,4 @@ public class SetDiffPreferences implements
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// TODO(davido): Remove manual merging in follow-up change
|
||||
private DiffPreferencesInfo merge(DiffPreferencesInfo n,
|
||||
DiffPreferencesInfo i) {
|
||||
if (i.context != null) {
|
||||
n.context = i.context;
|
||||
}
|
||||
if (i.expandAllComments != null) {
|
||||
n.expandAllComments = i.expandAllComments;
|
||||
}
|
||||
if (i.hideLineNumbers != null) {
|
||||
n.hideLineNumbers = i.hideLineNumbers;
|
||||
}
|
||||
if (i.hideTopMenu != null) {
|
||||
n.hideTopMenu = i.hideTopMenu;
|
||||
}
|
||||
if (i.ignoreWhitespace != null) {
|
||||
n.ignoreWhitespace = i.ignoreWhitespace;
|
||||
}
|
||||
if (i.intralineDifference != null) {
|
||||
n.intralineDifference = i.intralineDifference;
|
||||
}
|
||||
if (i.lineLength != null) {
|
||||
n.lineLength = i.lineLength;
|
||||
}
|
||||
if (i.manualReview != null) {
|
||||
n.manualReview = i.manualReview;
|
||||
}
|
||||
if (i.renderEntireFile != null) {
|
||||
n.renderEntireFile = i.renderEntireFile;
|
||||
}
|
||||
if (i.retainHeader != null) {
|
||||
n.retainHeader = i.retainHeader;
|
||||
}
|
||||
if (i.showLineEndings != null) {
|
||||
n.showLineEndings = i.showLineEndings;
|
||||
}
|
||||
if (i.showTabs != null) {
|
||||
n.showTabs = i.showTabs;
|
||||
}
|
||||
if (i.showWhitespaceErrors != null) {
|
||||
n.showWhitespaceErrors = i.showWhitespaceErrors;
|
||||
}
|
||||
if (i.skipDeleted != null) {
|
||||
n.skipDeleted = i.skipDeleted;
|
||||
}
|
||||
if (i.skipUncommented != null) {
|
||||
n.skipUncommented = i.skipUncommented;
|
||||
}
|
||||
if (i.syntaxHighlighting != null) {
|
||||
n.syntaxHighlighting = i.syntaxHighlighting;
|
||||
}
|
||||
if (i.tabSize != null) {
|
||||
n.tabSize = i.tabSize;
|
||||
}
|
||||
if (i.theme != null) {
|
||||
n.theme = i.theme;
|
||||
}
|
||||
if (i.hideEmptyPane != null) {
|
||||
n.hideEmptyPane = i.hideEmptyPane;
|
||||
}
|
||||
if (i.autoHideDiffTableHeader != null) {
|
||||
n.autoHideDiffTableHeader = i.autoHideDiffTableHeader;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
private static AccountDiffPreference initAccountDiffPreferences(
|
||||
AccountDiffPreference a, DiffPreferencesInfo i, Account.Id id) {
|
||||
if (a == null) {
|
||||
a = AccountDiffPreference.createDefault(id);
|
||||
}
|
||||
int context = i.context == null
|
||||
? DiffPreferencesInfo.DEFAULT_CONTEXT
|
||||
: i.context;
|
||||
a.setContext((short)context);
|
||||
a.setExpandAllComments(b(i.expandAllComments));
|
||||
a.setHideLineNumbers(b(i.hideLineNumbers));
|
||||
a.setHideTopMenu(b(i.hideTopMenu));
|
||||
a.setIgnoreWhitespace(i.ignoreWhitespace == null
|
||||
? Whitespace.IGNORE_NONE
|
||||
: Whitespace.forCode(
|
||||
PatchListKey.WHITESPACE_TYPES.get(i.ignoreWhitespace)));
|
||||
a.setIntralineDifference(b(i.intralineDifference));
|
||||
a.setLineLength(i.lineLength == null
|
||||
? DiffPreferencesInfo.DEFAULT_LINE_LENGTH
|
||||
: i.lineLength);
|
||||
a.setManualReview(b(i.manualReview));
|
||||
a.setRenderEntireFile(b(i.renderEntireFile));
|
||||
a.setRetainHeader(b(i.retainHeader));
|
||||
a.setShowLineEndings(b(i.showLineEndings));
|
||||
a.setShowTabs(b(i.showTabs));
|
||||
a.setShowWhitespaceErrors(b(i.showWhitespaceErrors));
|
||||
a.setSkipDeleted(b(i.skipDeleted));
|
||||
a.setSkipUncommented(b(i.skipUncommented));
|
||||
a.setSyntaxHighlighting(b(i.syntaxHighlighting));
|
||||
a.setTabSize(i.tabSize == null
|
||||
? DiffPreferencesInfo.DEFAULT_TAB_SIZE
|
||||
: i.tabSize);
|
||||
a.setTheme(i.theme);
|
||||
a.setHideEmptyPane(b(i.hideEmptyPane));
|
||||
a.setAutoHideDiffTableHeader(b(i.autoHideDiffTableHeader));
|
||||
return a;
|
||||
}
|
||||
|
||||
private static boolean b(Boolean b) {
|
||||
return b == null ? false : b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
/** A version of the database schema. */
|
||||
public abstract class SchemaVersion {
|
||||
/** The current schema version. */
|
||||
public static final Class<Schema_114> C = Schema_114.class;
|
||||
public static final Class<Schema_115> C = Schema_115.class;
|
||||
|
||||
public static int getBinaryVersion() {
|
||||
return guessVersion(C);
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
// Copyright (C) 2015 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.VersionedAccountPreferences;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.UserConfigSections;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
import org.eclipse.jgit.lib.NullProgressMonitor;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Schema_115 extends SchemaVersion {
|
||||
private final GitRepositoryManager mgr;
|
||||
private final AllUsersName allUsersName;
|
||||
private final PersonIdent serverUser;
|
||||
|
||||
@Inject
|
||||
Schema_115(Provider<Schema_114> prior,
|
||||
GitRepositoryManager mgr,
|
||||
AllUsersName allUsersName,
|
||||
@GerritPersonIdent PersonIdent serverUser) {
|
||||
super(prior);
|
||||
this.mgr = mgr;
|
||||
this.allUsersName = allUsersName;
|
||||
this.serverUser = serverUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void migrateData(ReviewDb db, UpdateUI ui)
|
||||
throws OrmException, SQLException {
|
||||
Map<Account.Id, DiffPreferencesInfo> imports = new HashMap<>();
|
||||
try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
|
||||
ResultSet rs = stmt.executeQuery(
|
||||
"SELECT "
|
||||
+ "id, "
|
||||
+ "context, "
|
||||
+ "expand_all_comments, "
|
||||
+ "hide_line_numbers, "
|
||||
+ "hide_top_menu, "
|
||||
+ "ignore_whitespace, "
|
||||
+ "intraline_difference, "
|
||||
+ "line_length, "
|
||||
+ "manual_review, "
|
||||
+ "render_entire_file, "
|
||||
+ "retain_header, "
|
||||
+ "show_line_endings, "
|
||||
+ "show_tabs, "
|
||||
+ "show_whitespace_errors, "
|
||||
+ "skip_deleted, "
|
||||
+ "skip_uncommented, "
|
||||
+ "syntax_highlighting, "
|
||||
+ "tab_size, "
|
||||
+ "theme, "
|
||||
+ "hide_empty_pane, "
|
||||
+ "auto_hide_diff_table_header "
|
||||
+ "FROM account_diff_preferences")) {
|
||||
while (rs.next()) {
|
||||
Account.Id accountId = new Account.Id(rs.getInt(1));
|
||||
DiffPreferencesInfo prefs = new DiffPreferencesInfo();
|
||||
prefs.context = (int)rs.getShort(2);
|
||||
prefs.expandAllComments = toBoolean(rs.getString(3));
|
||||
prefs.hideLineNumbers = toBoolean(rs.getString(4));
|
||||
prefs.hideTopMenu = toBoolean(rs.getString(5));
|
||||
// Enum with char as value
|
||||
prefs.ignoreWhitespace = toWhitespace(rs.getString(6));
|
||||
prefs.intralineDifference = toBoolean(rs.getString(7));
|
||||
prefs.lineLength = rs.getInt(8);
|
||||
prefs.manualReview = toBoolean(rs.getString(9));
|
||||
prefs.renderEntireFile = toBoolean(rs.getString(10));
|
||||
prefs.retainHeader = toBoolean(rs.getString(11));
|
||||
prefs.showLineEndings = toBoolean(rs.getString(12));
|
||||
prefs.showTabs = toBoolean(rs.getString(13));
|
||||
prefs.showWhitespaceErrors = toBoolean(rs.getString(14));
|
||||
prefs.skipDeleted = toBoolean(rs.getString(15));
|
||||
prefs.skipUncommented = toBoolean(rs.getString(16));
|
||||
prefs.syntaxHighlighting = toBoolean(rs.getString(17));
|
||||
prefs.tabSize = rs.getInt(18);
|
||||
// Enum with name as values; can be null
|
||||
prefs.theme = toTheme(rs.getString(19));
|
||||
prefs.hideEmptyPane = toBoolean(rs.getString(20));
|
||||
prefs.autoHideDiffTableHeader = toBoolean(rs.getString(21));
|
||||
imports.put(accountId, prefs);
|
||||
}
|
||||
}
|
||||
|
||||
if (imports.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (Repository git = mgr.openRepository(allUsersName);
|
||||
RevWalk rw = new RevWalk(git)) {
|
||||
BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
|
||||
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED,
|
||||
allUsersName, git, bru);
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
|
||||
for (Map.Entry<Account.Id, DiffPreferencesInfo> e : imports.entrySet()) {
|
||||
VersionedAccountPreferences p =
|
||||
VersionedAccountPreferences.forUser(e.getKey());
|
||||
p.load(md);
|
||||
storeSection(p.getConfig(), UserConfigSections.DIFF, null,
|
||||
e.getValue(), DiffPreferencesInfo.defaults());
|
||||
p.commit(md);
|
||||
}
|
||||
|
||||
bru.execute(rw, NullProgressMonitor.INSTANCE);
|
||||
} catch (ConfigInvalidException | IOException ex) {
|
||||
throw new OrmException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static Theme toTheme(String v) {
|
||||
if (v == null) {
|
||||
return Theme.DEFAULT;
|
||||
}
|
||||
return Theme.valueOf(v);
|
||||
}
|
||||
|
||||
private static Whitespace toWhitespace(String v) {
|
||||
Preconditions.checkNotNull(v);
|
||||
if (v.isEmpty()) {
|
||||
return Whitespace.IGNORE_NONE;
|
||||
}
|
||||
Whitespace r = PatchListKey.WHITESPACE_TYPES.inverse().get(v.charAt(0));
|
||||
if (r == null) {
|
||||
throw new IllegalArgumentException("Cannot find Whitespace type for: "
|
||||
+ v);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private static boolean toBoolean(String v) {
|
||||
Preconditions.checkState(!Strings.isNullOrEmpty(v));
|
||||
return v.equals("Y");
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.testutil;
|
||||
|
||||
import com.google.gerrit.reviewdb.server.AccountAccess;
|
||||
import com.google.gerrit.reviewdb.server.AccountDiffPreferenceAccess;
|
||||
import com.google.gerrit.reviewdb.server.AccountExternalIdAccess;
|
||||
import com.google.gerrit.reviewdb.server.AccountGroupAccess;
|
||||
import com.google.gerrit.reviewdb.server.AccountGroupByIdAccess;
|
||||
@@ -124,11 +123,6 @@ public class DisabledReviewDb implements ReviewDb {
|
||||
throw new Disabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountDiffPreferenceAccess accountDiffPreferences() {
|
||||
throw new Disabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StarredChangeAccess starredChanges() {
|
||||
throw new Disabled();
|
||||
|
||||
Reference in New Issue
Block a user