use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.
the class RepositoryManager method getRepositoryConfig.
/**
* Workaround JGit. I need to access the raw config object directly in order
* to see if the config is dirty so that I can reload a repository model.
* If I use the stock JGit method to get the config it already reloads the
* config. If the config changes are made within Gitblit this is fine as
* the returned config will still be flagged as dirty. BUT... if the config
* is manipulated outside Gitblit then it fails to recognize this as dirty.
*
* @param r
* @return a config
*/
private StoredConfig getRepositoryConfig(Repository r) {
try {
Field f = r.getClass().getDeclaredField("repoConfig");
f.setAccessible(true);
StoredConfig config = (StoredConfig) f.get(r);
return config;
} catch (Exception e) {
logger.error("Failed to retrieve \"repoConfig\" via reflection", e);
}
return r.getConfig();
}
use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.
the class RepositoryManager method updateConfiguration.
/**
* Updates the Gitblit configuration for the specified repository.
*
* @param r
* 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);
}
}
use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.
the class RepositoryModelTest method initializeConfiguration.
@Before
public void initializeConfiguration() throws Exception {
Repository r = GitBlitSuite.getHelloworldRepository();
StoredConfig config = r.getConfig();
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d");
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello");
config.save();
}
use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.
the class RepositoryModelTest method teardownConfiguration.
@After
public void teardownConfiguration() throws Exception {
Repository r = GitBlitSuite.getHelloworldRepository();
StoredConfig config = r.getConfig();
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);
config.save();
}
use of org.eclipse.jgit.lib.StoredConfig in project gerrit by GerritCodeReview.
the class LocalDiskRepositoryManager method createRepository.
@Override
public Repository createRepository(Project.NameKey name) throws RepositoryNotFoundException, RepositoryCaseMismatchException, IOException {
Path path = getBasePath(name);
if (isUnreasonableName(name)) {
throw new RepositoryNotFoundException("Invalid name: " + name);
}
File dir = FileKey.resolve(path.resolve(name.get()).toFile(), FS.DETECTED);
FileKey loc;
if (dir != null) {
// Already exists on disk, use the repository we found.
//
Project.NameKey onDiskName = getProjectName(path, dir.getCanonicalFile().toPath());
onCreateProject(onDiskName);
loc = FileKey.exact(dir, FS.DETECTED);
if (!names.contains(name)) {
throw new RepositoryCaseMismatchException(name);
}
} else {
// It doesn't exist under any of the standard permutations
// of the repository name, so prefer the standard bare name.
//
String n = name.get() + Constants.DOT_GIT_EXT;
loc = FileKey.exact(path.resolve(n).toFile(), FS.DETECTED);
}
try {
Repository db = RepositoryCache.open(loc, false);
db.create(true);
StoredConfig config = db.getConfig();
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
config.save();
// JGit only writes to the reflog for refs/meta/config if the log file
// already exists.
//
File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG);
if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) {
log.error(String.format("Failed to create ref log for %s in repository %s", RefNames.REFS_CONFIG, name));
}
onCreateProject(name);
return db;
} catch (IOException e1) {
final RepositoryNotFoundException e2;
e2 = new RepositoryNotFoundException("Cannot create repository " + name);
e2.initCause(e1);
throw e2;
}
}
Aggregations