Merge "Add verbose statistics for Schema 130 & 131"

This commit is contained in:
David Pursehouse
2016-11-15 02:26:33 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 2 deletions

View File

@@ -29,6 +29,9 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import java.io.IOException;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
public class Schema_130 extends SchemaVersion {
private static final String COMMIT_MSG =
@@ -51,16 +54,27 @@ public class Schema_130 extends SchemaVersion {
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
for (Project.NameKey projectName : repoManager.list()) {
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(Collectors.joining(" ")));
}
}

View File

@@ -30,6 +30,9 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import java.io.IOException;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
public class Schema_131 extends SchemaVersion {
private static final String COMMIT_MSG =
@@ -49,7 +52,10 @@ public class Schema_131 extends SchemaVersion {
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
for (Project.NameKey projectName : repoManager.list()) {
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)) {
@@ -59,10 +65,16 @@ public class Schema_131 extends SchemaVersion {
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(Collectors.joining(" ")));
}
}