InitJgitConfig: Git protocol v2 is enabled per default

Git wire protocol v2 is enabled in JGit per default, so there is no need
to enable it anymore in Gerrit init command. We still preserve the check
and issue a warning if protocol v2 was explicitly disabled.

Change-Id: If264e7fe2050094545d2d088ed6c1ff5b0cc0603
This commit is contained in:
David Ostrovsky
2021-01-04 09:26:52 +01:00
committed by David Ostrovsky
parent 8980a5ea81
commit dafac1cb80
3 changed files with 5 additions and 42 deletions

View File

@@ -5687,10 +5687,10 @@ and "never" suppresses expiration altogether.
[[protocol.version]]protocol.version:: [[protocol.version]]protocol.version::
+ +
If set, the server will accept requests from a client attempting to communicate If set, the server will accept requests from a client attempting to communicate
using the specified protocol version. Otherwise communication falls back to version 0. using the specified protocol version. Default is `2`. If set in file
If set in file `etc/jgit.config` this option will be used for all repositories of `etc/jgit.config` this option will be used for all repositories of the site.
the site. It can be overridden for a given repository by configuring a different It can be overridden for a given repository by configuring a different value in
value in the repository's `config` file. the repository's `config` file.
+ +
Supported versions: Supported versions:
0:: the original wire protocol. 0:: the original wire protocol.

View File

@@ -64,22 +64,9 @@ class InitJGitConfig implements InitStep {
+ "gc should be configured in gc config section or run as a separate process."); + "gc should be configured in gc config section or run as a separate process.");
} }
if (!jgitConfig if (jgitConfig
.getNames(ConfigConstants.CONFIG_PROTOCOL_SECTION) .getNames(ConfigConstants.CONFIG_PROTOCOL_SECTION)
.contains(ConfigConstants.CONFIG_KEY_VERSION)) { .contains(ConfigConstants.CONFIG_KEY_VERSION)) {
jgitConfig.setString(
ConfigConstants.CONFIG_PROTOCOL_SECTION,
null,
ConfigConstants.CONFIG_KEY_VERSION,
TransferConfig.ProtocolVersion.V2.version());
jgitConfig.save();
ui.error(
String.format(
"Auto-configured \"%s.%s = %s\" to activate git wire protocol version 2.",
ConfigConstants.CONFIG_PROTOCOL_SECTION,
ConfigConstants.CONFIG_KEY_VERSION,
TransferConfig.ProtocolVersion.V2.version()));
} else {
String version = String version =
jgitConfig.getString( jgitConfig.getString(
ConfigConstants.CONFIG_PROTOCOL_SECTION, null, ConfigConstants.CONFIG_KEY_VERSION); ConfigConstants.CONFIG_PROTOCOL_SECTION, null, ConfigConstants.CONFIG_KEY_VERSION);

View File

@@ -42,7 +42,6 @@ import com.google.inject.Inject;
import java.io.File; import java.io.File;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@@ -98,11 +97,6 @@ public class GitProtocolV2IT extends StandaloneSiteTest {
.group(SystemGroupBackend.REGISTERED_USERS)) .group(SystemGroupBackend.REGISTERED_USERS))
.update(); .update();
// Set protocol.version=2 in target repository
execute(
ImmutableList.of("git", "config", "protocol.version", "2"),
sitePaths.site_path.resolve("git").resolve(project.get() + Constants.DOT_GIT).toFile());
// Retrieve HTTP url // Retrieve HTTP url
String url = config.getString("gerrit", null, "canonicalweburl"); String url = config.getString("gerrit", null, "canonicalweburl");
String urlDestinationTemplate = String urlDestinationTemplate =
@@ -217,15 +211,6 @@ public class GitProtocolV2IT extends StandaloneSiteTest {
Project.NameKey allRefsVisibleProject = Project.nameKey("all-refs-visible"); Project.NameKey allRefsVisibleProject = Project.nameKey("all-refs-visible");
gApi.projects().create(allRefsVisibleProject.get()); gApi.projects().create(allRefsVisibleProject.get());
// Set protocol.version=2 in target repository
execute(
ImmutableList.of("git", "config", "protocol.version", "2"),
sitePaths
.site_path
.resolve("git")
.resolve(allRefsVisibleProject.get() + Constants.DOT_GIT)
.toFile());
// Set up project permission to allow reading all refs // Set up project permission to allow reading all refs
projectOperations projectOperations
.project(allRefsVisibleProject) .project(allRefsVisibleProject)
@@ -280,15 +265,6 @@ public class GitProtocolV2IT extends StandaloneSiteTest {
Project.NameKey privateProject = Project.nameKey("private-project"); Project.NameKey privateProject = Project.nameKey("private-project");
gApi.projects().create(privateProject.get()); gApi.projects().create(privateProject.get());
// Set protocol.version=2 in target repository
execute(
ImmutableList.of("git", "config", "protocol.version", "2"),
sitePaths
.site_path
.resolve("git")
.resolve(privateProject.get() + Constants.DOT_GIT)
.toFile());
// Disallow general read permissions for anonymous users // Disallow general read permissions for anonymous users
projectOperations projectOperations
.project(allProjectsName) .project(allProjectsName)