Example usage for org.eclipse.jgit.storage.pack PackConfig fromConfig

List of usage examples for org.eclipse.jgit.storage.pack PackConfig fromConfig

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.pack PackConfig fromConfig.

Prototype

public void fromConfig(Config rc) 

Source Link

Document

Update properties by setting fields from the configuration.

Usage

From source file:com.sap.poc.jgit.storage.jdbc.pgm.JdbcDaemon.java

License:Eclipse Distribution License

@Override
protected void run() throws Exception {
    final PackConfig packConfig = new PackConfig();

    if (configFile != null) {
        if (!configFile.exists())
            throw die(MessageFormat.format(CLIText.get().configFileNotFound, configFile.getAbsolutePath()));

        final FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
        cfg.load();//  www .  j  a  va 2  s  .c om
        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));

    final JdbcDatabase db = new JdbcDatabaseBuilder().setURI(uri).build();

    final RepositoryResolver<DaemonClient> resolver = new RepositoryResolver<DaemonClient>() {
        @Override
        public Repository open(DaemonClient req, String name) throws RepositoryNotFoundException {
            try {
                return new JdbcRepositoryBuilder().setDatabase(db).setRepositoryName(name).build();
            } catch (DhtException e) {
                throw new RepositoryNotFoundException(name, e);
            }
        }
    };

    d.setPackConfig(packConfig);
    d.setRepositoryResolver(resolver);
    if (0 <= timeout)
        d.setTimeout(timeout);

    for (final String n : enable)
        service(d, n).setEnabled(true);
    for (final String n : disable)
        service(d, n).setEnabled(false);

    for (final String n : canOverride)
        service(d, n).setOverridable(true);
    for (final String n : forbidOverride)
        service(d, n).setOverridable(false);

    d.start();
    out.println(MessageFormat.format(CLIText.get().listeningOn, d.getAddress()));
}

From source file:net.antoniy.gidder.beta.ssh.Upload.java

License:Apache License

@Override
protected void runImpl() throws IOException {
    if (!hasPermission()) {
        err.write(MSG_REPOSITORY_PERMISSIONS.getBytes());
        err.flush();//from w  w w  .j  ava  2 s  .c  o  m
        onExit(CODE_OK, MSG_REPOSITORY_PERMISSIONS);
        return;
    }

    Config config = new Config();
    //      int timeout = Integer.parseInt(config.getString("transfer", null,
    //            "timeout"));
    int timeout = 10;

    PackConfig packConfig = new PackConfig();
    packConfig.setDeltaCompress(false);
    packConfig.setThreads(1);
    packConfig.fromConfig(config);

    final UploadPack up = new UploadPack(repo);
    up.setPackConfig(packConfig);
    up.setTimeout(timeout);
    up.upload(in, out, err);
}