From 4f43759cdf4df22ea1033d68617dae6dfeca3894 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sun, 29 Nov 2020 16:49:18 +0100 Subject: [PATCH] Auto-enable git wire protocol v2 in jgit By JGit's default, git wire protocol version 2 is disabled. The attempt to activate it per default in JGit wasn't approved yet: [1],[2]. Given, that git wire protocol version 2 on server side is considered to be now very stable, activate it per default in init site program. Update JGit module to include the following change: 23389a632 Add constants for parsing git wire protocol version [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=563145 [2] https://git.eclipse.org/r/c/jgit/jgit/+/163216 Change-Id: I15da7c5e889bc222da08d473a4c41e349a2ee6a6 --- .../gerrit/pgm/init/InitJGitConfig.java | 31 +++++++++++++++++++ modules/jgit | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/java/com/google/gerrit/pgm/init/InitJGitConfig.java b/java/com/google/gerrit/pgm/init/InitJGitConfig.java index 2fb03cc98d..6e37f7f909 100644 --- a/java/com/google/gerrit/pgm/init/InitJGitConfig.java +++ b/java/com/google/gerrit/pgm/init/InitJGitConfig.java @@ -25,6 +25,7 @@ import java.io.IOException; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.transport.TransferConfig; import org.eclipse.jgit.util.FS; /** Initialize the JGit configuration. */ @@ -62,6 +63,36 @@ class InitJGitConfig implements InitStep { + "Disable this behavior to avoid the additional load it creates: " + "gc should be configured in gc config section or run as a separate process."); } + + if (!jgitConfig + .getNames(ConfigConstants.CONFIG_PROTOCOL_SECTION) + .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 = + jgitConfig.getString( + ConfigConstants.CONFIG_PROTOCOL_SECTION, null, ConfigConstants.CONFIG_KEY_VERSION); + if (!TransferConfig.ProtocolVersion.V2.version().equals(version)) { + ui.error( + String.format( + "HINT: JGit option \"%s.%s = %s\". It's recommended to activate git\n" + + "wire protocol version 2 to improve git fetch performance.", + ConfigConstants.CONFIG_PROTOCOL_SECTION, + ConfigConstants.CONFIG_KEY_VERSION, + version)); + } + } } catch (IOException e) { throw die(String.format("Handling JGit configuration %s failed", sitePaths.jgit_config), e); } catch (ConfigInvalidException e) { diff --git a/modules/jgit b/modules/jgit index 5cd485e5dd..23389a6323 160000 --- a/modules/jgit +++ b/modules/jgit @@ -1 +1 @@ -Subproject commit 5cd485e5dda41d2ef06226a692c64f1aa221eb25 +Subproject commit 23389a63238c50daf0d8d1e3fd2b1d29f4171645