Replace ACCOUNT_DIFF_PREFERENCES table with Git backend (part1)

Replace the usage of AccountDiffPreference with a different class in
extension API package.

Data is saved optimized in Git backend: default values are discarded
during save operation and restored during read operation; so that
this optimization step is transparent for the callers.

For example when only one setting, theme in this case, differs from
the default value, only this value is written into diff section in
preferences.config file:

+[diff]
+       theme = eclipse

To support live migration, the upgrade is done in two steps:

* part1 (this change):
  o Always write to both git and db
  o Introduce new configuration option to indicate whether to read from
    git or db, initially set to read from db
  o First binary update: some servers are reading/writing just the db;
    some servers are additionally writing to git
  o After first update: all servers are reading from the db, writing to
    both
  o Batch copy data from db to git (only related to non open source
    Gerrit version)
  o Update all servers to read from git. During the update, some will
    still be reading from the db; that's ok, because everybody is
    writing to git
* part2 (next change):
  o Bump database version, migrate the data from db to git, delete the
    table (and the flag) from the code and update the servers.

Change-Id: I30a6d82f4a8d0c33ae9bb26d7f93c66bd0cb8bee
This commit is contained in:
David Ostrovsky 2014-11-16 18:48:50 +01:00 committed by Edwin Kempin
parent ddd8ec8d06
commit 7d5a771844
43 changed files with 836 additions and 475 deletions

View File

@ -0,0 +1,160 @@
// 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.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import com.google.gerrit.acceptance.AbstractDaemonTest;
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 {
assertEquals(HttpStatus.SC_NOT_FOUND,
adminSession.get("/accounts/non-existing/preferences.diff")
.getStatusCode());
}
@Test
public void getDiffPreferences() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email
+ "/preferences.diff");
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
DiffPreferencesInfo d = DiffPreferencesInfo.defaults();
DiffPreferencesInfo o =
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
assertThat(o.context).isEqualTo(d.context);
assertThat(o.tabSize).isEqualTo(d.tabSize);
assertThat(o.lineLength).isEqualTo(d.lineLength);
assertThat(o.expandAllComments).isNull();
assertThat(o.intralineDifference).isEqualTo(d.intralineDifference);
assertThat(o.manualReview).isNull();
assertThat(o.retainHeader).isNull();
assertThat(o.showLineEndings).isEqualTo(d.showLineEndings);
assertThat(o.showTabs).isEqualTo(d.showTabs);
assertThat(o.showWhitespaceErrors).isEqualTo(d.showWhitespaceErrors);
assertThat(o.skipDeleted).isNull();
assertThat(o.skipUncommented).isNull();
assertThat(o.syntaxHighlighting).isEqualTo(d.syntaxHighlighting);
assertThat(o.hideTopMenu).isNull();
assertThat(o.autoHideDiffTableHeader).isEqualTo(d.autoHideDiffTableHeader);
assertThat(o.hideLineNumbers).isNull();
assertThat(o.renderEntireFile).isNull();
assertThat(o.hideEmptyPane).isNull();
assertThat(o.ignoreWhitespace).isEqualTo(d.ignoreWhitespace);
assertThat(o.theme).isEqualTo(d.theme);
}
@Test
public void setDiffPreferences() throws Exception {
DiffPreferencesInfo i = DiffPreferencesInfo.defaults();
// change all default values
i.context *= -1;
i.tabSize *= -1;
i.lineLength *= -1;
i.theme = Theme.MIDNIGHT;
i.ignoreWhitespace = Whitespace.IGNORE_ALL;
i.expandAllComments ^= true;
i.intralineDifference ^= true;
i.manualReview ^= true;
i.retainHeader ^= true;
i.showLineEndings ^= true;
i.showTabs ^= true;
i.showWhitespaceErrors ^= true;
i.skipDeleted ^= true;
i.skipUncommented ^= true;
i.syntaxHighlighting ^= true;
i.hideTopMenu ^= true;
i.autoHideDiffTableHeader ^= true;
i.hideLineNumbers ^= true;
i.renderEntireFile ^= true;
i.hideEmptyPane ^= true;
RestResponse r = adminSession.put("/accounts/" + admin.email
+ "/preferences.diff", i);
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
DiffPreferencesInfo o = newGson().fromJson(r.getReader(),
DiffPreferencesInfo.class);
assertThat(o.context).isEqualTo(i.context);
assertThat(o.tabSize).isEqualTo(i.tabSize);
assertThat(o.lineLength).isEqualTo(i.lineLength);
assertThat(o.expandAllComments).isEqualTo(i.expandAllComments);
assertThat(o.intralineDifference).isNull();
assertThat(o.manualReview).isEqualTo(i.manualReview);
assertThat(o.retainHeader).isEqualTo(i.retainHeader);
assertThat(o.showLineEndings).isNull();
assertThat(o.showTabs).isNull();
assertThat(o.showWhitespaceErrors).isNull();
assertThat(o.skipDeleted).isEqualTo(i.skipDeleted);
assertThat(o.skipUncommented).isEqualTo(i.skipUncommented);
assertThat(o.syntaxHighlighting).isNull();
assertThat(o.hideTopMenu).isEqualTo(i.hideTopMenu);
assertThat(o.autoHideDiffTableHeader).isNull();
assertThat(o.hideLineNumbers).isEqualTo(i.hideLineNumbers);
assertThat(o.renderEntireFile).isEqualTo(i.renderEntireFile);
assertThat(o.hideEmptyPane).isEqualTo(i.hideEmptyPane);
assertThat(o.ignoreWhitespace).isEqualTo(i.ignoreWhitespace);
assertThat(o.theme).isEqualTo(i.theme);
// Partially fill input record
i = new DiffPreferencesInfo();
i.tabSize = 42;
r = adminSession.put("/accounts/" + admin.email
+ "/preferences.diff", i);
DiffPreferencesInfo a = newGson().fromJson(r.getReader(),
DiffPreferencesInfo.class);
assertThat(a.context).isEqualTo(o.context);
assertThat(a.tabSize).isEqualTo(42);
assertThat(a.lineLength).isEqualTo(o.lineLength);
assertThat(a.expandAllComments).isEqualTo(o.expandAllComments);
assertThat(a.intralineDifference).isNull();
assertThat(a.manualReview).isEqualTo(o.manualReview);
assertThat(a.retainHeader).isEqualTo(o.retainHeader);
assertThat(a.showLineEndings).isNull();
assertThat(a.showTabs).isNull();
assertThat(a.showWhitespaceErrors).isNull();
assertThat(a.skipDeleted).isEqualTo(o.skipDeleted);
assertThat(a.skipUncommented).isEqualTo(o.skipUncommented);
assertThat(a.syntaxHighlighting).isNull();
assertThat(a.hideTopMenu).isEqualTo(o.hideTopMenu);
assertThat(a.autoHideDiffTableHeader).isNull();
assertThat(a.hideLineNumbers).isEqualTo(o.hideLineNumbers);
assertThat(a.renderEntireFile).isEqualTo(o.renderEntireFile);
assertThat(a.hideEmptyPane).isEqualTo(o.hideEmptyPane);
assertThat(a.ignoreWhitespace).isEqualTo(o.ignoreWhitespace);
assertThat(a.theme).isEqualTo(o.theme);
}
}

View File

@ -1,67 +0,0 @@
// Copyright (C) 2013 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.acceptance.rest.account;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.server.account.GetDiffPreferences.DiffPreferencesInfo;
import org.apache.http.HttpStatus;
import org.junit.Test;
public class GetDiffPreferencesIT extends AbstractDaemonTest {
@Test
public void getDiffPreferencesOfNonExistingAccount_NotFound()
throws Exception {
assertThat(adminSession.get("/accounts/non-existing/preferences.diff").getStatusCode())
.isEqualTo(HttpStatus.SC_NOT_FOUND);
}
@Test
public void getDiffPreferences() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email + "/preferences.diff");
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
DiffPreferencesInfo diffPreferences =
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
assertDiffPreferences(new AccountDiffPreference(admin.id), diffPreferences);
}
private static void assertDiffPreferences(AccountDiffPreference expected, DiffPreferencesInfo actual) {
assertThat(actual.context).isEqualTo(expected.getContext());
assertThat(toBoolean(actual.expandAllComments)).isEqualTo(expected.isExpandAllComments());
assertThat(actual.ignoreWhitespace).isEqualTo(expected.getIgnoreWhitespace());
assertThat(toBoolean(actual.intralineDifference)).isEqualTo(expected.isIntralineDifference());
assertThat(actual.lineLength).isEqualTo(expected.getLineLength());
assertThat(toBoolean(actual.manualReview)).isEqualTo(expected.isManualReview());
assertThat(toBoolean(actual.retainHeader)).isEqualTo(expected.isRetainHeader());
assertThat(toBoolean(actual.showLineEndings)).isEqualTo(expected.isShowLineEndings());
assertThat(toBoolean(actual.showTabs)).isEqualTo(expected.isShowTabs());
assertThat(toBoolean(actual.showWhitespaceErrors)).isEqualTo(expected.isShowWhitespaceErrors());
assertThat(toBoolean(actual.skipDeleted)).isEqualTo(expected.isSkipDeleted());
assertThat(toBoolean(actual.skipUncommented)).isEqualTo(expected.isSkipUncommented());
assertThat(toBoolean(actual.syntaxHighlighting)).isEqualTo(expected.isSyntaxHighlighting());
assertThat(actual.tabSize).isEqualTo(expected.getTabSize());
}
private static boolean toBoolean(Boolean b) {
if (b == null) {
return false;
}
return b.booleanValue();
}
}

View File

@ -20,8 +20,8 @@ import static com.google.gerrit.acceptance.GitUtil.pushHead;
import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType; import com.google.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gerrit.server.patch.PatchListCache; import com.google.gerrit.server.patch.PatchListCache;

View File

@ -16,8 +16,8 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit; import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.common.auth.SignInRequired; import com.google.gerrit.common.auth.SignInRequired;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountProjectWatch; import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.RemoteJsonService; import com.google.gwtjsonrpc.common.RemoteJsonService;
@ -35,7 +35,7 @@ public interface AccountService extends RemoteJsonService {
@Audit @Audit
@SignInRequired @SignInRequired
void changeDiffPreferences(AccountDiffPreference diffPref, void changeDiffPreferences(DiffPreferencesInfo diffPref,
AsyncCallback<VoidResult> callback); AsyncCallback<VoidResult> callback);
@SignInRequired @SignInRequired

View File

@ -15,7 +15,7 @@
package com.google.gerrit.common.data; package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit; import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.RemoteJsonService; import com.google.gwtjsonrpc.common.RemoteJsonService;
@ -29,5 +29,5 @@ public interface ChangeDetailService extends RemoteJsonService {
@Audit @Audit
void patchSetDetail2(PatchSet.Id baseId, PatchSet.Id key, void patchSetDetail2(PatchSet.Id baseId, PatchSet.Id key,
AccountDiffPreference diffPrefs, AsyncCallback<PatchSetDetail> callback); DiffPreferencesInfo diffPrefs, AsyncCallback<PatchSetDetail> callback);
} }

View File

@ -14,7 +14,7 @@
package com.google.gerrit.common.data; package com.google.gerrit.common.data;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -22,7 +22,7 @@ import java.util.List;
/** Data sent as part of the host page, to bootstrap the UI. */ /** Data sent as part of the host page, to bootstrap the UI. */
public class HostPageData { public class HostPageData {
public String version; public String version;
public AccountDiffPreference accountDiffPref; public DiffPreferencesInfo accountDiffPref;
public String xGerritAuth; public String xGerritAuth;
public Theme theme; public Theme theme;
public List<String> plugins; public List<String> plugins;

View File

@ -15,7 +15,7 @@
package com.google.gerrit.common.data; package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit; import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.AsyncCallback;
@ -27,5 +27,5 @@ import com.google.gwtjsonrpc.common.RpcImpl.Version;
public interface PatchDetailService extends RemoteJsonService { public interface PatchDetailService extends RemoteJsonService {
@Audit @Audit
void patchScript(Patch.Key key, PatchSet.Id a, PatchSet.Id b, void patchScript(Patch.Key key, PatchSet.Id a, PatchSet.Id b,
AccountDiffPreference diffPrefs, AsyncCallback<PatchScript> callback); DiffPreferencesInfo diffPrefs, AsyncCallback<PatchScript> callback);
} }

View File

@ -14,10 +14,10 @@
package com.google.gerrit.common.data; package com.google.gerrit.common.data;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.prettify.common.EditList; import com.google.gerrit.prettify.common.EditList;
import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType; import com.google.gerrit.reviewdb.client.Patch.ChangeType;
@ -42,7 +42,7 @@ public class PatchScript {
protected FileMode oldMode; protected FileMode oldMode;
protected FileMode newMode; protected FileMode newMode;
protected List<String> header; protected List<String> header;
protected AccountDiffPreference diffPrefs; protected DiffPreferencesInfo diffPrefs;
protected SparseFileContent a; protected SparseFileContent a;
protected SparseFileContent b; protected SparseFileContent b;
protected List<Edit> edits; protected List<Edit> edits;
@ -62,7 +62,7 @@ public class PatchScript {
public PatchScript(final Change.Key ck, final ChangeType ct, final String on, public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
final String nn, final FileMode om, final FileMode nm, final String nn, final FileMode om, final FileMode nm,
final List<String> h, final AccountDiffPreference dp, final List<String> h, final DiffPreferencesInfo dp,
final SparseFileContent ca, final SparseFileContent cb, final SparseFileContent ca, final SparseFileContent cb,
final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb, final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb,
final String mta, final String mtb, final CommentDetail cd, final String mta, final String mtb, final CommentDetail cd,
@ -142,11 +142,11 @@ public class PatchScript {
return history; return history;
} }
public AccountDiffPreference getDiffPrefs() { public DiffPreferencesInfo getDiffPrefs() {
return diffPrefs; return diffPrefs;
} }
public void setDiffPrefs(AccountDiffPreference dp) { public void setDiffPrefs(DiffPreferencesInfo dp) {
diffPrefs = dp; diffPrefs = dp;
} }
@ -155,7 +155,7 @@ public class PatchScript {
} }
public boolean isIgnoreWhitespace() { public boolean isIgnoreWhitespace() {
return diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE; return diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE;
} }
public boolean hasIntralineDifference() { public boolean hasIntralineDifference() {
@ -171,7 +171,7 @@ public class PatchScript {
} }
public boolean isExpandAllComments() { public boolean isExpandAllComments() {
return diffPrefs.isExpandAllComments(); return diffPrefs.expandAllComments;
} }
public SparseFileContent getA() { public SparseFileContent getA() {
@ -195,8 +195,8 @@ public class PatchScript {
} }
public Iterable<EditList.Hunk> getHunks() { public Iterable<EditList.Hunk> getHunks() {
int ctx = diffPrefs.getContext(); int ctx = diffPrefs.context;
if (ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT) { if (ctx == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
ctx = Math.max(a.size(), b.size()); ctx = Math.max(a.size(), b.size());
} }
return new EditList(edits, ctx, a.size(), b.size()).getHunks(); return new EditList(edits, ctx, a.size(), b.size()).getHunks();

View File

@ -0,0 +1,87 @@
// Copyright (C) 2014 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.extensions.client;
public class DiffPreferencesInfo {
/** Default number of lines of context. */
public static final int DEFAULT_CONTEXT = 10;
/** Default tab size. */
public static final int DEFAULT_TAB_SIZE = 8;
/** Default line length. */
public static final int DEFAULT_LINE_LENGTH = 100;
/** 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 {
IGNORE_NONE,
IGNORE_TRAILING,
IGNORE_LEADING_AND_TRAILING,
IGNORE_ALL;
}
public Integer context;
public Integer tabSize;
public Integer lineLength;
public Boolean expandAllComments;
public Boolean intralineDifference;
public Boolean manualReview;
public Boolean showLineEndings;
public Boolean showTabs;
public Boolean showWhitespaceErrors;
public Boolean syntaxHighlighting;
public Boolean hideTopMenu;
public Boolean autoHideDiffTableHeader;
public Boolean hideLineNumbers;
public Boolean renderEntireFile;
public Boolean hideEmptyPane;
public Theme theme;
public Whitespace ignoreWhitespace;
public Boolean retainHeader;
public Boolean skipDeleted;
public Boolean skipUncommented;
public static DiffPreferencesInfo defaults() {
DiffPreferencesInfo i = new DiffPreferencesInfo();
i.context = DEFAULT_CONTEXT;
i.tabSize = DEFAULT_TAB_SIZE;
i.lineLength = DEFAULT_LINE_LENGTH;
i.ignoreWhitespace = Whitespace.IGNORE_NONE;
i.theme = Theme.DEFAULT;
i.expandAllComments = false;
i.intralineDifference = true;
i.manualReview = false;
i.retainHeader = false;
i.showLineEndings = true;
i.showTabs = true;
i.showWhitespaceErrors = true;
i.skipDeleted = false;
i.skipUncommented = false;
i.syntaxHighlighting = true;
i.hideTopMenu = false;
i.autoHideDiffTableHeader = true;
i.hideLineNumbers = false;
i.renderEntireFile = false;
i.hideEmptyPane = false;
return i;
}
}

View File

@ -47,9 +47,9 @@ import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.common.data.HostPageData;
import com.google.gerrit.common.data.SystemInfoService; import com.google.gerrit.common.data.SystemInfoService;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.EditPreferencesInfo; import com.google.gerrit.extensions.client.EditPreferencesInfo;
import com.google.gerrit.extensions.client.GerritTopMenu; import com.google.gerrit.extensions.client.GerritTopMenu;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.aria.client.Roles; import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
@ -119,7 +119,7 @@ public class Gerrit implements EntryPoint {
private static String docUrl; private static String docUrl;
private static HostPageData.Theme myTheme; private static HostPageData.Theme myTheme;
private static String defaultScreenToken; private static String defaultScreenToken;
private static AccountDiffPreference myAccountDiffPref; private static DiffPreferencesInfo myAccountDiffPref;
private static EditPreferencesInfo editPrefs; private static EditPreferencesInfo editPrefs;
private static String xGerritAuth; private static String xGerritAuth;
private static boolean isNoteDbEnabled; private static boolean isNoteDbEnabled;
@ -321,12 +321,12 @@ public class Gerrit implements EntryPoint {
return myPrefs; return myPrefs;
} }
/** @return the currently signed in users's diff preferences; null if no diff preferences defined for the account */ /** @return the currently signed in users's diff preferences, or default values */
public static AccountDiffPreference getAccountDiffPreference() { public static DiffPreferencesInfo getDiffPreferences() {
return myAccountDiffPref; return myAccountDiffPref;
} }
public static void setAccountDiffPreference(AccountDiffPreference accountDiffPref) { public static void setDiffPreferences(DiffPreferencesInfo accountDiffPref) {
myAccountDiffPref = accountDiffPref; myAccountDiffPref = accountDiffPref;
} }

View File

@ -14,55 +14,58 @@
package com.google.gerrit.client.account; package com.google.gerrit.client.account;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.Theme; import com.google.gerrit.extensions.client.Theme;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JavaScriptObject;
public class DiffPreferences extends JavaScriptObject { public class DiffPreferences extends JavaScriptObject {
public static DiffPreferences create(AccountDiffPreference in) { public static DiffPreferences create(DiffPreferencesInfo in) {
DiffPreferences p = createObject().cast(); DiffPreferences p = createObject().cast();
if (in == null) { p.ignoreWhitespace(in.ignoreWhitespace);
in = AccountDiffPreference.createDefault(null); p.tabSize(in.tabSize);
} p.lineLength(in.lineLength);
p.ignoreWhitespace(in.getIgnoreWhitespace()); p.context(in.context);
p.tabSize(in.getTabSize()); p.intralineDifference(in.intralineDifference);
p.lineLength(in.getLineLength()); p.showLineEndings(in.showLineEndings);
p.context(in.getContext()); p.showTabs(in.showTabs);
p.intralineDifference(in.isIntralineDifference()); p.showWhitespaceErrors(in.showWhitespaceErrors);
p.showLineEndings(in.isShowLineEndings()); p.syntaxHighlighting(in.syntaxHighlighting);
p.showTabs(in.isShowTabs()); p.hideTopMenu(in.hideTopMenu);
p.showWhitespaceErrors(in.isShowWhitespaceErrors()); p.autoHideDiffTableHeader(in.autoHideDiffTableHeader);
p.syntaxHighlighting(in.isSyntaxHighlighting()); p.hideLineNumbers(in.hideLineNumbers);
p.hideTopMenu(in.isHideTopMenu()); p.expandAllComments(in.expandAllComments);
p.autoHideDiffTableHeader(in.isAutoHideDiffTableHeader()); p.manualReview(in.manualReview);
p.hideLineNumbers(in.isHideLineNumbers()); p.renderEntireFile(in.renderEntireFile);
p.expandAllComments(in.isExpandAllComments()); p.theme(in.theme);
p.manualReview(in.isManualReview()); p.hideEmptyPane(in.hideEmptyPane);
p.renderEntireFile(in.isRenderEntireFile()); p.retainHeader(in.retainHeader);
p.theme(in.getTheme()); p.skipUncommented(in.skipUncommented);
p.hideEmptyPane(in.isHideEmptyPane()); p.skipDeleted(in.skipDeleted);
return p; return p;
} }
public final void copyTo(AccountDiffPreference p) { public final void copyTo(DiffPreferencesInfo p) {
p.setIgnoreWhitespace(ignoreWhitespace()); p.context = context();
p.setTabSize(tabSize()); p.tabSize = tabSize();
p.setLineLength(lineLength()); p.lineLength = lineLength();
p.setContext((short)context()); p.expandAllComments = expandAllComments();
p.setIntralineDifference(intralineDifference()); p.intralineDifference = intralineDifference();
p.setShowLineEndings(showLineEndings()); p.manualReview = manualReview();
p.setShowTabs(showTabs()); p.retainHeader = retainHeader();
p.setShowWhitespaceErrors(showWhitespaceErrors()); p.showLineEndings = showLineEndings();
p.setSyntaxHighlighting(syntaxHighlighting()); p.showTabs = showTabs();
p.setHideTopMenu(hideTopMenu()); p.showWhitespaceErrors = showWhitespaceErrors();
p.setAutoHideDiffTableHeader(autoHideDiffTableHeader()); p.skipDeleted = skipDeleted();
p.setHideLineNumbers(hideLineNumbers()); p.skipUncommented = skipUncommented();
p.setExpandAllComments(expandAllComments()); p.syntaxHighlighting = syntaxHighlighting();
p.setManualReview(manualReview()); p.hideTopMenu = hideTopMenu();
p.setRenderEntireFile(renderEntireFile()); p.autoHideDiffTableHeader = autoHideDiffTableHeader();
p.setTheme(theme()); p.hideLineNumbers = hideLineNumbers();
p.setHideEmptyPane(hideEmptyPane()); p.renderEntireFile = renderEntireFile();
p.hideEmptyPane = hideEmptyPane();
p.theme = theme();
p.ignoreWhitespace = ignoreWhitespace();
} }
public final void ignoreWhitespace(Whitespace i) { public final void ignoreWhitespace(Whitespace i) {
@ -122,6 +125,9 @@ public class DiffPreferences extends JavaScriptObject {
public final native void manualReview(boolean r) /*-{ this.manual_review = r }-*/; 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 renderEntireFile(boolean r) /*-{ this.render_entire_file = r }-*/;
public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/; 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 skipUncommented(boolean s) /*-{ this.skip_uncommented = s }-*/;
public final native void skipDeleted(boolean s) /*-{ this.skip_deleted = s }-*/;
public final native boolean intralineDifference() /*-{ return this.intraline_difference || false }-*/; 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 showLineEndings() /*-{ return this.show_line_endings || false }-*/;
public final native boolean showTabs() /*-{ return this.show_tabs || false }-*/; public final native boolean showTabs() /*-{ return this.show_tabs || false }-*/;
@ -134,6 +140,9 @@ public class DiffPreferences extends JavaScriptObject {
public final native boolean manualReview() /*-{ return this.manual_review || false }-*/; public final native boolean manualReview() /*-{ return this.manual_review || false }-*/;
public final native boolean renderEntireFile() /*-{ return this.render_entire_file || false }-*/; public final native boolean renderEntireFile() /*-{ return this.render_entire_file || false }-*/;
public final native boolean hideEmptyPane() /*-{ return this.hide_empty_pane || false }-*/; public final native boolean hideEmptyPane() /*-{ return this.hide_empty_pane || false }-*/;
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 }-*/;
private final native void setThemeRaw(String i) /*-{ this.theme = i }-*/; private final native void setThemeRaw(String i) /*-{ this.theme = i }-*/;
private final native void setIgnoreWhitespaceRaw(String i) /*-{ this.ignore_whitespace = i }-*/; private final native void setIgnoreWhitespaceRaw(String i) /*-{ this.ignore_whitespace = i }-*/;

View File

@ -25,7 +25,7 @@ public class MyDiffPreferencesScreen extends SettingsScreen {
super.onInitUI(); super.onInitUI();
PreferencesBox pb = new PreferencesBox(null); PreferencesBox pb = new PreferencesBox(null);
pb.set(DiffPreferences.create(Gerrit.getAccountDiffPreference())); pb.set(DiffPreferences.create(Gerrit.getDiffPreferences()));
FlowPanel p = new FlowPanel(); FlowPanel p = new FlowPanel();
p.setStyleName(pb.getStyle().dialog()); p.setStyleName(pb.getStyle().dialog());
p.add(pb); p.add(pb);

View File

@ -18,7 +18,7 @@ import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.info.FileInfo; import com.google.gerrit.client.info.FileInfo;
import com.google.gerrit.client.rpc.NativeMap; import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.client.rpc.RestApi; import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -69,7 +69,7 @@ public class DiffApi {
return this; return this;
} }
public DiffApi ignoreWhitespace(AccountDiffPreference.Whitespace w) { public DiffApi ignoreWhitespace(DiffPreferencesInfo.Whitespace w) {
switch (w) { switch (w) {
default: default:
case IGNORE_NONE: case IGNORE_NONE:

View File

@ -29,9 +29,9 @@ import com.google.gerrit.client.patches.PatchUtil;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.Natives; import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.NpIntTextBox; import com.google.gerrit.client.ui.NpIntTextBox;
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.extensions.client.Theme;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType; import com.google.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -503,12 +503,9 @@ public class PreferencesBox extends Composite {
AccountApi.putDiffPreferences(prefs, new GerritCallback<DiffPreferences>() { AccountApi.putDiffPreferences(prefs, new GerritCallback<DiffPreferences>() {
@Override @Override
public void onSuccess(DiffPreferences result) { public void onSuccess(DiffPreferences result) {
AccountDiffPreference p = Gerrit.getAccountDiffPreference(); DiffPreferencesInfo p = Gerrit.getDiffPreferences();
if (p == null) {
p = AccountDiffPreference.createDefault(Gerrit.getUserAccount().getId());
}
result.copyTo(p); result.copyTo(p);
Gerrit.setAccountDiffPreference(p); Gerrit.setDiffPreferences(p);
} }
}); });
if (view != null) { if (view != null) {

View File

@ -14,7 +14,8 @@
package com.google.gerrit.client.diff; package com.google.gerrit.client.diff;
import static com.google.gerrit.reviewdb.client.AccountDiffPreference.WHOLE_FILE_CONTEXT; import static com.google.gerrit.extensions.client.DiffPreferencesInfo.WHOLE_FILE_CONTEXT;
import static java.lang.Double.POSITIVE_INFINITY; import static java.lang.Double.POSITIVE_INFINITY;
import com.google.gerrit.client.Dispatcher; import com.google.gerrit.client.Dispatcher;
@ -151,7 +152,7 @@ public class SideBySide extends Screen {
this.startSide = startSide; this.startSide = startSide;
this.startLine = startLine; this.startLine = startLine;
prefs = DiffPreferences.create(Gerrit.getAccountDiffPreference()); prefs = DiffPreferences.create(Gerrit.getDiffPreferences());
handlers = new ArrayList<>(6); handlers = new ArrayList<>(6);
keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation()); keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
header = new Header(keysNavigation, base, revision, path); header = new Header(keysNavigation, base, revision, path);

View File

@ -16,7 +16,7 @@ package com.google.gerrit.client.diff;
import com.google.gerrit.client.diff.DiffInfo.Region; import com.google.gerrit.client.diff.DiffInfo.Region;
import com.google.gerrit.client.patches.SkippedLine; import com.google.gerrit.client.patches.SkippedLine;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gwt.core.client.JsArray; import com.google.gwt.core.client.JsArray;
import net.codemirror.lib.CodeMirror; import net.codemirror.lib.CodeMirror;
@ -39,7 +39,7 @@ class SkipManager {
} }
void render(int context, DiffInfo diff) { void render(int context, DiffInfo diff) {
if (context == AccountDiffPreference.WHOLE_FILE_CONTEXT) { if (context == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
return; return;
} }

View File

@ -28,11 +28,11 @@ import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.common.data.CommentDetail; import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.client.ClientSideFormatter;
import com.google.gerrit.prettify.client.PrettyFormatter; import com.google.gerrit.prettify.client.PrettyFormatter;
import com.google.gerrit.prettify.client.SparseHtmlFile; import com.google.gerrit.prettify.client.SparseHtmlFile;
import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
@ -286,8 +286,8 @@ abstract class AbstractPatchContentTable extends NavigationTable<Object>
} }
protected SparseHtmlFile getSparseHtmlFileA(PatchScript s) { protected SparseHtmlFile getSparseHtmlFileA(PatchScript s) {
AccountDiffPreference dp = new AccountDiffPreference(s.getDiffPrefs()); DiffPreferencesInfo dp = s.getDiffPrefs();
dp.setShowWhitespaceErrors(false); dp.showWhitespaceErrors = false;
PrettyFormatter f = ClientSideFormatter.FACTORY.get(); PrettyFormatter f = ClientSideFormatter.FACTORY.get();
f.setDiffPrefs(dp); f.setDiffPrefs(dp);
@ -299,7 +299,7 @@ abstract class AbstractPatchContentTable extends NavigationTable<Object>
} }
protected SparseHtmlFile getSparseHtmlFileB(PatchScript s) { protected SparseHtmlFile getSparseHtmlFileB(PatchScript s) {
AccountDiffPreference dp = new AccountDiffPreference(s.getDiffPrefs()); DiffPreferencesInfo dp = s.getDiffPrefs();
SparseFileContent b = s.getB(); SparseFileContent b = s.getB();
PrettyFormatter f = ClientSideFormatter.FACTORY.get(); PrettyFormatter f = ClientSideFormatter.FACTORY.get();

View File

@ -20,8 +20,8 @@ import com.google.gerrit.client.account.Util;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.ListenableAccountDiffPreference; import com.google.gerrit.client.ui.ListenableAccountDiffPreference;
import com.google.gerrit.client.ui.NpIntTextBox; import com.google.gerrit.client.ui.NpIntTextBox;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.extensions.client.DiffPreferencesInfo.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.NodeList;
import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.OptionElement;
@ -156,7 +156,7 @@ public class PatchScriptSettingsPanel extends Composite {
public void setEnableSmallFileFeatures(final boolean on) { public void setEnableSmallFileFeatures(final boolean on) {
enableSmallFileFeatures = on; enableSmallFileFeatures = on;
if (enableSmallFileFeatures) { if (enableSmallFileFeatures) {
syntaxHighlighting.setValue(getValue().isSyntaxHighlighting()); syntaxHighlighting.setValue(getValue().syntaxHighlighting);
} else { } else {
syntaxHighlighting.setValue(false); syntaxHighlighting.setValue(false);
} }
@ -181,7 +181,7 @@ public class PatchScriptSettingsPanel extends Composite {
public void setEnableIntralineDifference(final boolean on) { public void setEnableIntralineDifference(final boolean on) {
enableIntralineDifference = on; enableIntralineDifference = on;
if (enableIntralineDifference) { if (enableIntralineDifference) {
intralineDifference.setValue(getValue().isIntralineDifference()); intralineDifference.setValue(getValue().intralineDifference);
} else { } else {
intralineDifference.setValue(false); intralineDifference.setValue(false);
} }
@ -197,36 +197,36 @@ public class PatchScriptSettingsPanel extends Composite {
syntaxHighlighting.setTitle(title); syntaxHighlighting.setTitle(title);
} }
public AccountDiffPreference getValue() { public DiffPreferencesInfo getValue() {
return listenablePrefs.get(); return listenablePrefs.get();
} }
public void setValue(final AccountDiffPreference dp) { public void setValue(final DiffPreferencesInfo dp) {
listenablePrefs.set(dp); listenablePrefs.set(dp);
display(); display();
} }
protected void display() { protected void display() {
final AccountDiffPreference dp = getValue(); final DiffPreferencesInfo dp = getValue();
setIgnoreWhitespace(dp.getIgnoreWhitespace()); setIgnoreWhitespace(dp.ignoreWhitespace);
if (enableSmallFileFeatures) { if (enableSmallFileFeatures) {
syntaxHighlighting.setValue(dp.isSyntaxHighlighting()); syntaxHighlighting.setValue(dp.syntaxHighlighting);
} else { } else {
syntaxHighlighting.setValue(false); syntaxHighlighting.setValue(false);
} }
setContext(dp.getContext()); setContext(dp.context);
tabWidth.setIntValue(dp.getTabSize()); tabWidth.setIntValue(dp.tabSize);
colWidth.setIntValue(dp.getLineLength()); colWidth.setIntValue(dp.lineLength);
intralineDifference.setValue(dp.isIntralineDifference()); intralineDifference.setValue(dp.intralineDifference);
whitespaceErrors.setValue(dp.isShowWhitespaceErrors()); whitespaceErrors.setValue(dp.showWhitespaceErrors);
showLineEndings.setValue(dp.isShowLineEndings()); showLineEndings.setValue(dp.showLineEndings);
showTabs.setValue(dp.isShowTabs()); showTabs.setValue(dp.showTabs);
skipDeleted.setValue(dp.isSkipDeleted()); skipDeleted.setValue(dp.skipDeleted);
skipUncommented.setValue(dp.isSkipUncommented()); skipUncommented.setValue(dp.skipUncommented);
expandAllComments.setValue(dp.isExpandAllComments()); expandAllComments.setValue(dp.expandAllComments);
retainHeader.setValue(dp.isRetainHeader()); retainHeader.setValue(dp.retainHeader);
manualReview.setValue(dp.isManualReview()); manualReview.setValue(dp.manualReview);
} }
@UiHandler("update") @UiHandler("update")
@ -244,22 +244,21 @@ public class PatchScriptSettingsPanel extends Composite {
new ErrorDialog(PatchUtil.C.illegalNumberOfColumns()).center(); new ErrorDialog(PatchUtil.C.illegalNumberOfColumns()).center();
return; return;
} }
DiffPreferencesInfo dp = getValue();
AccountDiffPreference dp = new AccountDiffPreference(getValue()); dp.ignoreWhitespace = getIgnoreWhitespace();
dp.setIgnoreWhitespace(getIgnoreWhitespace()); dp.context = getContext();
dp.setContext(getContext()); dp.tabSize = tabWidth.getIntValue();
dp.setTabSize(tabWidth.getIntValue()); dp.lineLength = colWidth.getIntValue();
dp.setLineLength(colWidth.getIntValue()); dp.syntaxHighlighting = syntaxHighlighting.getValue();
dp.setSyntaxHighlighting(syntaxHighlighting.getValue()); dp.intralineDifference = intralineDifference.getValue();
dp.setIntralineDifference(intralineDifference.getValue()); dp.showWhitespaceErrors = whitespaceErrors.getValue();
dp.setShowWhitespaceErrors(whitespaceErrors.getValue()); dp.showLineEndings = showLineEndings.getValue();
dp.setShowLineEndings(showLineEndings.getValue()); dp.showTabs = showTabs.getValue();
dp.setShowTabs(showTabs.getValue()); dp.skipDeleted = skipDeleted.getValue();
dp.setSkipDeleted(skipDeleted.getValue()); dp.skipUncommented = skipUncommented.getValue();
dp.setSkipUncommented(skipUncommented.getValue()); dp.expandAllComments = expandAllComments.getValue();
dp.setExpandAllComments(expandAllComments.getValue()); dp.retainHeader = retainHeader.getValue();
dp.setRetainHeader(retainHeader.getValue()); dp.manualReview = manualReview.getValue();
dp.setManualReview(manualReview.getValue());
listenablePrefs.set(dp); listenablePrefs.set(dp);
} }
@ -298,9 +297,9 @@ public class PatchScriptSettingsPanel extends Composite {
} }
private void initContext(ListBox context) { private void initContext(ListBox context) {
for (final short v : AccountDiffPreference.CONTEXT_CHOICES) { for (final short v : DiffPreferencesInfo.CONTEXT_CHOICES) {
final String label; final String label;
if (v == AccountDiffPreference.WHOLE_FILE_CONTEXT) { if (v == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
label = Util.C.contextWholeFile(); label = Util.C.contextWholeFile();
} else { } else {
label = Util.M.lines(v); label = Util.M.lines(v);
@ -314,7 +313,7 @@ public class PatchScriptSettingsPanel extends Composite {
if (0 <= sel) { if (0 <= sel) {
return Whitespace.valueOf(ignoreWhitespace.getValue(sel)); return Whitespace.valueOf(ignoreWhitespace.getValue(sel));
} }
return getValue().getIgnoreWhitespace(); return getValue().ignoreWhitespace;
} }
private void setIgnoreWhitespace(Whitespace s) { private void setIgnoreWhitespace(Whitespace s) {
@ -327,12 +326,12 @@ public class PatchScriptSettingsPanel extends Composite {
ignoreWhitespace.setSelectedIndex(0); ignoreWhitespace.setSelectedIndex(0);
} }
private short getContext() { private int getContext() {
final int sel = context.getSelectedIndex(); final int sel = context.getSelectedIndex();
if (0 <= sel) { if (0 <= sel) {
return Short.parseShort(context.getValue(sel)); return Short.parseShort(context.getValue(sel));
} }
return getValue().getContext(); return getValue().context;
} }
private void setContext(int ctx) { private void setContext(int ctx) {

View File

@ -65,9 +65,9 @@ class PatchTable extends Composite {
new PatchValidator() { new PatchValidator() {
@Override @Override
public boolean isValid(Patch patch) { public boolean isValid(Patch patch) {
return !((listenablePrefs.get().isSkipDeleted() return !((listenablePrefs.get().skipDeleted
&& patch.getChangeType().equals(ChangeType.DELETED)) && patch.getChangeType().equals(ChangeType.DELETED))
|| (listenablePrefs.get().isSkipUncommented() || (listenablePrefs.get().skipUncommented
&& patch.getCommentCount() == 0)); && patch.getCommentCount() == 0));
} }

View File

@ -294,7 +294,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
private void appendImageDifferences(final PatchScript script, private void appendImageDifferences(final PatchScript script,
final SafeHtmlBuilder nc) { final SafeHtmlBuilder nc) {
final boolean syntaxHighlighting = final boolean syntaxHighlighting =
script.getDiffPrefs().isSyntaxHighlighting(); script.getDiffPrefs().syntaxHighlighting;
if (script.getDisplayMethodA() == DisplayMethod.IMG) { if (script.getDisplayMethodA() == DisplayMethod.IMG) {
final String url = getUrlA(); final String url = getUrlA();
appendImageLine(nc, url, syntaxHighlighting, false); appendImageLine(nc, url, syntaxHighlighting, false);
@ -310,7 +310,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
final SparseHtmlFile a = getSparseHtmlFileA(script); final SparseHtmlFile a = getSparseHtmlFileA(script);
final SparseHtmlFile b = getSparseHtmlFileB(script); final SparseHtmlFile b = getSparseHtmlFileB(script);
final boolean syntaxHighlighting = final boolean syntaxHighlighting =
script.getDiffPrefs().isSyntaxHighlighting(); script.getDiffPrefs().syntaxHighlighting;
for (final EditList.Hunk hunk : script.getHunks()) { for (final EditList.Hunk hunk : script.getHunks()) {
appendHunkHeader(nc, hunk); appendHunkHeader(nc, hunk);
while (hunk.next()) { while (hunk.next()) {

View File

@ -31,9 +31,9 @@ import com.google.gerrit.client.ui.ListenableAccountDiffPreference;
import com.google.gerrit.client.ui.Screen; import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.client.ClientSideFormatter;
import com.google.gerrit.prettify.client.PrettyFactory; import com.google.gerrit.prettify.client.PrettyFactory;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler;
@ -125,10 +125,10 @@ public class UnifiedPatchScreen extends Screen implements
lastScript = null; lastScript = null;
} }
private void update(AccountDiffPreference dp) { private void update(DiffPreferencesInfo dp) {
// Did the user just turn on auto-review? // Did the user just turn on auto-review?
if (!reviewedPanels.getValue() && prefs.getOld().isManualReview() if (!reviewedPanels.getValue() && prefs.getOld().manualReview
&& !dp.isManualReview()) { && !dp.manualReview) {
reviewedPanels.setValue(true); reviewedPanels.setValue(true);
reviewedPanels.setReviewedByCurrentUser(true); reviewedPanels.setReviewedByCurrentUser(true);
} }
@ -152,25 +152,25 @@ public class UnifiedPatchScreen extends Screen implements
} }
} }
private boolean canReuse(AccountDiffPreference dp, PatchScript last) { private boolean canReuse(DiffPreferencesInfo dp, PatchScript last) {
if (last.getDiffPrefs().getIgnoreWhitespace() != dp.getIgnoreWhitespace()) { if (last.getDiffPrefs().ignoreWhitespace != dp.ignoreWhitespace) {
// Whitespace ignore setting requires server computation. // Whitespace ignore setting requires server computation.
return false; return false;
} }
final int ctx = dp.getContext(); final int ctx = dp.context;
if (ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT && !last.getA().isWholeFile()) { if (ctx == DiffPreferencesInfo.WHOLE_FILE_CONTEXT
&& !last.getA().isWholeFile()) {
// We don't have the entire file here, so we can't render it. // We don't have the entire file here, so we can't render it.
return false; return false;
} }
if (last.getDiffPrefs().getContext() < ctx && !last.getA().isWholeFile()) { if (last.getDiffPrefs().context < ctx && !last.getA().isWholeFile()) {
// We don't have sufficient context. // We don't have sufficient context.
return false; return false;
} }
if (dp.isSyntaxHighlighting() if (dp.syntaxHighlighting && !last.getA().isWholeFile()) {
&& !last.getA().isWholeFile()) {
// We need the whole file to syntax highlight accurately. // We need the whole file to syntax highlight accurately.
return false; return false;
} }
@ -425,15 +425,15 @@ public class UnifiedPatchScreen extends Screen implements
} }
if (script.isHugeFile()) { if (script.isHugeFile()) {
AccountDiffPreference dp = script.getDiffPrefs(); DiffPreferencesInfo dp = script.getDiffPrefs();
int context = dp.getContext(); int context = dp.context;
if (context == AccountDiffPreference.WHOLE_FILE_CONTEXT) { if (context == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
context = Short.MAX_VALUE; context = Short.MAX_VALUE;
} else if (context > Short.MAX_VALUE) { } else if (context > Short.MAX_VALUE) {
context = Short.MAX_VALUE; context = Short.MAX_VALUE;
} }
dp.setContext((short) Math.min(context, LARGE_FILE_CONTEXT)); dp.context = Math.min(context, LARGE_FILE_CONTEXT);
dp.setSyntaxHighlighting(false); dp.syntaxHighlighting = false;
script.setDiffPrefs(dp); script.setDiffPrefs(dp);
} }
@ -453,7 +453,7 @@ public class UnifiedPatchScreen extends Screen implements
if (Gerrit.isSignedIn()) { if (Gerrit.isSignedIn()) {
boolean isReviewed = false; boolean isReviewed = false;
if (isFirst && !prefs.get().isManualReview()) { if (isFirst && !prefs.get().manualReview) {
isReviewed = true; isReviewed = true;
reviewedPanels.setReviewedByCurrentUser(isReviewed); reviewedPanels.setReviewedByCurrentUser(isReviewed);
} else { } else {
@ -476,9 +476,9 @@ public class UnifiedPatchScreen extends Screen implements
super.onShowView(); super.onShowView();
if (prefsHandler == null) { if (prefsHandler == null) {
prefsHandler = prefs.addValueChangeHandler( prefsHandler = prefs.addValueChangeHandler(
new ValueChangeHandler<AccountDiffPreference>() { new ValueChangeHandler<DiffPreferencesInfo>() {
@Override @Override
public void onValueChange(ValueChangeEvent<AccountDiffPreference> event) { public void onValueChange(ValueChangeEvent<DiffPreferencesInfo> event) {
update(event.getValue()); update(event.getValue());
} }
}); });
@ -491,7 +491,7 @@ public class UnifiedPatchScreen extends Screen implements
new ErrorDialog(PatchUtil.C.intralineTimeout()).setText( new ErrorDialog(PatchUtil.C.intralineTimeout()).setText(
Gerrit.C.warnTitle()).show(); Gerrit.C.warnTitle()).show();
} }
if (topView != null && prefs.get().isRetainHeader()) { if (topView != null && prefs.get().retainHeader) {
setTopView(topView); setTopView(topView);
} }
} }

View File

@ -17,11 +17,11 @@ package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.account.Util; import com.google.gerrit.client.account.Util;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gwtjsonrpc.common.VoidResult; import com.google.gwtjsonrpc.common.VoidResult;
public class ListenableAccountDiffPreference public class ListenableAccountDiffPreference
extends ListenableOldValue<AccountDiffPreference> { extends ListenableOldValue<DiffPreferencesInfo> {
public ListenableAccountDiffPreference() { public ListenableAccountDiffPreference() {
reset(); reset();
@ -33,7 +33,7 @@ public class ListenableAccountDiffPreference
new GerritCallback<VoidResult>() { new GerritCallback<VoidResult>() {
@Override @Override
public void onSuccess(VoidResult result) { public void onSuccess(VoidResult result) {
Gerrit.setAccountDiffPreference(get()); Gerrit.setDiffPreferences(get());
cb.onSuccess(result); cb.onSuccess(result);
} }
@ -46,10 +46,10 @@ public class ListenableAccountDiffPreference
} }
public void reset() { public void reset() {
if (Gerrit.isSignedIn() && Gerrit.getAccountDiffPreference() != null) { if (Gerrit.isSignedIn() && Gerrit.getDiffPreferences() != null) {
set(Gerrit.getAccountDiffPreference()); set(Gerrit.getDiffPreferences());
} else { } else {
set(AccountDiffPreference.createDefault(null)); set(DiffPreferencesInfo.defaults());
} }
} }
} }

View File

@ -24,13 +24,18 @@ import com.google.common.hash.Hashing;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import com.google.gerrit.common.Version; import com.google.gerrit.common.Version;
import com.google.gerrit.common.data.HostPageData; import com.google.gerrit.common.data.HostPageData;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.systemstatus.MessageOfTheDay; import com.google.gerrit.extensions.systemstatus.MessageOfTheDay;
import com.google.gerrit.extensions.webui.WebUiPlugin; import com.google.gerrit.extensions.webui.WebUiPlugin;
import com.google.gerrit.httpd.HtmlDomUtil; import com.google.gerrit.httpd.HtmlDomUtil;
import com.google.gerrit.httpd.WebSession; import com.google.gerrit.httpd.WebSession;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.GetDiffPreferences;
import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.config.SitePaths;
@ -38,10 +43,12 @@ import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gwtexpui.server.CacheHeaders; import com.google.gwtexpui.server.CacheHeaders;
import com.google.gwtjsonrpc.server.JsonServlet; import com.google.gwtjsonrpc.server.JsonServlet;
import com.google.gwtjsonrpc.server.RPCServletUtils; import com.google.gwtjsonrpc.server.RPCServletUtils;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -87,6 +94,7 @@ public class HostPageServlet extends HttpServlet {
private final StaticServlet staticServlet; private final StaticServlet staticServlet;
private final boolean isNoteDbEnabled; private final boolean isNoteDbEnabled;
private final Integer pluginsLoadTimeout; private final Integer pluginsLoadTimeout;
private final GetDiffPreferences getDiff;
private volatile Page page; private volatile Page page;
@Inject @Inject
@ -100,7 +108,8 @@ public class HostPageServlet extends HttpServlet {
DynamicSet<MessageOfTheDay> motd, DynamicSet<MessageOfTheDay> motd,
@GerritServerConfig Config cfg, @GerritServerConfig Config cfg,
StaticServlet ss, StaticServlet ss,
NotesMigration migration) NotesMigration migration,
GetDiffPreferences diffPref)
throws IOException, ServletException { throws IOException, ServletException {
currentUser = cu; currentUser = cu;
session = w; session = w;
@ -113,6 +122,7 @@ public class HostPageServlet extends HttpServlet {
staticServlet = ss; staticServlet = ss;
isNoteDbEnabled = migration.enabled(); isNoteDbEnabled = migration.enabled();
pluginsLoadTimeout = getPluginsLoadTimeout(cfg); pluginsLoadTimeout = getPluginsLoadTimeout(cfg);
getDiff = diffPref;
final String pageName = "HostPage.html"; final String pageName = "HostPage.html";
template = HtmlDomUtil.parseFile(getClass(), pageName); template = HtmlDomUtil.parseFile(getClass(), pageName);
@ -187,7 +197,7 @@ public class HostPageServlet extends HttpServlet {
w.write(";"); w.write(";");
w.write(HPD_ID + ".accountDiffPref="); w.write(HPD_ID + ".accountDiffPref=");
json(user.asIdentifiedUser().getAccountDiffPreference(), w); json(getDiffPreferences(user.asIdentifiedUser()), w);
w.write(";"); w.write(";");
w.write(HPD_ID + ".theme="); w.write(HPD_ID + ".theme=");
@ -220,6 +230,16 @@ public class HostPageServlet extends HttpServlet {
} }
} }
private DiffPreferencesInfo getDiffPreferences(IdentifiedUser user) {
try {
return getDiff.apply(new AccountResource(user));
} catch (AuthException | OrmException | ConfigInvalidException
| IOException e) {
log.warn("Cannot query account diff preferences", e);
}
return DiffPreferencesInfo.defaults();
}
private void plugins(StringWriter w) { private void plugins(StringWriter w) {
List<String> urls = Lists.newArrayList(); List<String> urls = Lists.newArrayList();
for (WebUiPlugin u : plugins) { for (WebUiPlugin u : plugins) {

View File

@ -19,13 +19,17 @@ import com.google.gerrit.common.data.AccountService;
import com.google.gerrit.common.data.AgreementInfo; import com.google.gerrit.common.data.AgreementInfo;
import com.google.gerrit.common.errors.InvalidQueryException; import com.google.gerrit.common.errors.InvalidQueryException;
import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountProjectWatch; import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.SetDiffPreferences;
import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
@ -37,6 +41,9 @@ import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import org.eclipse.jgit.errors.ConfigInvalidException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -49,18 +56,21 @@ class AccountServiceImpl extends BaseServiceImplementation implements
private final ProjectControl.Factory projectControlFactory; private final ProjectControl.Factory projectControlFactory;
private final AgreementInfoFactory.Factory agreementInfoFactory; private final AgreementInfoFactory.Factory agreementInfoFactory;
private final ChangeQueryBuilder queryBuilder; private final ChangeQueryBuilder queryBuilder;
private final SetDiffPreferences setDiff;
@Inject @Inject
AccountServiceImpl(final Provider<ReviewDb> schema, AccountServiceImpl(final Provider<ReviewDb> schema,
final Provider<IdentifiedUser> identifiedUser, final Provider<IdentifiedUser> identifiedUser,
final ProjectControl.Factory projectControlFactory, final ProjectControl.Factory projectControlFactory,
final AgreementInfoFactory.Factory agreementInfoFactory, final AgreementInfoFactory.Factory agreementInfoFactory,
final ChangeQueryBuilder queryBuilder) { final ChangeQueryBuilder queryBuilder,
SetDiffPreferences setDiff) {
super(schema, identifiedUser); super(schema, identifiedUser);
this.currentUser = identifiedUser; this.currentUser = identifiedUser;
this.projectControlFactory = projectControlFactory; this.projectControlFactory = projectControlFactory;
this.agreementInfoFactory = agreementInfoFactory; this.agreementInfoFactory = agreementInfoFactory;
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;
this.setDiff = setDiff;
} }
@Override @Override
@ -74,17 +84,21 @@ class AccountServiceImpl extends BaseServiceImplementation implements
} }
@Override @Override
public void changeDiffPreferences(final AccountDiffPreference diffPref, public void changeDiffPreferences(final DiffPreferencesInfo diffPref,
AsyncCallback<VoidResult> callback) { AsyncCallback<VoidResult> callback) {
run(callback, new Action<VoidResult>(){ run(callback, new Action<VoidResult>(){
@Override @Override
public VoidResult run(ReviewDb db) throws OrmException { public VoidResult run(ReviewDb db) throws OrmException {
if (!diffPref.getAccountId().equals(getAccountId())) { if (!getUser().isIdentifiedUser()) {
throw new IllegalArgumentException("diffPref.getAccountId() " throw new IllegalArgumentException("Not authenticated");
+ diffPref.getAccountId() + " doesn't match" }
+ " the accountId of the signed in user " + getAccountId()); IdentifiedUser me = getUser().asIdentifiedUser();
try {
setDiff.apply(new AccountResource(me), diffPref);
} catch (AuthException | BadRequestException | ConfigInvalidException
| IOException e) {
throw new OrmException("Cannot save diff preferences", e);
} }
db.accountDiffPreferences().upsert(Collections.singleton(diffPref));
return VoidResult.INSTANCE; return VoidResult.INSTANCE;
} }
}); });

View File

@ -16,7 +16,7 @@ package com.google.gerrit.httpd.rpc.changedetail;
import com.google.gerrit.common.data.ChangeDetailService; import com.google.gerrit.common.data.ChangeDetailService;
import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.client.AccountDiffPreference; import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -38,7 +38,7 @@ class ChangeDetailServiceImpl implements ChangeDetailService {
@Override @Override
public void patchSetDetail2(PatchSet.Id baseId, PatchSet.Id id, public void patchSetDetail2(PatchSet.Id baseId, PatchSet.Id id,
AccountDiffPreference diffPrefs, AsyncCallback<PatchSetDetail> callback) { DiffPreferencesInfo diffPrefs, AsyncCallback<PatchSetDetail> callback) {
patchSetDetail.create(baseId, id, diffPrefs).to(callback); patchSetDetail.create(baseId, id, diffPrefs).to(callback);
} }
} }

View File

@ -18,11 +18,11 @@ import com.google.common.base.Optional;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.httpd.rpc.Handler; import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.Account; 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.client.AccountPatchReview; import com.google.gerrit.reviewdb.client.AccountPatchReview;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
@ -67,7 +67,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
PatchSetDetailFactory create( PatchSetDetailFactory create(
@Assisted("psIdBase") @Nullable PatchSet.Id psIdBase, @Assisted("psIdBase") @Nullable PatchSet.Id psIdBase,
@Assisted("psIdNew") PatchSet.Id psIdNew, @Assisted("psIdNew") PatchSet.Id psIdNew,
@Nullable AccountDiffPreference diffPrefs); @Nullable DiffPreferencesInfo diffPrefs);
} }
private final PatchSetInfoFactory infoFactory; private final PatchSetInfoFactory infoFactory;
@ -81,7 +81,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
private Project.NameKey project; private Project.NameKey project;
private final PatchSet.Id psIdBase; private final PatchSet.Id psIdBase;
private final PatchSet.Id psIdNew; private final PatchSet.Id psIdNew;
private final AccountDiffPreference diffPrefs; private final DiffPreferencesInfo diffPrefs;
private ObjectId oldId; private ObjectId oldId;
private ObjectId newId; private ObjectId newId;
@ -98,7 +98,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
ChangeEditUtil editUtil, ChangeEditUtil editUtil,
@Assisted("psIdBase") @Nullable final PatchSet.Id psIdBase, @Assisted("psIdBase") @Nullable final PatchSet.Id psIdBase,
@Assisted("psIdNew") final PatchSet.Id psIdNew, @Assisted("psIdNew") final PatchSet.Id psIdNew,
@Assisted @Nullable final AccountDiffPreference diffPrefs) { @Assisted @Nullable final DiffPreferencesInfo diffPrefs) {
this.infoFactory = psif; this.infoFactory = psif;
this.db = db; this.db = db;
this.patchListCache = patchListCache; this.patchListCache = patchListCache;
@ -145,7 +145,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
newId = toObjectId(psIdNew); newId = toObjectId(psIdNew);
} }
list = listFor(keyFor(diffPrefs.getIgnoreWhitespace())); list = listFor(keyFor(diffPrefs.ignoreWhitespace));
} else { // OK, means use base to compare } else { // OK, means use base to compare
list = patchListCache.get(control.getChange(), patchSet); list = patchListCache.get(control.getChange(), patchSet);
} }

View File

@ -17,9 +17,9 @@ package com.google.gerrit.httpd.rpc.patch;
import com.google.gerrit.common.data.PatchDetailService; import com.google.gerrit.common.data.PatchDetailService;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
import com.google.gerrit.httpd.rpc.Handler; import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
@ -48,7 +48,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
@Override @Override
public void patchScript(final Patch.Key patchKey, final PatchSet.Id psa, public void patchScript(final Patch.Key patchKey, final PatchSet.Id psa,
final PatchSet.Id psb, final AccountDiffPreference dp, final PatchSet.Id psb, final DiffPreferencesInfo dp,
final AsyncCallback<PatchScript> callback) { final AsyncCallback<PatchScript> callback) {
if (psb == null) { if (psb == null) {
callback.onFailure(new NoSuchEntityException()); callback.onFailure(new NoSuchEntityException());

View File

@ -15,6 +15,7 @@ gwt_module(
'//gerrit-gwtexpui:SafeHtml', '//gerrit-gwtexpui:SafeHtml',
], ],
exported_deps = [ exported_deps = [
'//gerrit-extension-api:client',
'//gerrit-patch-jgit:client', '//gerrit-patch-jgit:client',
'//gerrit-reviewdb:client', '//gerrit-reviewdb:client',
'//lib:gwtjsonrpc', '//lib:gwtjsonrpc',

View File

@ -14,8 +14,8 @@
package com.google.gerrit.prettify.client; package com.google.gerrit.prettify.client;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gwtexpui.safehtml.client.SafeHtml; import com.google.gwtexpui.safehtml.client.SafeHtml;
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder; import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
@ -73,7 +73,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
protected SparseFileContent content; protected SparseFileContent content;
protected EditFilter side; protected EditFilter side;
protected List<Edit> edits; protected List<Edit> edits;
protected AccountDiffPreference diffPrefs; protected DiffPreferencesInfo diffPrefs;
protected String fileName; protected String fileName;
protected Set<Integer> trailingEdits; protected Set<Integer> trailingEdits;
@ -110,7 +110,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
edits = all; edits = all;
} }
public void setDiffPrefs(AccountDiffPreference how) { public void setDiffPrefs(DiffPreferencesInfo how) {
diffPrefs = how; diffPrefs = how;
} }
@ -132,7 +132,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
String html = toHTML(src); String html = toHTML(src);
html = expandTabs(html); html = expandTabs(html);
if (diffPrefs.isSyntaxHighlighting() && getFileType() != null if (diffPrefs.syntaxHighlighting && getFileType() != null
&& src.isWholeFile()) { && src.isWholeFile()) {
// The prettify parsers don't like &#39; as an entity for the // The prettify parsers don't like &#39; as an entity for the
// single quote character. Replace them all out so we don't // single quote character. Replace them all out so we don't
@ -233,7 +233,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
cleanText(txt, pos, start); cleanText(txt, pos, start);
pos = txt.indexOf(';', start + 1) + 1; pos = txt.indexOf(';', start + 1) + 1;
if (diffPrefs.getLineLength() <= col) { if (diffPrefs.lineLength <= col) {
buf.append("<br />"); buf.append("<br />");
col = 0; col = 0;
} }
@ -247,14 +247,14 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
private void cleanText(String txt, int pos, int end) { private void cleanText(String txt, int pos, int end) {
while (pos < end) { while (pos < end) {
int free = diffPrefs.getLineLength() - col; int free = diffPrefs.lineLength - col;
if (free <= 0) { if (free <= 0) {
// The current line is full. Throw an explicit line break // The current line is full. Throw an explicit line break
// onto the end, and we'll continue on the next line. // onto the end, and we'll continue on the next line.
// //
buf.append("<br />"); buf.append("<br />");
col = 0; col = 0;
free = diffPrefs.getLineLength(); free = diffPrefs.lineLength;
} }
int n = Math.min(end - pos, free); int n = Math.min(end - pos, free);
@ -326,7 +326,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
private String toHTML(SparseFileContent src) { private String toHTML(SparseFileContent src) {
SafeHtml html; SafeHtml html;
if (diffPrefs.isIntralineDifference()) { if (diffPrefs.intralineDifference) {
html = colorLineEdits(src); html = colorLineEdits(src);
} else { } else {
SafeHtmlBuilder b = new SafeHtmlBuilder(); SafeHtmlBuilder b = new SafeHtmlBuilder();
@ -342,7 +342,7 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
html = html.replaceAll("\r([^\n])", r); html = html.replaceAll("\r([^\n])", r);
} }
if (diffPrefs.isShowWhitespaceErrors()) { if (diffPrefs.showWhitespaceErrors) {
// We need to do whitespace errors before showing tabs, because // We need to do whitespace errors before showing tabs, because
// these patterns rely on \t as a literal, before it expands. // these patterns rely on \t as a literal, before it expands.
// //
@ -350,12 +350,12 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
html = showTrailingWhitespace(html); html = showTrailingWhitespace(html);
} }
if (diffPrefs.isShowLineEndings()){ if (diffPrefs.showLineEndings){
html = showLineEndings(html); html = showLineEndings(html);
} }
if (diffPrefs.isShowTabs()) { if (diffPrefs.showTabs) {
String t = 1 < diffPrefs.getTabSize() ? "\t" : ""; String t = 1 < diffPrefs.tabSize ? "\t" : "";
html = html.replaceAll("\t", "<span class=\"vt\">\u00BB</span>" + t); html = html.replaceAll("\t", "<span class=\"vt\">\u00BB</span>" + t);
} }
@ -528,10 +528,10 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
private String expandTabs(String html) { private String expandTabs(String html) {
StringBuilder tmp = new StringBuilder(); StringBuilder tmp = new StringBuilder();
int i = 0; int i = 0;
if (diffPrefs.isShowTabs()) { if (diffPrefs.showTabs) {
i = 1; i = 1;
} }
for (; i < diffPrefs.getTabSize(); i++) { for (; i < diffPrefs.tabSize; i++) {
tmp.append("&nbsp;"); tmp.append("&nbsp;");
} }
return html.replaceAll("\t", tmp.toString()); return html.replaceAll("\t", tmp.toString());

View File

@ -16,6 +16,7 @@ package com.google.gerrit.reviewdb.client;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS; import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gwtorm.client.Column; import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.IntKey; import com.google.gwtorm.client.IntKey;
@ -51,7 +52,7 @@ import java.sql.Timestamp;
* notifications of updates on that change, or just book-marking it for faster * notifications of updates on that change, or just book-marking it for faster
* future reference. One record per starred change.</li> * future reference. One record per starred change.</li>
* *
* <li>{@link AccountDiffPreference}: user's preferences for rendering side-to-side * <li>{@link DiffPreferencesInfo}: user's preferences for rendering side-to-side
* and unified diff</li> * and unified diff</li>
* *
* </ul> * </ul>

View File

@ -17,8 +17,8 @@ package com.google.gerrit.rules;
import static com.google.gerrit.rules.StoredValue.create; import static com.google.gerrit.rules.StoredValue.create;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetInfo; import com.google.gerrit.reviewdb.client.PatchSetInfo;

View File

@ -21,7 +21,6 @@ import com.google.common.collect.Sets;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.AccountInfo; import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountProjectWatch; import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.StarredChange; import com.google.gerrit.reviewdb.client.StarredChange;
@ -110,14 +109,16 @@ public class IdentifiedUser extends CurrentUser {
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) { public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
return new IdentifiedUser(capabilityControlFactory, authConfig, realm, return new IdentifiedUser(capabilityControlFactory, authConfig, realm,
anonymousCowardName, canonicalUrl, accountCache, groupBackend, anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, Providers.of(remotePeer), null, id, null); disableReverseDnsLookup, Providers.of(remotePeer), null,
id, null);
} }
public CurrentUser runAs(SocketAddress remotePeer, Account.Id id, public CurrentUser runAs(SocketAddress remotePeer, Account.Id id,
@Nullable CurrentUser caller) { @Nullable CurrentUser caller) {
return new IdentifiedUser(capabilityControlFactory, authConfig, realm, return new IdentifiedUser(capabilityControlFactory, authConfig, realm,
anonymousCowardName, canonicalUrl, accountCache, groupBackend, anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, Providers.of(remotePeer), null, id, caller); disableReverseDnsLookup, Providers.of(remotePeer), null,
id, caller);
} }
} }
@ -151,7 +152,6 @@ public class IdentifiedUser extends CurrentUser {
final AccountCache accountCache, final AccountCache accountCache,
final GroupBackend groupBackend, final GroupBackend groupBackend,
@DisableReverseDnsLookup final Boolean disableReverseDnsLookup, @DisableReverseDnsLookup final Boolean disableReverseDnsLookup,
@RemotePeer final Provider<SocketAddress> remotePeerProvider, @RemotePeer final Provider<SocketAddress> remotePeerProvider,
final Provider<ReviewDb> dbProvider) { final Provider<ReviewDb> dbProvider) {
this.capabilityControlFactory = capabilityControlFactory; this.capabilityControlFactory = capabilityControlFactory;
@ -162,7 +162,6 @@ public class IdentifiedUser extends CurrentUser {
this.accountCache = accountCache; this.accountCache = accountCache;
this.groupBackend = groupBackend; this.groupBackend = groupBackend;
this.disableReverseDnsLookup = disableReverseDnsLookup; this.disableReverseDnsLookup = disableReverseDnsLookup;
this.remotePeerProvider = remotePeerProvider; this.remotePeerProvider = remotePeerProvider;
this.dbProvider = dbProvider; this.dbProvider = dbProvider;
} }
@ -170,13 +169,15 @@ public class IdentifiedUser extends CurrentUser {
public IdentifiedUser create(Account.Id id) { public IdentifiedUser create(Account.Id id) {
return new IdentifiedUser(capabilityControlFactory, authConfig, realm, return new IdentifiedUser(capabilityControlFactory, authConfig, realm,
anonymousCowardName, canonicalUrl, accountCache, groupBackend, anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, remotePeerProvider, dbProvider, id, null); disableReverseDnsLookup, remotePeerProvider, dbProvider,
id, null);
} }
public IdentifiedUser runAs(Account.Id id, CurrentUser caller) { public IdentifiedUser runAs(Account.Id id, CurrentUser caller) {
return new IdentifiedUser(capabilityControlFactory, authConfig, realm, return new IdentifiedUser(capabilityControlFactory, authConfig, realm,
anonymousCowardName, canonicalUrl, accountCache, groupBackend, anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, remotePeerProvider, dbProvider, id, caller); disableReverseDnsLookup, remotePeerProvider, dbProvider,
id, caller);
} }
} }
@ -274,20 +275,6 @@ public class IdentifiedUser extends CurrentUser {
return state().getAccount(); return state().getAccount();
} }
public AccountDiffPreference getAccountDiffPreference() {
AccountDiffPreference diffPref;
try {
diffPref = dbProvider.get().accountDiffPreferences().get(getAccountId());
if (diffPref == null) {
diffPref = AccountDiffPreference.createDefault(getAccountId());
}
} catch (OrmException e) {
log.warn("Cannot query account diff preferences", e);
diffPref = AccountDiffPreference.createDefault(getAccountId());
}
return diffPref;
}
public boolean hasEmailAddress(String email) { public boolean hasEmailAddress(String email) {
if (validEmails.contains(email)) { if (validEmails.contains(email)) {
return true; return true;

View File

@ -14,91 +14,140 @@
package com.google.gerrit.server.account; package com.google.gerrit.server.account;
import com.google.gerrit.extensions.client.Theme; import static com.google.gerrit.server.config.ConfigUtil.loadSection;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
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.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser; 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.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; 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;
@Singleton @Singleton
public class GetDiffPreferences implements RestReadView<AccountResource> { public class GetDiffPreferences implements RestReadView<AccountResource> {
private final Provider<CurrentUser> self; private final Provider<CurrentUser> self;
private final Provider<ReviewDb> db; private final Provider<ReviewDb> db;
private final Provider<AllUsersName> allUsersName;
private final GitRepositoryManager gitMgr;
private final boolean readFromGit;
@Inject @Inject
GetDiffPreferences(Provider<CurrentUser> self, Provider<ReviewDb> db) { GetDiffPreferences(Provider<CurrentUser> self,
Provider<ReviewDb> db,
@GerritServerConfig Config cfg,
Provider<AllUsersName> allUsersName,
GitRepositoryManager gitMgr) {
this.self = self; this.self = self;
this.db = db; this.db = db;
this.allUsersName = allUsersName;
this.gitMgr = gitMgr;
readFromGit = cfg.getBoolean("user", null, "readPrefsFromGit", false);
} }
@Override @Override
public DiffPreferencesInfo apply(AccountResource rsrc) public DiffPreferencesInfo apply(AccountResource rsrc)
throws AuthException, OrmException { throws AuthException, OrmException, ConfigInvalidException, IOException {
if (self.get() != rsrc.getUser() if (self.get() != rsrc.getUser()
&& !self.get().getCapabilities().canAdministrateServer()) { && !self.get().getCapabilities().canAdministrateServer()) {
throw new AuthException("restricted to administrator"); throw new AuthException("restricted to administrator");
} }
Account.Id userId = rsrc.getUser().getAccountId(); Account.Id userId = rsrc.getUser().getAccountId();
AccountDiffPreference a = db.get().accountDiffPreferences().get(userId); return readFromGit
if (a == null) { ? readFromGit(userId, gitMgr, allUsersName.get(), null)
a = new AccountDiffPreference(userId); : readFromDb(userId);
}
return DiffPreferencesInfo.parse(a);
} }
public static class DiffPreferencesInfo { static DiffPreferencesInfo readFromGit(Account.Id id,
static DiffPreferencesInfo parse(AccountDiffPreference p) { GitRepositoryManager gitMgr, AllUsersName allUsersName,
DiffPreferencesInfo info = new DiffPreferencesInfo(); DiffPreferencesInfo in)
info.context = p.getContext(); throws IOException, ConfigInvalidException, RepositoryNotFoundException {
info.expandAllComments = p.isExpandAllComments() ? true : null; try (Repository git = gitMgr.openRepository(allUsersName)) {
info.ignoreWhitespace = p.getIgnoreWhitespace(); VersionedAccountPreferences p =
info.intralineDifference = p.isIntralineDifference() ? true : null; VersionedAccountPreferences.forUser(id);
info.lineLength = p.getLineLength(); p.load(git);
info.manualReview = p.isManualReview() ? true : null; DiffPreferencesInfo prefs = new DiffPreferencesInfo();
info.retainHeader = p.isRetainHeader() ? true : null; loadSection(p.getConfig(), UserConfigSections.DIFF, null, prefs,
info.showLineEndings = p.isShowLineEndings() ? true : null; DiffPreferencesInfo.defaults(), in);
info.showTabs = p.isShowTabs() ? true : null; return prefs;
info.showWhitespaceErrors = p.isShowWhitespaceErrors() ? true : null; }
info.skipDeleted = p.isSkipDeleted() ? true : null; }
info.skipUncommented = p.isSkipUncommented() ? true : null;
info.hideTopMenu = p.isHideTopMenu() ? true : null; private DiffPreferencesInfo readFromDb(Account.Id id)
info.autoHideDiffTableHeader = p.isAutoHideDiffTableHeader() ? true : null; throws OrmException {
info.hideLineNumbers = p.isHideLineNumbers() ? true : null; AccountDiffPreference a = db.get().accountDiffPreferences().get(id);
info.syntaxHighlighting = p.isSyntaxHighlighting() ? true : null; return nullify(initFromDb(a));
info.tabSize = p.getTabSize(); }
info.renderEntireFile = p.isRenderEntireFile() ? true : null;
info.hideEmptyPane = p.isHideEmptyPane() ? true : null; static DiffPreferencesInfo initFromDb(AccountDiffPreference a) {
info.theme = p.getTheme(); DiffPreferencesInfo prefs = DiffPreferencesInfo.defaults();
return info; 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();
} }
public short context; return prefs;
public Boolean expandAllComments; }
public Whitespace ignoreWhitespace;
public Boolean intralineDifference; private static DiffPreferencesInfo nullify(DiffPreferencesInfo prefs) {
public int lineLength; prefs.expandAllComments = b(prefs.expandAllComments);
public Boolean manualReview; prefs.hideLineNumbers = b(prefs.hideLineNumbers);
public Boolean retainHeader; prefs.hideTopMenu = b(prefs.hideTopMenu);
public Boolean showLineEndings; prefs.intralineDifference = b(prefs.intralineDifference);
public Boolean showTabs; prefs.manualReview = b(prefs.manualReview);
public Boolean showWhitespaceErrors; prefs.renderEntireFile = b(prefs.renderEntireFile);
public Boolean skipDeleted; prefs.retainHeader = b(prefs.retainHeader);
public Boolean skipUncommented; prefs.showLineEndings = b(prefs.showLineEndings);
public Boolean syntaxHighlighting; prefs.showTabs = b(prefs.showTabs);
public Boolean hideTopMenu; prefs.showWhitespaceErrors = b(prefs.showWhitespaceErrors);
public Boolean autoHideDiffTableHeader; prefs.skipDeleted = b(prefs.skipDeleted);
public Boolean hideLineNumbers; prefs.skipUncommented = b(prefs.skipUncommented);
public Boolean renderEntireFile; prefs.syntaxHighlighting = b(prefs.syntaxHighlighting);
public Boolean hideEmptyPane; prefs.hideEmptyPane = b(prefs.hideEmptyPane);
public int tabSize; prefs.autoHideDiffTableHeader = b(prefs.autoHideDiffTableHeader);
public Theme theme; return prefs;
}
private static Boolean b(Boolean b) {
if (b == null) {
return null;
}
return b ? Boolean.TRUE : null;
} }
} }

View File

@ -14,144 +14,224 @@
package com.google.gerrit.server.account; package com.google.gerrit.server.account;
import com.google.gerrit.extensions.client.Theme; 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;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.restapi.AuthException; 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.extensions.restapi.RestModifyView;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
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.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.GetDiffPreferences.DiffPreferencesInfo; import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.account.SetDiffPreferences.Input; 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.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; 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; import java.util.Collections;
@Singleton @Singleton
public class SetDiffPreferences implements RestModifyView<AccountResource, Input> { public class SetDiffPreferences implements
static class Input { RestModifyView<AccountResource, DiffPreferencesInfo> {
Short context;
Boolean expandAllComments;
Whitespace ignoreWhitespace;
Boolean intralineDifference;
Integer lineLength;
Boolean manualReview;
Boolean retainHeader;
Boolean showLineEndings;
Boolean showTabs;
Boolean showWhitespaceErrors;
Boolean skipDeleted;
Boolean skipUncommented;
Boolean syntaxHighlighting;
Boolean hideTopMenu;
Boolean autoHideDiffTableHeader;
Boolean hideLineNumbers;
Boolean renderEntireFile;
Integer tabSize;
Theme theme;
Boolean hideEmptyPane;
}
private final Provider<CurrentUser> self; private final Provider<CurrentUser> self;
private final Provider<ReviewDb> db; private final Provider<ReviewDb> db;
private final Provider<MetaDataUpdate.User> metaDataUpdateFactory;
private final AllUsersName allUsersName;
private final GitRepositoryManager gitMgr;
private final boolean readFromGit;
@Inject @Inject
SetDiffPreferences(Provider<CurrentUser> self, Provider<ReviewDb> db) { SetDiffPreferences(Provider<CurrentUser> self,
Provider<ReviewDb> db,
@GerritServerConfig Config cfg,
Provider<MetaDataUpdate.User> metaDataUpdateFactory,
AllUsersName allUsersName,
GitRepositoryManager gitMgr) {
this.self = self; this.self = self;
this.db = db; this.db = db;
this.metaDataUpdateFactory = metaDataUpdateFactory;
this.allUsersName = allUsersName;
this.gitMgr = gitMgr;
readFromGit = cfg.getBoolean("user", null, "readPrefsFromGit", false);
} }
@Override @Override
public DiffPreferencesInfo apply(AccountResource rsrc, Input input) public DiffPreferencesInfo apply(AccountResource rsrc, DiffPreferencesInfo in)
throws AuthException, OrmException { throws AuthException, BadRequestException, ConfigInvalidException,
RepositoryNotFoundException, IOException, OrmException {
if (self.get() != rsrc.getUser() if (self.get() != rsrc.getUser()
&& !self.get().getCapabilities().canModifyAccount()) { && !self.get().getCapabilities().canModifyAccount()) {
throw new AuthException("restricted to members of Modify Accounts"); throw new AuthException("restricted to members of Modify Accounts");
} }
if (input == null) {
input = new Input(); if (in == null) {
throw new BadRequestException("input must be provided");
} }
Account.Id accountId = rsrc.getUser().getAccountId(); Account.Id userId = rsrc.getUser().getAccountId();
AccountDiffPreference p; 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;
}
db.get().accounts().beginTransaction(accountId); private void writeToDb(DiffPreferencesInfo in, Account.Id id)
throws OrmException {
db.get().accounts().beginTransaction(id);
try { try {
p = db.get().accountDiffPreferences().get(accountId); AccountDiffPreference p = db.get().accountDiffPreferences().get(id);
if (p == null) { p = initAccountDiffPreferences(p, in, id);
p = new AccountDiffPreference(accountId);
}
if (input.context != null) {
p.setContext(input.context);
}
if (input.ignoreWhitespace != null) {
p.setIgnoreWhitespace(input.ignoreWhitespace);
}
if (input.expandAllComments != null) {
p.setExpandAllComments(input.expandAllComments);
}
if (input.intralineDifference != null) {
p.setIntralineDifference(input.intralineDifference);
}
if (input.lineLength != null) {
p.setLineLength(input.lineLength);
}
if (input.manualReview != null) {
p.setManualReview(input.manualReview);
}
if (input.retainHeader != null) {
p.setRetainHeader(input.retainHeader);
}
if (input.showLineEndings != null) {
p.setShowLineEndings(input.showLineEndings);
}
if (input.showTabs != null) {
p.setShowTabs(input.showTabs);
}
if (input.showWhitespaceErrors != null) {
p.setShowWhitespaceErrors(input.showWhitespaceErrors);
}
if (input.skipDeleted != null) {
p.setSkipDeleted(input.skipDeleted);
}
if (input.skipUncommented != null) {
p.setSkipUncommented(input.skipUncommented);
}
if (input.syntaxHighlighting != null) {
p.setSyntaxHighlighting(input.syntaxHighlighting);
}
if (input.hideTopMenu != null) {
p.setHideTopMenu(input.hideTopMenu);
}
if (input.autoHideDiffTableHeader != null) {
p.setAutoHideDiffTableHeader(input.autoHideDiffTableHeader);
}
if (input.hideLineNumbers != null) {
p.setHideLineNumbers(input.hideLineNumbers);
}
if (input.renderEntireFile != null) {
p.setRenderEntireFile(input.renderEntireFile);
}
if (input.tabSize != null) {
p.setTabSize(input.tabSize);
}
if (input.theme != null) {
p.setTheme(input.theme);
}
if (input.hideEmptyPane != null) {
p.setHideEmptyPane(input.hideEmptyPane);
}
db.get().accountDiffPreferences().upsert(Collections.singleton(p)); db.get().accountDiffPreferences().upsert(Collections.singleton(p));
db.get().commit(); db.get().commit();
} finally { } finally {
db.get().rollback(); db.get().rollback();
} }
return DiffPreferencesInfo.parse(p); }
private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in,
Account.Id useId) throws RepositoryNotFoundException, IOException,
ConfigInvalidException {
MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName);
VersionedAccountPreferences prefs;
DiffPreferencesInfo out = new DiffPreferencesInfo();
try {
prefs = VersionedAccountPreferences.forUser(useId);
prefs.load(md);
storeSection(prefs.getConfig(), UserConfigSections.DIFF, null, in,
DiffPreferencesInfo.defaults());
prefs.commit(md);
loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out,
DiffPreferencesInfo.defaults(), null);
} finally {
md.close();
}
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;
} }
} }

View File

@ -16,8 +16,8 @@ package com.google.gerrit.server.change;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.common.FileInfo; import com.google.gerrit.extensions.common.FileInfo;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;

View File

@ -24,6 +24,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchScript.DisplayMethod; import com.google.gerrit.common.data.PatchScript.DisplayMethod;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.common.ChangeType; import com.google.gerrit.extensions.common.ChangeType;
import com.google.gerrit.extensions.common.DiffInfo; import com.google.gerrit.extensions.common.DiffInfo;
import com.google.gerrit.extensions.common.DiffInfo.ContentEntry; import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
@ -39,8 +40,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
@ -52,7 +51,6 @@ import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import org.eclipse.jgit.diff.Edit; import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.ReplaceEdit; import org.eclipse.jgit.diff.ReplaceEdit;
@ -69,6 +67,8 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
public class GetDiff implements RestReadView<FileResource> { public class GetDiff implements RestReadView<FileResource> {
private static final ImmutableMap<Patch.ChangeType, ChangeType> CHANGE_TYPE = private static final ImmutableMap<Patch.ChangeType, ChangeType> CHANGE_TYPE =
Maps.immutableEnumMap( Maps.immutableEnumMap(
@ -93,7 +93,7 @@ public class GetDiff implements RestReadView<FileResource> {
IgnoreWhitespace ignoreWhitespace = IgnoreWhitespace.NONE; IgnoreWhitespace ignoreWhitespace = IgnoreWhitespace.NONE;
@Option(name = "--context", handler = ContextOptionHandler.class) @Option(name = "--context", handler = ContextOptionHandler.class)
short context = AccountDiffPreference.DEFAULT_CONTEXT; int context = DiffPreferencesInfo.DEFAULT_CONTEXT;
@Option(name = "--intraline") @Option(name = "--intraline")
boolean intraline; boolean intraline;
@ -122,10 +122,10 @@ public class GetDiff implements RestReadView<FileResource> {
resource.getRevision().getChangeResource(), IdString.fromDecoded(base)); resource.getRevision().getChangeResource(), IdString.fromDecoded(base));
basePatchSet = baseResource.getPatchSet(); basePatchSet = baseResource.getPatchSet();
} }
AccountDiffPreference prefs = new AccountDiffPreference(new Account.Id(0)); DiffPreferencesInfo prefs = new DiffPreferencesInfo();
prefs.setIgnoreWhitespace(ignoreWhitespace.whitespace); prefs.ignoreWhitespace = ignoreWhitespace.whitespace;
prefs.setContext(context); prefs.context = context;
prefs.setIntralineDifference(intraline); prefs.intralineDifference = intraline;
try { try {
PatchScriptFactory psf = patchScriptFactoryFactory.create( PatchScriptFactory psf = patchScriptFactoryFactory.create(
@ -135,7 +135,7 @@ public class GetDiff implements RestReadView<FileResource> {
resource.getPatchKey().getParentKey(), resource.getPatchKey().getParentKey(),
prefs); prefs);
psf.setLoadHistory(false); psf.setLoadHistory(false);
psf.setLoadComments(context != AccountDiffPreference.WHOLE_FILE_CONTEXT); psf.setLoadComments(context != DiffPreferencesInfo.WHOLE_FILE_CONTEXT);
PatchScript ps = psf.call(); PatchScript ps = psf.call();
Content content = new Content(ps); Content content = new Content(ps);
for (Edit edit : ps.getEdits()) { for (Edit edit : ps.getEdits()) {
@ -369,14 +369,14 @@ public class GetDiff implements RestReadView<FileResource> {
} }
enum IgnoreWhitespace { enum IgnoreWhitespace {
NONE(AccountDiffPreference.Whitespace.IGNORE_NONE), NONE(DiffPreferencesInfo.Whitespace.IGNORE_NONE),
TRAILING(AccountDiffPreference.Whitespace.IGNORE_TRAILING), TRAILING(DiffPreferencesInfo.Whitespace.IGNORE_TRAILING),
CHANGED(AccountDiffPreference.Whitespace.IGNORE_LEADING_AND_TRAILING), CHANGED(DiffPreferencesInfo.Whitespace.IGNORE_LEADING_AND_TRAILING),
ALL(AccountDiffPreference.Whitespace.IGNORE_ALL); ALL(DiffPreferencesInfo.Whitespace.IGNORE_ALL);
private final AccountDiffPreference.Whitespace whitespace; private final DiffPreferencesInfo.Whitespace whitespace;
private IgnoreWhitespace(AccountDiffPreference.Whitespace whitespace) { private IgnoreWhitespace(DiffPreferencesInfo.Whitespace whitespace) {
this.whitespace = whitespace; this.whitespace = whitespace;
} }
} }
@ -393,7 +393,7 @@ public class GetDiff implements RestReadView<FileResource> {
final String value = params.getParameter(0); final String value = params.getParameter(0);
short context; short context;
if ("all".equalsIgnoreCase(value)) { if ("all".equalsIgnoreCase(value)) {
context = AccountDiffPreference.WHOLE_FILE_CONTEXT; context = DiffPreferencesInfo.WHOLE_FILE_CONTEXT;
} else { } else {
try { try {
context = Short.parseShort(value, 10); context = Short.parseShort(value, 10);

View File

@ -22,6 +22,9 @@ public class UserConfigSections {
/** The edit user preferences. */ /** The edit user preferences. */
public static final String EDIT = "edit"; public static final String EDIT = "edit";
/** The diff user preferences. */
public static final String DIFF = "diff";
private UserConfigSections() { private UserConfigSections() {
} }
} }

View File

@ -16,7 +16,7 @@
package com.google.gerrit.server.patch; package com.google.gerrit.server.patch;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;

View File

@ -14,15 +14,16 @@
package com.google.gerrit.server.patch; package com.google.gerrit.server.patch;
import static com.google.gerrit.server.ioutil.BasicSerialization.readEnum; import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeEnum;
import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull; import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@ -35,6 +36,16 @@ import java.io.Serializable;
public class PatchListKey implements Serializable { public class PatchListKey implements Serializable {
static final long serialVersionUID = 18L; static final long serialVersionUID = 18L;
public static final BiMap<Whitespace, Character> WHITESPACE_TYPES = ImmutableBiMap.of(
Whitespace.IGNORE_NONE, 'N',
Whitespace.IGNORE_TRAILING, 'E',
Whitespace.IGNORE_LEADING_AND_TRAILING, 'S',
Whitespace.IGNORE_ALL, 'A');
static {
checkState(WHITESPACE_TYPES.size() == Whitespace.values().length);
}
private transient ObjectId oldId; private transient ObjectId oldId;
private transient ObjectId newId; private transient ObjectId newId;
private transient Whitespace whitespace; private transient Whitespace whitespace;
@ -108,12 +119,20 @@ public class PatchListKey implements Serializable {
private void writeObject(final ObjectOutputStream out) throws IOException { private void writeObject(final ObjectOutputStream out) throws IOException {
writeCanBeNull(out, oldId); writeCanBeNull(out, oldId);
writeNotNull(out, newId); writeNotNull(out, newId);
writeEnum(out, whitespace); Character c = WHITESPACE_TYPES.get(whitespace);
if (c == null) {
throw new IOException("Invalid whitespace type: " + whitespace);
}
out.writeChar(c);
} }
private void readObject(final ObjectInputStream in) throws IOException { private void readObject(final ObjectInputStream in) throws IOException {
oldId = readCanBeNull(in); oldId = readCanBeNull(in);
newId = readNotNull(in); newId = readNotNull(in);
whitespace = readEnum(in, Whitespace.values()); char t = in.readChar();
whitespace = WHITESPACE_TYPES.inverse().get(t);
if (whitespace == null) {
throw new IOException("Invalid whitespace type code: " + t);
}
} }
} }

View File

@ -21,7 +21,7 @@ import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames; import com.google.gerrit.reviewdb.client.RefNames;

View File

@ -17,10 +17,10 @@ package com.google.gerrit.server.patch;
import com.google.gerrit.common.data.CommentDetail; import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchScript.DisplayMethod; import com.google.gerrit.common.data.PatchScript.DisplayMethod;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.prettify.common.EditList; import com.google.gerrit.prettify.common.EditList;
import com.google.gerrit.prettify.common.SparseFileContent; import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchLineComment;
@ -65,7 +65,7 @@ class PatchScriptBuilder {
private Project.NameKey projectKey; private Project.NameKey projectKey;
private ObjectReader reader; private ObjectReader reader;
private Change change; private Change change;
private AccountDiffPreference diffPrefs; private DiffPreferencesInfo diffPrefs;
private boolean againstParent; private boolean againstParent;
private ObjectId aId; private ObjectId aId;
private ObjectId bId; private ObjectId bId;
@ -95,11 +95,11 @@ class PatchScriptBuilder {
this.change = c; this.change = c;
} }
void setDiffPrefs(final AccountDiffPreference dp) { void setDiffPrefs(final DiffPreferencesInfo dp) {
diffPrefs = dp; diffPrefs = dp;
context = diffPrefs.getContext(); context = diffPrefs.context;
if (context == AccountDiffPreference.WHOLE_FILE_CONTEXT) { if (context == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
context = MAX_CONTEXT; context = MAX_CONTEXT;
} else if (context > MAX_CONTEXT) { } else if (context > MAX_CONTEXT) {
context = MAX_CONTEXT; context = MAX_CONTEXT;
@ -140,12 +140,12 @@ class PatchScriptBuilder {
if (!isModify(content)) { if (!isModify(content)) {
intralineDifferenceIsPossible = false; intralineDifferenceIsPossible = false;
} else if (diffPrefs.isIntralineDifference()) { } else if (diffPrefs.intralineDifference) {
IntraLineDiff d = IntraLineDiff d =
patchListCache.getIntraLineDiff( patchListCache.getIntraLineDiff(
new IntraLineDiffKey( new IntraLineDiffKey(
a.id, b.id, a.id, b.id,
diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE), diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE),
IntraLineDiffArgs.create( IntraLineDiffArgs.create(
a.src, b.src, edits, projectKey, bId, b.path)); a.src, b.src, edits, projectKey, bId, b.path));
if (d != null) { if (d != null) {
@ -208,7 +208,7 @@ class PatchScriptBuilder {
// //
context = MAX_CONTEXT; context = MAX_CONTEXT;
packContent(diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE); packContent(diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE);
} }
return new PatchScript(change.getKey(), content.getChangeType(), return new PatchScript(change.getKey(), content.getChangeType(),

View File

@ -18,10 +18,10 @@ import com.google.common.base.Optional;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.CommentDetail; import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.reviewdb.client.Account; 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.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType; import com.google.gerrit.reviewdb.client.Patch.ChangeType;
@ -66,7 +66,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
String fileName, String fileName,
@Assisted("patchSetA") PatchSet.Id patchSetA, @Assisted("patchSetA") PatchSet.Id patchSetA,
@Assisted("patchSetB") PatchSet.Id patchSetB, @Assisted("patchSetB") PatchSet.Id patchSetB,
AccountDiffPreference diffPrefs); DiffPreferencesInfo diffPrefs);
} }
private static final Logger log = private static final Logger log =
@ -83,7 +83,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
@Nullable @Nullable
private final PatchSet.Id psa; private final PatchSet.Id psa;
private final PatchSet.Id psb; private final PatchSet.Id psb;
private final AccountDiffPreference diffPrefs; private final DiffPreferencesInfo diffPrefs;
private final ChangeEditUtil editReader; private final ChangeEditUtil editReader;
private Optional<ChangeEdit> edit; private Optional<ChangeEdit> edit;
@ -110,7 +110,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
@Assisted final String fileName, @Assisted final String fileName,
@Assisted("patchSetA") @Nullable final PatchSet.Id patchSetA, @Assisted("patchSetA") @Nullable final PatchSet.Id patchSetA,
@Assisted("patchSetB") final PatchSet.Id patchSetB, @Assisted("patchSetB") final PatchSet.Id patchSetB,
@Assisted final AccountDiffPreference diffPrefs) { @Assisted DiffPreferencesInfo diffPrefs) {
this.repoManager = grm; this.repoManager = grm;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.patchListCache = patchListCache; this.patchListCache = patchListCache;
@ -156,7 +156,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
try (Repository git = repoManager.openRepository(project)) { try (Repository git = repoManager.openRepository(project)) {
try { try {
final PatchList list = listFor(keyFor(diffPrefs.getIgnoreWhitespace())); final PatchList list = listFor(keyFor(diffPrefs.ignoreWhitespace));
final PatchScriptBuilder b = newBuilder(list, git); final PatchScriptBuilder b = newBuilder(list, git);
final PatchListEntry content = list.get(fileName); final PatchListEntry content = list.get(fileName);
@ -192,11 +192,10 @@ public class PatchScriptFactory implements Callable<PatchScript> {
} }
private PatchScriptBuilder newBuilder(final PatchList list, Repository git) { private PatchScriptBuilder newBuilder(final PatchList list, Repository git) {
final AccountDiffPreference dp = new AccountDiffPreference(diffPrefs);
final PatchScriptBuilder b = builderFactory.get(); final PatchScriptBuilder b = builderFactory.get();
b.setRepository(git, project); b.setRepository(git, project);
b.setChange(change); b.setChange(change);
b.setDiffPrefs(dp); b.setDiffPrefs(diffPrefs);
b.setTrees(list.isAgainstParent(), list.getOldId(), list.getNewId()); b.setTrees(list.isAgainstParent(), list.getOldId(), list.getNewId());
return b; return b;
} }

View File

@ -19,6 +19,7 @@ import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GerritPersonIdent; import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.config.AllProjectsName; import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.AnonymousCowardName; import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
@ -76,6 +77,7 @@ public class SchemaUpdater {
for (Class<?> c : new Class<?>[] { for (Class<?> c : new Class<?>[] {
AllProjectsName.class, AllProjectsName.class,
AllUsersCreator.class, AllUsersCreator.class,
AllUsersName.class,
GitRepositoryManager.class, GitRepositoryManager.class,
SitePaths.class, SitePaths.class,
}) { }) {