MCPcopy Create free account
hub / github.com/GerritCodeReview/gerrit / InitJGitConfig

Class InitJGitConfig

java/com/google/gerrit/pgm/init/InitJGitConfig.java:32–87  ·  view source on GitHub ↗

Initialize the JGit configuration.

Source from the content-addressed store, hash-verified

30
31/** Initialize the JGit configuration. */
32@Singleton
33class InitJGitConfig implements InitStep {
34 private final ConsoleUI ui;
35 private final SitePaths sitePaths;
36
37 @Inject
38 InitJGitConfig(ConsoleUI ui, SitePaths sitePaths) {
39 this.ui = ui;
40 this.sitePaths = sitePaths;
41 }
42
43 @Override
44 public void run() {
45 ui.header("JGit Configuration");
46 FileBasedConfig jgitConfig = new FileBasedConfig(sitePaths.jgit_config.toFile(), FS.DETECTED);
47 try {
48 jgitConfig.load();
49 if (!jgitConfig
50 .getNames(ConfigConstants.CONFIG_RECEIVE_SECTION)
51 .contains(ConfigConstants.CONFIG_KEY_AUTOGC)) {
52 jgitConfig.setBoolean(
53 ConfigConstants.CONFIG_RECEIVE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOGC, false);
54 jgitConfig.save();
55 ui.error(
56 "Auto-configured \"receive.autogc = false\" to disable auto-gc after"
57 + " git-receive-pack.");
58 } else if (jgitConfig.getBoolean(
59 ConfigConstants.CONFIG_RECEIVE_SECTION, ConfigConstants.CONFIG_KEY_AUTOGC, true)) {
60 ui.error(
61 "WARNING: JGit option \"receive.autogc = true\". This is not recommended in Gerrit.\n"
62 + "git-receive-pack will run auto gc after receiving data from "
63 + "git-push and updating refs.\n"
64 + "Disable this behavior to avoid the additional load it creates: "
65 + "gc should be configured in gc config section or run as a separate process.");
66 }
67
68 if (jgitConfig
69 .getNames(ConfigConstants.CONFIG_PROTOCOL_SECTION)
70 .contains(ConfigConstants.CONFIG_KEY_VERSION)) {
71 String version =
72 jgitConfig.getString(
73 ConfigConstants.CONFIG_PROTOCOL_SECTION, null, ConfigConstants.CONFIG_KEY_VERSION);
74 if (!TransferConfig.ProtocolVersion.V2.version().equals(version)) {
75 ui.error(
76 "HINT: JGit option \"%s.%s = %s\". It's recommended to activate git\n"
77 + "wire protocol version 2 to improve git fetch performance.",
78 ConfigConstants.CONFIG_PROTOCOL_SECTION, ConfigConstants.CONFIG_KEY_VERSION, version);
79 }
80 }
81 } catch (IOException e) {
82 throw die(String.format("Handling JGit configuration %s failed", sitePaths.jgit_config), e);
83 } catch (ConfigInvalidException e) {
84 throw die(String.format("Invalid JGit configuration %s", sitePaths.jgit_config), e);
85 }
86 }
87}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected