use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method reindexIfStale.
@Test
public void reindexIfStale() throws Exception {
Account.Id user = createAccount("user");
Project.NameKey project = new Project.NameKey("repo");
TestRepository<Repo> repo = createProject(project.get());
Change change = insert(repo, newChange(repo));
String changeId = change.getKey().get();
ChangeNotes notes = notesFactory.create(db, change.getProject(), change.getId());
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());
requestContext.setContext(newRequestContext(user));
gApi.changes().id(changeId).edit().create();
assertQuery("has:edit", change);
assertThat(indexer.reindexIfStale(project, change.getId()).get()).isFalse();
// Delete edit ref behind index's back.
RefUpdate ru = repo.getRepository().updateRef(RefNames.refsEdit(user, change.getId(), ps.getId()));
ru.setForceUpdate(true);
assertThat(ru.delete()).isEqualTo(RefUpdate.Result.FORCED);
// Index is stale.
assertQuery("has:edit", change);
assertThat(indexer.reindexIfStale(project, change.getId()).get()).isTrue();
assertQuery("has:edit");
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeDataTest method setPatchSetsClearsCurrentPatchSet.
@Test
public void setPatchSetsClearsCurrentPatchSet() throws Exception {
Project.NameKey project = new Project.NameKey("project");
ChangeData cd = ChangeData.createForTest(project, new Change.Id(1), 1);
cd.setChange(TestChanges.newChange(project, new Account.Id(1000)));
PatchSet curr1 = cd.currentPatchSet();
int currId = curr1.getId().get();
PatchSet ps1 = new PatchSet(new PatchSet.Id(cd.getId(), currId + 1));
PatchSet ps2 = new PatchSet(new PatchSet.Id(cd.getId(), currId + 2));
cd.setPatchSets(ImmutableList.of(ps1, ps2));
PatchSet curr2 = cd.currentPatchSet();
assertThat(curr2).isNotSameAs(curr1);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeIncludedIn method apply.
@Override
public IncludedInInfo apply(ChangeResource rsrc) throws RestApiException, OrmException, IOException {
ChangeControl ctl = rsrc.getControl();
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes());
Project.NameKey project = ctl.getProject().getNameKey();
return includedIn.apply(project, ps.getRevision().get());
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeJson method messages.
private Collection<ChangeMessageInfo> messages(ChangeControl ctl, ChangeData cd, Map<PatchSet.Id, PatchSet> map) throws OrmException {
List<ChangeMessage> messages = cmUtil.byChange(db.get(), cd.notes());
if (messages.isEmpty()) {
return Collections.emptyList();
}
List<ChangeMessageInfo> result = Lists.newArrayListWithCapacity(messages.size());
for (ChangeMessage message : messages) {
PatchSet.Id patchNum = message.getPatchSetId();
PatchSet ps = patchNum != null ? map.get(patchNum) : null;
if (patchNum == null || ctl.isPatchVisible(ps, db.get())) {
ChangeMessageInfo cmi = new ChangeMessageInfo();
cmi.id = message.getKey().get();
cmi.author = accountLoader.get(message.getAuthor());
cmi.date = message.getWrittenOn();
cmi.message = message.getMessage();
cmi.tag = message.getTag();
cmi._revisionNumber = patchNum != null ? patchNum.get() : null;
Account.Id realAuthor = message.getRealAuthor();
if (realAuthor != null) {
cmi.realAuthor = accountLoader.get(realAuthor);
}
result.add(cmi);
}
}
return result;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class Schema_108 method updateGroups.
private static void updateGroups(ReviewDb db, GroupCollector collector, ListMultimap<ObjectId, PatchSet.Id> patchSetsBySha) throws OrmException {
Map<PatchSet.Id, PatchSet> patchSets = db.patchSets().toMap(db.patchSets().get(patchSetsBySha.values()));
for (Map.Entry<ObjectId, Collection<String>> e : collector.getGroups().asMap().entrySet()) {
for (PatchSet.Id psId : patchSetsBySha.get(e.getKey())) {
PatchSet ps = patchSets.get(psId);
if (ps != null) {
ps.setGroups(ImmutableList.copyOf(e.getValue()));
}
}
}
db.patchSets().update(patchSets.values());
}
Aggregations