diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 7ee2a7c4be..3461774226 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -5604,10 +5604,12 @@ Supported versions: [[receive.autogc]]receive.autogc:: + -By default, `git-receive-pack` will run auto gc after receiving data from git-push and updating refs. +By default, up to Gerrit 3.2 `git-receive-pack` will run auto gc after receiving data from git-push and updating refs. You can stop it by setting this variable to `false`. This is recommended in gerrit to avoid the additional load this creates. Instead schedule gc using link:cmd-gc.html#gc.startTime[gc.startTime] and link:cmd-gc.html#gc.interval[gc.interval] or e.g. in a cron job that runs gc in a separate process. +Since Gerrit 3.3 the init command will auto-configure `git-receive-pack = false` in `etc/jgit.config` if +it wasn't set manually and show a warning if it was set to `true` manually. GERRIT ------ diff --git a/java/com/google/gerrit/pgm/init/InitJGitConfig.java b/java/com/google/gerrit/pgm/init/InitJGitConfig.java new file mode 100644 index 0000000000..2fb03cc98d --- /dev/null +++ b/java/com/google/gerrit/pgm/init/InitJGitConfig.java @@ -0,0 +1,71 @@ +// Copyright (C) 2020 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.pgm.init; + +import static com.google.gerrit.pgm.init.api.InitUtil.die; + +import com.google.gerrit.pgm.init.api.ConsoleUI; +import com.google.gerrit.pgm.init.api.InitStep; +import com.google.gerrit.server.config.SitePaths; +import com.google.inject.Inject; +import com.google.inject.Singleton; +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.util.FS; + +/** Initialize the JGit configuration. */ +@Singleton +class InitJGitConfig implements InitStep { + private final ConsoleUI ui; + private final SitePaths sitePaths; + + @Inject + InitJGitConfig(ConsoleUI ui, SitePaths sitePaths) { + this.ui = ui; + this.sitePaths = sitePaths; + } + + @Override + public void run() { + ui.header("JGit Configuration"); + FileBasedConfig jgitConfig = new FileBasedConfig(sitePaths.jgit_config.toFile(), FS.DETECTED); + try { + jgitConfig.load(); + if (!jgitConfig + .getNames(ConfigConstants.CONFIG_RECEIVE_SECTION) + .contains(ConfigConstants.CONFIG_KEY_AUTOGC)) { + jgitConfig.setBoolean( + ConfigConstants.CONFIG_RECEIVE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOGC, false); + jgitConfig.save(); + ui.error( + "Auto-configured \"receive.autogc = false\" to disable auto-gc after git-receive-pack."); + } else if (jgitConfig.getBoolean( + ConfigConstants.CONFIG_RECEIVE_SECTION, ConfigConstants.CONFIG_KEY_AUTOGC, true)) { + ui.error( + "WARNING: JGit option \"receive.autogc = true\". This is not recommended in Gerrit.\n" + + "git-receive-pack will run auto gc after receiving data from " + + "git-push and updating refs.\n" + + "Disable this behavior to avoid the additional load it creates: " + + "gc should be configured in gc config section or run as a separate process."); + } + } catch (IOException e) { + throw die(String.format("Handling JGit configuration %s failed", sitePaths.jgit_config), e); + } catch (ConfigInvalidException e) { + throw die(String.format("Invalid JGit configuration %s", sitePaths.jgit_config), e); + } + } +} diff --git a/java/com/google/gerrit/pgm/init/InitModule.java b/java/com/google/gerrit/pgm/init/InitModule.java index b65867538b..32c66978fe 100644 --- a/java/com/google/gerrit/pgm/init/InitModule.java +++ b/java/com/google/gerrit/pgm/init/InitModule.java @@ -40,6 +40,7 @@ public class InitModule extends FactoryModule { // Steps are executed in the order listed here. // step().to(InitGitManager.class); + step().to(InitJGitConfig.class); step().to(InitLogging.class); step().to(InitIndex.class); step().to(InitAuth.class);