use of org.eclipse.jgit.lib.Repository 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 org.eclipse.jgit.lib.Repository 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 org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class Schema_148 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (Repository repo = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId rev = ExternalIdReader.readRevision(repo);
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
boolean dirty = false;
for (Note note : noteMap) {
byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(ExternalIdReader.MAX_NOTE_SZ);
try {
ExternalId extId = ExternalId.parse(note.getName(), raw);
if (needsUpdate(extId)) {
ExternalIdsUpdate.upsert(rw, ins, noteMap, extId);
dirty = true;
}
} catch (ConfigInvalidException e) {
ui.message(String.format("Warning: Ignoring invalid external ID note %s", note.getName()));
}
}
if (dirty) {
ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, COMMIT_MSG, serverUser, serverUser);
}
} catch (IOException e) {
throw new OrmException("Failed to update external IDs", e);
}
}
use of org.eclipse.jgit.lib.Repository in project gitiles by GerritCodeReview.
the class DefaultAccess method listRepositories.
@Override
public Map<String, RepositoryDescription> listRepositories(String prefix, Set<String> branches) throws IOException {
Map<String, RepositoryDescription> repos = Maps.newTreeMap(US_COLLATOR);
for (Repository repo : scanRepositories(basePath, prefix, req)) {
repos.put(getRepositoryName(repo), buildDescription(repo, branches));
repo.close();
}
return repos;
}
use of org.eclipse.jgit.lib.Repository in project gitiles by GerritCodeReview.
the class DiffServlet method doGetText.
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo)) {
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
try (Writer writer = startRenderText(req, res);
OutputStream out = BaseEncoding.base64().encodingStream(writer);
DiffFormatter diff = new DiffFormatter(out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
Aggregations