Browse Source

pgm daemon: fallback to user and system config if no config specified

If a config file is passed via option --config-file then use only the
options defined in that file. This helps to concisely configure the
daemon without side effects from global and system level git configs.

Otherwise fallback to user and system level configs.

Change-Id: I242de248f257579874ad0bfe4882a22502353b1f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.1
Matthias Sohn 5 years ago
parent
commit
187b7ad72e
  1. 25
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java

25
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java

@ -44,6 +44,7 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -51,12 +52,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.internal.ketch.KetchLeader; import org.eclipse.jgit.internal.ketch.KetchLeader;
import org.eclipse.jgit.internal.ketch.KetchLeaderCache; import org.eclipse.jgit.internal.ketch.KetchLeaderCache;
import org.eclipse.jgit.internal.ketch.KetchPreReceive; import org.eclipse.jgit.internal.ketch.KetchPreReceive;
import org.eclipse.jgit.internal.ketch.KetchSystem; import org.eclipse.jgit.internal.ketch.KetchSystem;
import org.eclipse.jgit.internal.ketch.KetchText; import org.eclipse.jgit.internal.ketch.KetchText;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.storage.file.WindowCacheConfig;
@ -69,6 +72,7 @@ import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
@ -121,19 +125,20 @@ class Daemon extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
PackConfig packConfig = new PackConfig(); PackConfig packConfig = new PackConfig();
StoredConfig cfg;
if (configFile != null) { if (configFile == null) {
cfg = getUserConfig();
} else {
if (!configFile.exists()) { if (!configFile.exists()) {
throw die(MessageFormat.format( throw die(MessageFormat.format(
CLIText.get().configFileNotFound, // CLIText.get().configFileNotFound, //
configFile.getAbsolutePath())); configFile.getAbsolutePath()));
} }
cfg = new FileBasedConfig(configFile, FS.DETECTED);
FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED); }
cfg.load(); cfg.load();
new WindowCacheConfig().fromConfig(cfg).install(); new WindowCacheConfig().fromConfig(cfg).install();
packConfig.fromConfig(cfg); packConfig.fromConfig(cfg);
}
int threads = packConfig.getThreads(); int threads = packConfig.getThreads();
if (threads <= 0) if (threads <= 0)
@ -173,6 +178,16 @@ class Daemon extends TextBuiltin {
outw.println(MessageFormat.format(CLIText.get().listeningOn, d.getAddress())); outw.println(MessageFormat.format(CLIText.get().listeningOn, d.getAddress()));
} }
private StoredConfig getUserConfig() throws IOException {
StoredConfig userConfig = null;
try {
userConfig = SystemReader.getInstance().getUserConfig();
} catch (ConfigInvalidException e) {
throw die(e.getMessage());
}
return userConfig;
}
private static DaemonService service( private static DaemonService service(
final org.eclipse.jgit.transport.Daemon d, final org.eclipse.jgit.transport.Daemon d,
final String n) { final String n) {

Loading…
Cancel
Save