use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_125 method getLabelTypes.
private Collection<LabelType> getLabelTypes(ProjectConfig config) throws IOException, ConfigInvalidException {
Map<String, LabelType> labelTypes = new HashMap<>(config.getLabelSections());
Project.NameKey parent = config.getProject().getParent(allProjectsName);
while (parent != null) {
try (Repository git = repoManager.openRepository(parent);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, parent, git)) {
ProjectConfig parentConfig = ProjectConfig.read(md);
for (LabelType lt : parentConfig.getLabelSections().values()) {
if (!labelTypes.containsKey(lt.getName())) {
labelTypes.put(lt.getName(), lt);
}
}
parent = parentConfig.getProject().getParent(allProjectsName);
}
}
return labelTypes.values();
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_130 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
SortedSet<Project.NameKey> repoList = repoManager.list();
SortedSet<Project.NameKey> repoUpgraded = new TreeSet<>();
ui.message("\tMigrating " + repoList.size() + " repositories ...");
for (Project.NameKey projectName : repoList) {
try (Repository git = repoManager.openRepository(projectName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, git)) {
ProjectConfigSchemaUpdate cfg = ProjectConfigSchemaUpdate.read(md);
cfg.removeForceFromPermission("pushTag");
if (cfg.isUpdated()) {
repoUpgraded.add(projectName);
}
cfg.save(serverUser, COMMIT_MSG);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException("Cannot migrate project " + projectName, ex);
}
}
ui.message("\tMigration completed: " + repoUpgraded.size() + " repositories updated:");
ui.message("\t" + repoUpgraded.stream().map(n -> n.get()).collect(joining(" ")));
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method saveProjectConfig.
protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg) throws Exception {
try (MetaDataUpdate md = metaDataUpdateFactory.create(p)) {
md.setAuthor(identifiedUserFactory.create(admin.getId()));
cfg.commit(md);
}
projectCache.evict(cfg.getProject());
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method grant.
protected void grant(Project.NameKey project, String ref, String permission, boolean force, AccountGroup.UUID groupUUID) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
md.setMessage(String.format("Grant %s on %s", permission, ref));
ProjectConfig config = ProjectConfig.read(md);
AccessSection s = config.getAccessSection(ref, true);
Permission p = s.getPermission(permission, true);
PermissionRule rule = Util.newRule(config, groupUUID);
rule.setForce(force);
p.add(rule);
config.commit(md);
projectCache.evict(config.getProject());
}
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method removePermission.
protected void removePermission(Project.NameKey project, String ref, String permission) throws IOException, ConfigInvalidException {
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
md.setMessage(String.format("Remove %s on %s", permission, ref));
ProjectConfig config = ProjectConfig.read(md);
AccessSection s = config.getAccessSection(ref, true);
Permission p = s.getPermission(permission, true);
p.getRules().clear();
config.commit(md);
projectCache.evict(config.getProject());
}
}
Aggregations