* @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);
}
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);
}
}