From 9fbce904e6471b49668457caa4c0c2d4131a0fb5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 28 Jul 2010 10:48:53 -0700 Subject: Pass PackConfig down to PackWriter when packing When we are creating a pack the higher level application should be able to override the PackConfig used, allowing it to control the number of threads used or how much memory is allocated per writer. Change-Id: I47795987bb0d161d3642082acc2f617d7cb28d8c Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/pgm/CLIText.java | 1 + .../src/org/eclipse/jgit/pgm/Daemon.java | 37 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit.pgm/src') diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java index bae895cc76..14dcb1f50d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java @@ -67,6 +67,7 @@ public class CLIText extends TranslationBundle { /***/ public String branchIsNotAnAncestorOfYourCurrentHEAD; /***/ public String branchNotFound; /***/ public String cacheTreePathInfo; + /***/ public String configFileNotFound; /***/ public String cannotBeRenamed; /***/ public String cannotChekoutNoHeadsAdvertisedByRemote; /***/ public String cannotCreateCommand; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java index f015a9e7bd..3cca87abe8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java @@ -48,13 +48,22 @@ import java.net.InetSocketAddress; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.storage.file.WindowCache; +import org.eclipse.jgit.storage.file.WindowCacheConfig; +import org.eclipse.jgit.storage.pack.PackConfig; +import org.eclipse.jgit.transport.DaemonService; +import org.eclipse.jgit.util.FS; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; -import org.eclipse.jgit.transport.DaemonService; @Command(common = true, usage = "usage_exportRepositoriesOverGit") class Daemon extends TextBuiltin { + @Option(name = "--config-file", metaVar = "metaVar_configFile", usage = "usage_configFile") + File configFile; + @Option(name = "--port", metaVar = "metaVar_port", usage = "usage_portNumberToListenOn") int port = org.eclipse.jgit.transport.Daemon.DEFAULT_PORT; @@ -89,12 +98,38 @@ class Daemon extends TextBuiltin { @Override protected void run() throws Exception { + PackConfig packConfig = new PackConfig(); + + if (configFile != null) { + if (!configFile.exists()) { + throw die(MessageFormat.format( + CLIText.get().configFileNotFound, // + configFile.getAbsolutePath())); + } + + FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED); + cfg.load(); + + WindowCacheConfig wcc = new WindowCacheConfig(); + wcc.fromConfig(cfg); + WindowCache.reconfigure(wcc); + + packConfig.fromConfig(cfg); + } + + int threads = packConfig.getThreads(); + if (threads <= 0) + threads = Runtime.getRuntime().availableProcessors(); + if (1 < threads) + packConfig.setExecutor(Executors.newFixedThreadPool(threads)); + final org.eclipse.jgit.transport.Daemon d; d = new org.eclipse.jgit.transport.Daemon( host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port)); d.setExportAll(exportAll); + d.setPackConfig(packConfig); if (0 <= timeout) d.setTimeout(timeout); -- cgit v1.2.3