use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class SchemaCreatorTest method getLabelTypes.
private LabelTypes getLabelTypes() throws Exception {
db.create();
ProjectConfig c = new ProjectConfig(allProjects);
try (Repository repo = repoManager.openRepository(allProjects)) {
c.load(repo);
return new LabelTypes(ImmutableList.copyOf(c.getLabelSections().values()));
}
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class FixReplacementInterpreter method toTreeModifications.
/**
* Transforms the given {@code FixReplacement}s into {@code TreeModification}s.
*
* @param repository the affected Git repository
* @param projectState the affected project
* @param patchSetCommitId the patch set which should be modified
* @param fixReplacements the replacements which should be applied
* @return a list of {@code TreeModification}s representing the given replacements
* @throws ResourceNotFoundException if a file to which one of the replacements refers doesn't
* exist
* @throws ResourceConflictException if the replacements can't be transformed into {@code
* TreeModification}s
*/
public List<TreeModification> toTreeModifications(Repository repository, ProjectState projectState, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceNotFoundException, IOException, ResourceConflictException {
checkNotNull(fixReplacements, "Fix replacements must not be null");
Map<String, List<FixReplacement>> fixReplacementsPerFilePath = fixReplacements.stream().collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
List<TreeModification> treeModifications = new ArrayList<>();
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
TreeModification treeModification = toTreeModification(repository, projectState, patchSetCommitId, entry.getKey(), entry.getValue());
treeModifications.add(treeModification);
}
return treeModifications;
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class ChangeEditUtil method delete.
/**
* Delete change edit.
*
* @param edit change edit to delete
* @throws IOException
* @throws OrmException
*/
public void delete(ChangeEdit edit) throws IOException, OrmException {
Change change = edit.getChange();
try (Repository repo = gitManager.openRepository(change.getProject())) {
deleteRef(repo, edit);
}
indexer.index(db.get(), change);
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method openRepo.
private OpenRepo openRepo(Project.NameKey p) throws IOException {
// Closed by OpenRepo#close.
Repository repo = repoManager.openRepository(p);
// Closed by OpenRepo#close.
ObjectInserter ins = repo.newObjectInserter();
// Not closed by OpenRepo#close.
ObjectReader reader = ins.newReader();
try (RevWalk rw = new RevWalk(reader)) {
// Doesn't escape OpenRepo constructor.
return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {
@Override
public void close() {
reader.close();
super.close();
}
};
}
}
use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.
the class PrimaryStorageMigrator method setPrimaryStorageReviewDb.
private void setPrimaryStorageReviewDb(Change.Id id, ObjectId newMetaId) throws OrmException, IOException {
ImmutableMap.Builder<Account.Id, ObjectId> draftIds = ImmutableMap.builder();
try (Repository repo = repoManager.openRepository(allUsers)) {
for (Ref draftRef : repo.getRefDatabase().getRefs(RefNames.refsDraftCommentsPrefix(id)).values()) {
Account.Id accountId = Account.Id.fromRef(draftRef.getName());
if (accountId != null) {
draftIds.put(accountId, draftRef.getObjectId().copy());
}
}
}
NoteDbChangeState newState = new NoteDbChangeState(id, PrimaryStorage.REVIEW_DB, Optional.of(RefState.create(newMetaId, draftIds.build())), Optional.empty());
db().changes().atomicUpdate(id, new AtomicUpdate<Change>() {
@Override
public Change update(Change change) {
if (PrimaryStorage.of(change) != PrimaryStorage.NOTE_DB) {
throw new OrmRuntimeException("change " + id + " is not NoteDb primary: " + change.getNoteDbState());
}
change.setNoteDbState(newState.toString());
return change;
}
});
}
Aggregations