Merge branch 'stable-2.7'
* stable-2.7: Work around MySQL refusing to be case sensitive Reference included plugins by absolute Urls Fix PatchScript's mapping of lines below the last edit Fix refreshing PatchScreen when fileList has not yet been loaded Fix login servlets when canonicalWebUrl is not set
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,11 +1,11 @@
|
|||||||
[submodule "plugins/replication"]
|
[submodule "plugins/replication"]
|
||||||
path = plugins/replication
|
path = plugins/replication
|
||||||
url = ../plugins/replication
|
url = https://gerrit.googlesource.com/plugins/replication
|
||||||
|
|
||||||
[submodule "plugins/reviewnotes"]
|
[submodule "plugins/reviewnotes"]
|
||||||
path = plugins/reviewnotes
|
path = plugins/reviewnotes
|
||||||
url = ../plugins/reviewnotes
|
url = https://gerrit.googlesource.com/plugins/reviewnotes
|
||||||
|
|
||||||
[submodule "plugins/commit-message-length-validator"]
|
[submodule "plugins/commit-message-length-validator"]
|
||||||
path = plugins/commit-message-length-validator
|
path = plugins/commit-message-length-validator
|
||||||
url = ../plugins/commit-message-length-validator
|
url = https://gerrit.googlesource.com/plugins/commit-message-length-validator
|
||||||
|
|||||||
@@ -169,7 +169,9 @@ public class PatchTable extends Composite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void movePointerTo(final Patch.Key k) {
|
public void movePointerTo(final Patch.Key k) {
|
||||||
myTable.movePointerTo(k);
|
if (myTable != null) {
|
||||||
|
myTable.movePointerTo(k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActive(boolean active) {
|
public void setActive(boolean active) {
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ public abstract class PatchScreen extends Screen implements
|
|||||||
lastScript = null;
|
lastScript = null;
|
||||||
settingsPanel.setEnabled(false);
|
settingsPanel.setEnabled(false);
|
||||||
reviewedPanels.populate(patchKey, fileList, patchIndex, getPatchScreenType());
|
reviewedPanels.populate(patchKey, fileList, patchIndex, getPatchScreenType());
|
||||||
if (isFirst && fileList != null) {
|
if (isFirst && fileList != null && fileList.isLoaded()) {
|
||||||
fileList.movePointerTo(patchKey);
|
fileList.movePointerTo(patchKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// 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.httpd;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
public class CanonicalWebUrl {
|
||||||
|
private final Provider<String> configured;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CanonicalWebUrl(
|
||||||
|
@com.google.gerrit.server.config.CanonicalWebUrl
|
||||||
|
@Nullable
|
||||||
|
Provider<String> provider) {
|
||||||
|
configured = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(HttpServletRequest req) {
|
||||||
|
String url = configured.get();
|
||||||
|
return url != null ? url : computeFromRequest(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String computeFromRequest(HttpServletRequest req) {
|
||||||
|
StringBuffer url = req.getRequestURL();
|
||||||
|
url.setLength(url.length() - req.getServletPath().length());
|
||||||
|
if (url.charAt(url.length() - 1) != '/') {
|
||||||
|
url.append('/');
|
||||||
|
}
|
||||||
|
return url.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd;
|
package com.google.gerrit.httpd;
|
||||||
|
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
|
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -26,7 +25,7 @@ import org.eclipse.jgit.lib.Config;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/** Sets {@link CanonicalWebUrl} to current HTTP request if not configured. */
|
/** Sets {@code CanonicalWebUrl} to current HTTP request if not configured. */
|
||||||
public class HttpCanonicalWebUrlProvider extends CanonicalWebUrlProvider {
|
public class HttpCanonicalWebUrlProvider extends CanonicalWebUrlProvider {
|
||||||
private Provider<HttpServletRequest> requestProvider;
|
private Provider<HttpServletRequest> requestProvider;
|
||||||
|
|
||||||
@@ -65,13 +64,7 @@ public class HttpCanonicalWebUrlProvider extends CanonicalWebUrlProvider {
|
|||||||
throw noWeb;
|
throw noWeb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return CanonicalWebUrl.computeFromRequest(req);
|
||||||
final StringBuffer url = req.getRequestURL();
|
|
||||||
url.setLength(url.length() - req.getServletPath().length());
|
|
||||||
if (url.charAt(url.length() - 1) != '/') {
|
|
||||||
url.append('/');
|
|
||||||
}
|
|
||||||
return url.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have no way of guessing our HTTP url.
|
// We have no way of guessing our HTTP url.
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
package com.google.gerrit.httpd.auth.container;
|
package com.google.gerrit.httpd.auth.container;
|
||||||
|
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
|
import com.google.gerrit.httpd.CanonicalWebUrl;
|
||||||
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.account.AccountException;
|
import com.google.gerrit.server.account.AccountException;
|
||||||
import com.google.gerrit.server.account.AccountManager;
|
import com.google.gerrit.server.account.AccountManager;
|
||||||
import com.google.gerrit.server.account.AuthRequest;
|
import com.google.gerrit.server.account.AuthRequest;
|
||||||
import com.google.gerrit.server.account.AuthResult;
|
import com.google.gerrit.server.account.AuthResult;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
|
||||||
import com.google.gwtexpui.server.CacheHeaders;
|
import com.google.gwtexpui.server.CacheHeaders;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
@@ -57,13 +57,13 @@ class HttpLoginServlet extends HttpServlet {
|
|||||||
LoggerFactory.getLogger(HttpLoginServlet.class);
|
LoggerFactory.getLogger(HttpLoginServlet.class);
|
||||||
|
|
||||||
private final Provider<WebSession> webSession;
|
private final Provider<WebSession> webSession;
|
||||||
private final Provider<String> urlProvider;
|
private final CanonicalWebUrl urlProvider;
|
||||||
private final AccountManager accountManager;
|
private final AccountManager accountManager;
|
||||||
private final HttpAuthFilter authFilter;
|
private final HttpAuthFilter authFilter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
HttpLoginServlet(final Provider<WebSession> webSession,
|
HttpLoginServlet(final Provider<WebSession> webSession,
|
||||||
@CanonicalWebUrl @Nullable final Provider<String> urlProvider,
|
final CanonicalWebUrl urlProvider,
|
||||||
final AccountManager accountManager,
|
final AccountManager accountManager,
|
||||||
final HttpAuthFilter authFilter) {
|
final HttpAuthFilter authFilter) {
|
||||||
this.webSession = webSession;
|
this.webSession = webSession;
|
||||||
@@ -121,7 +121,7 @@ class HttpLoginServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder rdr = new StringBuilder();
|
final StringBuilder rdr = new StringBuilder();
|
||||||
rdr.append(urlProvider.get());
|
rdr.append(urlProvider.get(req));
|
||||||
rdr.append('#');
|
rdr.append('#');
|
||||||
if (arsp.isNew() && !token.startsWith(PageLinks.REGISTER + "/")) {
|
if (arsp.isNew() && !token.startsWith(PageLinks.REGISTER + "/")) {
|
||||||
rdr.append(PageLinks.REGISTER);
|
rdr.append(PageLinks.REGISTER);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package com.google.gerrit.httpd.auth.ldap;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
|
import com.google.gerrit.httpd.CanonicalWebUrl;
|
||||||
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.httpd.template.SiteHeaderFooter;
|
import com.google.gerrit.httpd.template.SiteHeaderFooter;
|
||||||
@@ -26,7 +27,7 @@ import com.google.gerrit.server.account.AccountUserNameException;
|
|||||||
import com.google.gerrit.server.account.AuthRequest;
|
import com.google.gerrit.server.account.AuthRequest;
|
||||||
import com.google.gerrit.server.account.AuthResult;
|
import com.google.gerrit.server.account.AuthResult;
|
||||||
import com.google.gerrit.server.auth.AuthenticationUnavailableException;
|
import com.google.gerrit.server.auth.AuthenticationUnavailableException;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gwtexpui.server.CacheHeaders;
|
import com.google.gwtexpui.server.CacheHeaders;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
@@ -55,28 +56,24 @@ class LdapLoginServlet extends HttpServlet {
|
|||||||
|
|
||||||
private final AccountManager accountManager;
|
private final AccountManager accountManager;
|
||||||
private final Provider<WebSession> webSession;
|
private final Provider<WebSession> webSession;
|
||||||
private final Provider<String> urlProvider;
|
private final CanonicalWebUrl urlProvider;
|
||||||
private final SiteHeaderFooter headers;
|
private final SiteHeaderFooter headers;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LdapLoginServlet(AccountManager accountManager,
|
LdapLoginServlet(AccountManager accountManager,
|
||||||
Provider<WebSession> webSession,
|
Provider<WebSession> webSession,
|
||||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
CanonicalWebUrl urlProvider,
|
||||||
SiteHeaderFooter headers) {
|
SiteHeaderFooter headers) {
|
||||||
this.accountManager = accountManager;
|
this.accountManager = accountManager;
|
||||||
this.webSession = webSession;
|
this.webSession = webSession;
|
||||||
this.urlProvider = urlProvider;
|
this.urlProvider = urlProvider;
|
||||||
this.headers = headers;
|
this.headers = headers;
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(urlProvider.get())) {
|
|
||||||
log.error("gerrit.canonicalWebUrl must be set in gerrit.config");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendForm(HttpServletRequest req, HttpServletResponse res,
|
private void sendForm(HttpServletRequest req, HttpServletResponse res,
|
||||||
@Nullable String errorMessage) throws IOException {
|
@Nullable String errorMessage) throws IOException {
|
||||||
String self = req.getRequestURI();
|
String self = req.getRequestURI();
|
||||||
String cancel = Objects.firstNonNull(urlProvider.get(), "/");
|
String cancel = Objects.firstNonNull(urlProvider.get(req), "/");
|
||||||
String token = getToken(req);
|
String token = getToken(req);
|
||||||
if (!token.equals("/")) {
|
if (!token.equals("/")) {
|
||||||
cancel += "#" + token;
|
cancel += "#" + token;
|
||||||
@@ -146,11 +143,10 @@ class LdapLoginServlet extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String token = getToken(req);
|
|
||||||
StringBuilder dest = new StringBuilder();
|
StringBuilder dest = new StringBuilder();
|
||||||
dest.append(urlProvider.get());
|
dest.append(urlProvider.get(req));
|
||||||
dest.append('#');
|
dest.append('#');
|
||||||
dest.append(token);
|
dest.append(getToken(req));
|
||||||
|
|
||||||
CacheHeaders.setNotCacheable(res);
|
CacheHeaders.setNotCacheable(res);
|
||||||
webSession.get().login(ares, "1".equals(remember));
|
webSession.get().login(ares, "1".equals(remember));
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class LoginForm extends HttpServlet {
|
|||||||
remember = false;
|
remember = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoveryResult r = impl.discover(id, mode, remember, token);
|
DiscoveryResult r = impl.discover(req, id, mode, remember, token);
|
||||||
switch (r.status) {
|
switch (r.status) {
|
||||||
case VALID:
|
case VALID:
|
||||||
redirect(r, res);
|
redirect(r, res);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package com.google.gerrit.httpd.auth.openid;
|
|||||||
|
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.auth.openid.OpenIdUrls;
|
import com.google.gerrit.common.auth.openid.OpenIdUrls;
|
||||||
|
import com.google.gerrit.httpd.CanonicalWebUrl;
|
||||||
import com.google.gerrit.httpd.WebSession;
|
import com.google.gerrit.httpd.WebSession;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
@@ -24,7 +25,6 @@ import com.google.gerrit.server.account.AccountException;
|
|||||||
import com.google.gerrit.server.account.AccountManager;
|
import com.google.gerrit.server.account.AccountManager;
|
||||||
import com.google.gerrit.server.auth.openid.OpenIdProviderPattern;
|
import com.google.gerrit.server.auth.openid.OpenIdProviderPattern;
|
||||||
import com.google.gerrit.server.config.AuthConfig;
|
import com.google.gerrit.server.config.AuthConfig;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
|
||||||
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.gwtorm.client.KeyUtil;
|
import com.google.gwtorm.client.KeyUtil;
|
||||||
@@ -63,7 +63,6 @@ import java.net.URL;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -93,7 +92,7 @@ class OpenIdServiceImpl {
|
|||||||
|
|
||||||
private final Provider<WebSession> webSession;
|
private final Provider<WebSession> webSession;
|
||||||
private final Provider<IdentifiedUser> identifiedUser;
|
private final Provider<IdentifiedUser> identifiedUser;
|
||||||
private final Provider<String> urlProvider;
|
private final CanonicalWebUrl urlProvider;
|
||||||
private final AccountManager accountManager;
|
private final AccountManager accountManager;
|
||||||
private final ConsumerManager manager;
|
private final ConsumerManager manager;
|
||||||
private final List<OpenIdProviderPattern> allowedOpenIDs;
|
private final List<OpenIdProviderPattern> allowedOpenIDs;
|
||||||
@@ -105,7 +104,7 @@ class OpenIdServiceImpl {
|
|||||||
@Inject
|
@Inject
|
||||||
OpenIdServiceImpl(final Provider<WebSession> cf,
|
OpenIdServiceImpl(final Provider<WebSession> cf,
|
||||||
final Provider<IdentifiedUser> iu,
|
final Provider<IdentifiedUser> iu,
|
||||||
@CanonicalWebUrl @Nullable final Provider<String> up,
|
CanonicalWebUrl up,
|
||||||
@GerritServerConfig final Config config, final AuthConfig ac,
|
@GerritServerConfig final Config config, final AuthConfig ac,
|
||||||
final AccountManager am) throws ConsumerException, MalformedURLException {
|
final AccountManager am) throws ConsumerException, MalformedURLException {
|
||||||
|
|
||||||
@@ -145,10 +144,10 @@ class OpenIdServiceImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
DiscoveryResult discover(final String openidIdentifier, final SignInMode mode,
|
DiscoveryResult discover(HttpServletRequest req, String openidIdentifier,
|
||||||
final boolean remember, final String returnToken) {
|
final SignInMode mode, final boolean remember, final String returnToken) {
|
||||||
final State state;
|
final State state;
|
||||||
state = init(openidIdentifier, mode, remember, returnToken);
|
state = init(req, openidIdentifier, mode, remember, returnToken);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
return new DiscoveryResult(DiscoveryResult.Status.NO_PROVIDER);
|
return new DiscoveryResult(DiscoveryResult.Status.NO_PROVIDER);
|
||||||
}
|
}
|
||||||
@@ -235,7 +234,7 @@ class OpenIdServiceImpl {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = init(rediscoverIdentifier, mode, remember, returnToken);
|
state = init(req, rediscoverIdentifier, mode, remember, returnToken);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
// Re-discovery must have failed, we can't run a login.
|
// Re-discovery must have failed, we can't run a login.
|
||||||
//
|
//
|
||||||
@@ -482,7 +481,7 @@ class OpenIdServiceImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder rdr = new StringBuilder();
|
final StringBuilder rdr = new StringBuilder();
|
||||||
rdr.append(urlProvider.get());
|
rdr.append(urlProvider.get(req));
|
||||||
rdr.append('#');
|
rdr.append('#');
|
||||||
if (isNew && !token.startsWith(PageLinks.REGISTER + "/")) {
|
if (isNew && !token.startsWith(PageLinks.REGISTER + "/")) {
|
||||||
rdr.append(PageLinks.REGISTER);
|
rdr.append(PageLinks.REGISTER);
|
||||||
@@ -507,7 +506,7 @@ class OpenIdServiceImpl {
|
|||||||
webSession.get().logout();
|
webSession.get().logout();
|
||||||
}
|
}
|
||||||
final StringBuilder rdr = new StringBuilder();
|
final StringBuilder rdr = new StringBuilder();
|
||||||
rdr.append(urlProvider.get());
|
rdr.append(urlProvider.get(req));
|
||||||
rdr.append('#');
|
rdr.append('#');
|
||||||
rdr.append("SignInFailure");
|
rdr.append("SignInFailure");
|
||||||
rdr.append(',');
|
rdr.append(',');
|
||||||
@@ -517,8 +516,8 @@ class OpenIdServiceImpl {
|
|||||||
rsp.sendRedirect(rdr.toString());
|
rsp.sendRedirect(rdr.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private State init(final String openidIdentifier, final SignInMode mode,
|
private State init(HttpServletRequest req, final String openidIdentifier,
|
||||||
final boolean remember, final String returnToken) {
|
final SignInMode mode, final boolean remember, final String returnToken) {
|
||||||
final List<?> list;
|
final List<?> list;
|
||||||
try {
|
try {
|
||||||
list = manager.discover(openidIdentifier);
|
list = manager.discover(openidIdentifier);
|
||||||
@@ -530,7 +529,7 @@ class OpenIdServiceImpl {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String contextUrl = urlProvider.get();
|
final String contextUrl = urlProvider.get(req);
|
||||||
final DiscoveryInformation discovered = manager.associate(list);
|
final DiscoveryInformation discovered = manager.associate(list);
|
||||||
final UrlEncoded retTo = new UrlEncoded(contextUrl + RETURN_URL);
|
final UrlEncoded retTo = new UrlEncoded(contextUrl + RETURN_URL);
|
||||||
retTo.put(P_MODE, mode.name());
|
retTo.put(P_MODE, mode.name());
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server;
|
package com.google.gerrit.server;
|
||||||
|
|
||||||
import com.google.common.base.CharMatcher;
|
|
||||||
import com.google.gerrit.common.ChangeHooks;
|
import com.google.gerrit.common.ChangeHooks;
|
||||||
import com.google.gerrit.common.data.LabelTypes;
|
import com.google.gerrit.common.data.LabelTypes;
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
@@ -63,9 +62,7 @@ import org.eclipse.jgit.revwalk.FooterLine;
|
|||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||||
import org.eclipse.jgit.util.Base64;
|
|
||||||
import org.eclipse.jgit.util.ChangeIdUtil;
|
import org.eclipse.jgit.util.ChangeIdUtil;
|
||||||
import org.eclipse.jgit.util.NB;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -80,6 +77,8 @@ import java.util.Set;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
public class ChangeUtil {
|
public class ChangeUtil {
|
||||||
|
private static final Object uuidLock = new Object();
|
||||||
|
private static final int SEED = 0x2418e6f9;
|
||||||
private static int uuidPrefix;
|
private static int uuidPrefix;
|
||||||
private static int uuidSeq;
|
private static int uuidSeq;
|
||||||
|
|
||||||
@@ -91,25 +90,19 @@ public class ChangeUtil {
|
|||||||
* @return the new unique identifier.
|
* @return the new unique identifier.
|
||||||
* @throws OrmException the database couldn't be incremented.
|
* @throws OrmException the database couldn't be incremented.
|
||||||
*/
|
*/
|
||||||
public static String messageUUID(final ReviewDb db) throws OrmException {
|
public static String messageUUID(ReviewDb db) throws OrmException {
|
||||||
final byte[] raw = new byte[8];
|
int p, s;
|
||||||
fill(raw, db);
|
synchronized (uuidLock) {
|
||||||
|
if (uuidSeq == 0) {
|
||||||
// Make the resulting base64 string more URL friendly.
|
uuidPrefix = db.nextChangeMessageId();
|
||||||
return CharMatcher.is('A').trimLeadingFrom(
|
uuidSeq = Integer.MAX_VALUE;
|
||||||
CharMatcher.is('=').trimTrailingFrom(Base64.encodeBytes(raw)))
|
}
|
||||||
.replace('+', '.')
|
p = uuidPrefix;
|
||||||
.replace('/', '-');
|
s = uuidSeq--;
|
||||||
}
|
|
||||||
|
|
||||||
private static synchronized void fill(byte[] raw, ReviewDb db)
|
|
||||||
throws OrmException {
|
|
||||||
if (uuidSeq == 0) {
|
|
||||||
uuidPrefix = db.nextChangeMessageId();
|
|
||||||
uuidSeq = Integer.MAX_VALUE;
|
|
||||||
}
|
}
|
||||||
NB.encodeInt32(raw, 0, uuidPrefix);
|
String u = IdGenerator.format(IdGenerator.mix(SEED, p));
|
||||||
NB.encodeInt32(raw, 4, IdGenerator.mix(uuidPrefix, uuidSeq--));
|
String l = IdGenerator.format(IdGenerator.mix(p, s));
|
||||||
|
return u + '_' + l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void touch(final Change change, ReviewDb db)
|
public static void touch(final Change change, ReviewDb db)
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ class PatchScriptBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Edit last = edits.get(edits.size() - 1);
|
final Edit last = edits.get(edits.size() - 1);
|
||||||
return last.getBeginB() + (a - last.getEndA());
|
return last.getEndB() + (a - last.getEndA());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mapB2A(final int b) {
|
private int mapB2A(final int b) {
|
||||||
@@ -368,7 +368,7 @@ class PatchScriptBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Edit last = edits.get(edits.size() - 1);
|
final Edit last = edits.get(edits.size() - 1);
|
||||||
return last.getBeginA() + (b - last.getEndB());
|
return last.getEndA() + (b - last.getEndB());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void packContent(boolean ignoredWhitespace) {
|
private void packContent(boolean ignoredWhitespace) {
|
||||||
|
|||||||
Reference in New Issue
Block a user