Example usage for org.eclipse.jgit.lib StoredConfig setInt

List of usage examples for org.eclipse.jgit.lib StoredConfig setInt

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib StoredConfig setInt.

Prototype

public void setInt(final String section, final String subsection, final String name, final int value) 

Source Link

Document

Add or modify a configuration value.

Usage

From source file:com.gitblit.manager.RepositoryManager.java

License:Apache License

/**
 * Updates the Gitblit configuration for the specified repository.
 *
 * @param r//from  w ww  . j a v a2s. c o m
 *            the Git repository
 * @param repository
 *            the Gitblit repository model
 */
@Override
public void updateConfiguration(Repository r, RepositoryModel repository) {
    StoredConfig config = r.getConfig();
    config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description);
    config.setString(Constants.CONFIG_GITBLIT, null, "originRepository", repository.originRepository);
    config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners));
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewPatchsets", repository.acceptNewPatchsets);
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewTickets", repository.acceptNewTickets);
    if (settings.getBoolean(Keys.tickets.requireApproval, false) == repository.requireApproval) {
        // use default
        config.unset(Constants.CONFIG_GITBLIT, null, "requireApproval");
    } else {
        // override default
        config.setBoolean(Constants.CONFIG_GITBLIT, null, "requireApproval", repository.requireApproval);
    }
    if (!StringUtils.isEmpty(repository.mergeTo)) {
        config.setString(Constants.CONFIG_GITBLIT, null, "mergeTo", repository.mergeTo);
    }
    if (repository.mergeType == null
            || repository.mergeType == MergeType.fromName(settings.getString(Keys.tickets.mergeType, null))) {
        // use default
        config.unset(Constants.CONFIG_GITBLIT, null, "mergeType");
    } else {
        // override default
        config.setString(Constants.CONFIG_GITBLIT, null, "mergeType", repository.mergeType.name());
    }
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalPushTags",
            repository.useIncrementalPushTags);
    if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) || repository.incrementalPushTagPrefix
            .equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) {
        config.unset(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix");
    } else {
        config.setString(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix",
                repository.incrementalPushTagPrefix);
    }
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks);
    config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name());
    config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl",
            repository.authorizationControl.name());
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "verifyCommitter", repository.verifyCommitter);
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches);
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen);
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation);
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics);
    config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy",
            repository.federationStrategy.name());
    config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated);
    config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold);
    if (repository.gcPeriod == settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7)) {
        // use default from config
        config.unset(Constants.CONFIG_GITBLIT, null, "gcPeriod");
    } else {
        config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);
    }
    if (repository.lastGC != null) {
        config.setString(Constants.CONFIG_GITBLIT, null, "lastGC",
                new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC));
    }
    if (repository.maxActivityCommits == settings.getInteger(Keys.web.maxActivityCommits, 0)) {
        // use default from config
        config.unset(Constants.CONFIG_GITBLIT, null, "maxActivityCommits");
    } else {
        config.setInt(Constants.CONFIG_GITBLIT, null, "maxActivityCommits", repository.maxActivityCommits);
    }

    CommitMessageRenderer defaultRenderer = CommitMessageRenderer
            .fromName(settings.getString(Keys.web.commitMessageRenderer, null));
    if (repository.commitMessageRenderer == null || repository.commitMessageRenderer == defaultRenderer) {
        // use default from config
        config.unset(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer");
    } else {
        // repository overrides default
        config.setString(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer",
                repository.commitMessageRenderer.name());
    }

    updateList(config, "federationSets", repository.federationSets);
    updateList(config, "preReceiveScript", repository.preReceiveScripts);
    updateList(config, "postReceiveScript", repository.postReceiveScripts);
    updateList(config, "mailingList", repository.mailingLists);
    updateList(config, "indexBranch", repository.indexedBranches);
    updateList(config, "metricAuthorExclusions", repository.metricAuthorExclusions);

    // User Defined Properties
    if (repository.customFields != null) {
        if (repository.customFields.size() == 0) {
            // clear section
            config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);
        } else {
            for (Entry<String, String> property : repository.customFields.entrySet()) {
                // set field
                String key = property.getKey();
                String value = property.getValue();
                config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value);
            }
        }
    }

    try {
        config.save();
    } catch (IOException e) {
        logger.error("Failed to save repository config!", e);
    }
}

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java

License:Open Source License

public Repository createGitRepository(Path path) {
    Repository toReturn;/*from   ww  w.ja va 2 s.c o m*/
    path = Paths.get(path.toAbsolutePath().toString(), GIT_ROOT);
    try {
        toReturn = FileRepositoryBuilder.create(path.toFile());
        toReturn.create();

        // Get git configuration
        StoredConfig config = toReturn.getConfig();
        // Set compression level (core.compression)
        config.setInt(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_COMPRESSION,
                CONFIG_PARAMETER_COMPRESSION_DEFAULT);
        // Set big file threshold (core.bigFileThreshold)
        config.setString(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_BIG_FILE_THRESHOLD,
                CONFIG_PARAMETER_BIG_FILE_THRESHOLD_DEFAULT);
        // Save configuration changes
        config.save();
    } catch (IOException e) {
        logger.error("Error while creating repository for site with path" + path.toString(), e);
        toReturn = null;
    }

    return toReturn;
}