use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_125 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
try (Repository git = repoManager.openRepository(allUsersName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
ProjectConfig config = ProjectConfig.read(md);
config.getAccessSection(RefNames.REFS_USERS + "*", true).remove(new Permission(Permission.READ));
GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
AccessSection users = config.getAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", true);
grant(config, users, Permission.READ, true, registered);
grant(config, users, Permission.PUSH, true, registered);
grant(config, users, Permission.SUBMIT, true, registered);
for (LabelType lt : getLabelTypes(config)) {
if ("Code-Review".equals(lt.getName()) || "Verified".equals(lt.getName())) {
grant(config, users, lt, lt.getMin().getValue(), lt.getMax().getValue(), registered);
}
}
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_126 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
try (Repository git = repoManager.openRepository(allUsersName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
ProjectConfig config = ProjectConfig.read(md);
String refsUsersShardedId = RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}";
config.remove(config.getAccessSection(refsUsersShardedId));
GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
AccessSection users = config.getAccessSection(refsUsersShardedId, true);
grant(config, users, Permission.READ, false, true, registered);
grant(config, users, Permission.PUSH, false, true, registered);
grant(config, users, Permission.SUBMIT, false, true, registered);
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_128 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
try (Repository git = repoManager.openRepository(allProjectsName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git)) {
ProjectConfig config = ProjectConfig.read(md);
GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
AccessSection refsFor = config.getAccessSection("refs/for/*", true);
grant(config, refsFor, Permission.ADD_PATCH_SET, false, false, registered);
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_131 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)) {
ProjectConfig config = ProjectConfig.read(md);
if (config.hasLegacyPermissions()) {
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
repoUpgraded.add(projectName);
}
} 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 SetPreferences method writeToGit.
private GeneralPreferencesInfo writeToGit(GeneralPreferencesInfo i) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
VersionedAccountPreferences p = VersionedAccountPreferences.forDefault();
p.load(md);
storeSection(p.getConfig(), UserConfigSections.GENERAL, null, i, GeneralPreferencesInfo.defaults());
com.google.gerrit.server.account.SetPreferences.storeMyMenus(p, i.my);
com.google.gerrit.server.account.SetPreferences.storeUrlAliases(p, i.urlAliases);
p.commit(md);
accountCache.evictAll();
GeneralPreferencesInfo r = loadSection(p.getConfig(), UserConfigSections.GENERAL, null, new GeneralPreferencesInfo(), GeneralPreferencesInfo.defaults(), null);
return loader.loadMyMenusAndUrlAliases(r, p, null);
}
}
Aggregations