PatchSetUtil: Remove ReviewDb-specific logic

ReviewDb is gone.

Change-Id: Ic02f41d87d5ebe02399dc4624faeb35f93cc2190
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-12-11 15:15:01 +01:00
parent 58c7b49927
commit c4515b05e2
55 changed files with 135 additions and 247 deletions

View File

@@ -143,7 +143,7 @@ public class CatServlet extends HttpServlet {
return; return;
} }
} else { } else {
PatchSet patchSet = psUtil.get(requestDb.get(), notes, patchKey.getParentKey()); PatchSet patchSet = psUtil.get(notes, patchKey.getParentKey());
if (patchSet == null) { if (patchSet == null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND); rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;

View File

@@ -137,7 +137,7 @@ public class ApprovalCopier {
@Nullable Config repoConfig, @Nullable Config repoConfig,
Iterable<PatchSetApproval> dontCopy) Iterable<PatchSetApproval> dontCopy)
throws OrmException { throws OrmException {
PatchSet ps = psUtil.get(db, notes, psId); PatchSet ps = psUtil.get(notes, psId);
if (ps == null) { if (ps == null) {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@@ -15,16 +15,11 @@
package com.google.gerrit.server; package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.gerrit.server.ChangeUtil.PS_ID_ORDER;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.gerrit.common.data.LabelFunction; import com.google.gerrit.common.data.LabelFunction;
import com.google.gerrit.common.data.LabelType; import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
@@ -37,7 +32,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate; import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -46,7 +40,6 @@ import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@@ -57,7 +50,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
/** Utilities for manipulating patch sets. */ /** Utilities for manipulating patch sets. */
@Singleton @Singleton
public class PatchSetUtil { public class PatchSetUtil {
private final NotesMigration migration;
private final Provider<ApprovalsUtil> approvalsUtilProvider; private final Provider<ApprovalsUtil> approvalsUtilProvider;
private final ProjectCache projectCache; private final ProjectCache projectCache;
private final Provider<ReviewDb> dbProvider; private final Provider<ReviewDb> dbProvider;
@@ -65,62 +57,38 @@ public class PatchSetUtil {
@Inject @Inject
PatchSetUtil( PatchSetUtil(
NotesMigration migration,
Provider<ApprovalsUtil> approvalsUtilProvider, Provider<ApprovalsUtil> approvalsUtilProvider,
ProjectCache projectCache, ProjectCache projectCache,
Provider<ReviewDb> dbProvider, Provider<ReviewDb> dbProvider,
GitRepositoryManager repoManager) { GitRepositoryManager repoManager) {
this.migration = migration;
this.approvalsUtilProvider = approvalsUtilProvider; this.approvalsUtilProvider = approvalsUtilProvider;
this.projectCache = projectCache; this.projectCache = projectCache;
this.dbProvider = dbProvider; this.dbProvider = dbProvider;
this.repoManager = repoManager; this.repoManager = repoManager;
} }
public PatchSet current(ReviewDb db, ChangeNotes notes) throws OrmException { public PatchSet current(ChangeNotes notes) throws OrmException {
return get(db, notes, notes.getChange().currentPatchSetId()); return get(notes, notes.getChange().currentPatchSetId());
} }
public PatchSet get(ReviewDb db, ChangeNotes notes, PatchSet.Id psId) throws OrmException { public PatchSet get(ChangeNotes notes, PatchSet.Id psId) throws OrmException {
if (!migration.readChanges()) {
return db.patchSets().get(psId);
}
return notes.load().getPatchSets().get(psId); return notes.load().getPatchSets().get(psId);
} }
public ImmutableCollection<PatchSet> byChange(ReviewDb db, ChangeNotes notes) public ImmutableCollection<PatchSet> byChange(ChangeNotes notes) throws OrmException {
throws OrmException {
if (!migration.readChanges()) {
return PS_ID_ORDER.immutableSortedCopy(db.patchSets().byChange(notes.getChangeId()));
}
return notes.load().getPatchSets().values(); return notes.load().getPatchSets().values();
} }
public ImmutableMap<PatchSet.Id, PatchSet> byChangeAsMap(ReviewDb db, ChangeNotes notes) public ImmutableMap<PatchSet.Id, PatchSet> byChangeAsMap(ChangeNotes notes) throws OrmException {
throws OrmException {
if (!migration.readChanges()) {
ImmutableMap.Builder<PatchSet.Id, PatchSet> result = ImmutableMap.builder();
for (PatchSet ps : PS_ID_ORDER.sortedCopy(db.patchSets().byChange(notes.getChangeId()))) {
result.put(ps.getId(), ps);
}
return result.build();
}
return notes.load().getPatchSets(); return notes.load().getPatchSets();
} }
public ImmutableMap<PatchSet.Id, PatchSet> getAsMap( public ImmutableMap<PatchSet.Id, PatchSet> getAsMap(
ReviewDb db, ChangeNotes notes, Set<PatchSet.Id> patchSetIds) throws OrmException { ChangeNotes notes, Set<PatchSet.Id> patchSetIds) throws OrmException {
if (!migration.readChanges()) {
patchSetIds = Sets.filter(patchSetIds, p -> p.getParentKey().equals(notes.getChangeId()));
return Streams.stream(db.patchSets().get(patchSetIds))
.sorted(PS_ID_ORDER)
.collect(toImmutableMap(PatchSet::getId, identity()));
}
return ImmutableMap.copyOf(Maps.filterKeys(notes.load().getPatchSets(), patchSetIds::contains)); return ImmutableMap.copyOf(Maps.filterKeys(notes.load().getPatchSets(), patchSetIds::contains));
} }
public PatchSet insert( public PatchSet insert(
ReviewDb db,
RevWalk rw, RevWalk rw,
ChangeUpdate update, ChangeUpdate update,
PatchSet.Id psId, PatchSet.Id psId,
@@ -128,10 +96,14 @@ public class PatchSetUtil {
List<String> groups, List<String> groups,
String pushCertificate, String pushCertificate,
String description) String description)
throws OrmException, IOException { throws IOException {
requireNonNull(groups, "groups may not be null"); requireNonNull(groups, "groups may not be null");
ensurePatchSetMatches(psId, update); ensurePatchSetMatches(psId, update);
update.setCommit(rw, commit, pushCertificate);
update.setPsDescription(description);
update.setGroups(groups);
PatchSet ps = new PatchSet(psId); PatchSet ps = new PatchSet(psId);
ps.setRevision(new RevId(commit.name())); ps.setRevision(new RevId(commit.name()));
ps.setUploader(update.getAccountId()); ps.setUploader(update.getAccountId());
@@ -139,12 +111,6 @@ public class PatchSetUtil {
ps.setGroups(groups); ps.setGroups(groups);
ps.setPushCertificate(pushCertificate); ps.setPushCertificate(pushCertificate);
ps.setDescription(description); ps.setDescription(description);
db.patchSets().insert(Collections.singleton(ps));
update.setCommit(rw, commit, pushCertificate);
update.setPsDescription(description);
update.setGroups(groups);
return ps; return ps;
} }
@@ -166,11 +132,9 @@ public class PatchSetUtil {
} }
} }
public void setGroups(ReviewDb db, ChangeUpdate update, PatchSet ps, List<String> groups) public void setGroups(ChangeUpdate update, PatchSet ps, List<String> groups) {
throws OrmException {
ps.setGroups(groups); ps.setGroups(groups);
update.setGroups(groups); update.setGroups(groups);
db.patchSets().update(Collections.singleton(ps));
} }
/** Check if the current patch set of the change is locked. */ /** Check if the current patch set of the change is locked. */

View File

@@ -56,8 +56,7 @@ public class PublishCommentUtil {
} }
Map<Id, PatchSet> patchSets = Map<Id, PatchSet> patchSets =
psUtil.getAsMap( psUtil.getAsMap(notes, drafts.stream().map(d -> psId(notes, d)).collect(toSet()));
ctx.getDb(), notes, drafts.stream().map(d -> psId(notes, d)).collect(toSet()));
for (Comment d : drafts) { for (Comment d : drafts) {
PatchSet ps = patchSets.get(psId(notes, d)); PatchSet ps = patchSets.get(psId(notes, d));
if (ps == null) { if (ps == null) {

View File

@@ -99,7 +99,7 @@ public class AbandonOp implements BatchUpdateOp {
if (!change.getStatus().isOpen()) { if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); patchSet = psUtil.get(ctx.getNotes(), psId);
change.setStatus(Change.Status.ABANDONED); change.setStatus(Change.Status.ABANDONED);
change.setLastUpdatedOn(ctx.getWhen()); change.setLastUpdatedOn(ctx.getWhen());

View File

@@ -213,7 +213,7 @@ public class AddReviewersOp implements BatchUpdateOp {
checkAdded(); checkAdded();
if (patchSet == null) { if (patchSet == null) {
patchSet = requireNonNull(psUtil.current(ctx.getDb(), ctx.getNotes())); patchSet = requireNonNull(psUtil.current(ctx.getNotes()));
} }
return true; return true;
} }

View File

@@ -412,14 +412,7 @@ public class ChangeInserter implements InsertChangeOp {
} }
patchSet = patchSet =
psUtil.insert( psUtil.insert(
ctx.getDb(), ctx.getRevWalk(), update, psId, commitId, newGroups, pushCert, patchSetDescription);
ctx.getRevWalk(),
update,
psId,
commitId,
newGroups,
pushCert,
patchSetDescription);
/* TODO: fixStatus is used here because the tests /* TODO: fixStatus is used here because the tests
* (byStatusClosed() in AbstractQueryChangesTest) * (byStatusClosed() in AbstractQueryChangesTest)

View File

@@ -154,11 +154,7 @@ public class ChangeResource implements RestResource, HasETag {
accounts.add(getChange().getAssignee()); accounts.add(getChange().getAssignee());
} }
try { try {
patchSetUtil patchSetUtil.byChange(notes).stream().map(PatchSet::getUploader).forEach(accounts::add);
.byChange(db.get(), notes)
.stream()
.map(PatchSet::getUploader)
.forEach(accounts::add);
// It's intentional to include the states for *all* reviewers into the ETag computation. // It's intentional to include the states for *all* reviewers into the ETag computation.
// We need the states of all current reviewers and CCs because they are part of ChangeInfo. // We need the states of all current reviewers and CCs because they are part of ChangeInfo.

View File

@@ -230,7 +230,7 @@ public class ConsistencyChecker {
private void checkCurrentPatchSetEntity() { private void checkCurrentPatchSetEntity() {
try { try {
currPs = psUtil.current(db.get(), notes); currPs = psUtil.current(notes);
if (currPs == null) { if (currPs == null) {
problem( problem(
String.format("Current patch set %d not found", change().currentPatchSetId().get())); String.format("Current patch set %d not found", change().currentPatchSetId().get()));
@@ -258,7 +258,7 @@ public class ConsistencyChecker {
List<PatchSet> all; List<PatchSet> all;
try { try {
// Iterate in descending order. // Iterate in descending order.
all = PS_ID_ORDER.sortedCopy(psUtil.byChange(db.get(), notes)); all = PS_ID_ORDER.sortedCopy(psUtil.byChange(notes));
} catch (OrmException e) { } catch (OrmException e) {
return error("Failed to look up patch sets", e); return error("Failed to look up patch sets", e);
} }
@@ -705,7 +705,7 @@ public class ConsistencyChecker {
// Doesn't make any assumptions about the order in which deletes happen // Doesn't make any assumptions about the order in which deletes happen
// and whether they are seen by this op; we are already given the full set // and whether they are seen by this op; we are already given the full set
// of patch sets that will eventually be deleted in this update. // of patch sets that will eventually be deleted in this update.
for (PatchSet ps : psUtil.byChange(ctx.getDb(), ctx.getNotes())) { for (PatchSet ps : psUtil.byChange(ctx.getNotes())) {
if (!toDelete.contains(ps.getId())) { if (!toDelete.contains(ps.getId())) {
all.add(ps.getId()); all.add(ps.getId());
} }
@@ -714,8 +714,7 @@ public class ConsistencyChecker {
throw new NoPatchSetsWouldRemainException(); throw new NoPatchSetsWouldRemainException();
} }
PatchSet.Id latest = ReviewDbUtil.intKeyOrdering().max(all); PatchSet.Id latest = ReviewDbUtil.intKeyOrdering().max(all);
ctx.getChange() ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getNotes(), latest));
.setCurrentPatchSet(patchSetInfoFactory.get(ctx.getDb(), ctx.getNotes(), latest));
return true; return true;
} }
} }

View File

@@ -233,21 +233,14 @@ public class PatchSetInserter implements BatchUpdateOp {
List<String> newGroups = groups; List<String> newGroups = groups;
if (newGroups.isEmpty()) { if (newGroups.isEmpty()) {
PatchSet prevPs = psUtil.current(db, ctx.getNotes()); PatchSet prevPs = psUtil.current(ctx.getNotes());
if (prevPs != null) { if (prevPs != null) {
newGroups = prevPs.getGroups(); newGroups = prevPs.getGroups();
} }
} }
patchSet = patchSet =
psUtil.insert( psUtil.insert(
db, ctx.getRevWalk(), ctx.getUpdate(psId), psId, commitId, newGroups, null, description);
ctx.getRevWalk(),
ctx.getUpdate(psId),
psId,
commitId,
newGroups,
null,
description);
if (notify != NotifyHandling.NONE) { if (notify != NotifyHandling.NONE) {
oldReviewers = approvalsUtil.getReviewers(ctx.getNotes()); oldReviewers = approvalsUtil.getReviewers(ctx.getNotes());

View File

@@ -70,7 +70,7 @@ public class PureRevert {
public PureRevertInfo get(ChangeNotes notes, @Nullable String claimedOriginal) public PureRevertInfo get(ChangeNotes notes, @Nullable String claimedOriginal)
throws OrmException, IOException, BadRequestException, ResourceConflictException { throws OrmException, IOException, BadRequestException, ResourceConflictException {
PatchSet currentPatchSet = psUtil.current(dbProvider.get(), notes); PatchSet currentPatchSet = psUtil.current(notes);
if (currentPatchSet == null) { if (currentPatchSet == null) {
throw new ResourceConflictException("current revision is missing"); throw new ResourceConflictException("current revision is missing");
} }
@@ -81,7 +81,6 @@ public class PureRevert {
} }
PatchSet ps = PatchSet ps =
psUtil.current( psUtil.current(
dbProvider.get(),
notesFactory.createChecked( notesFactory.createChecked(
dbProvider.get(), notes.getProjectName(), notes.getChange().getRevertOf())); dbProvider.get(), notes.getProjectName(), notes.getChange().getRevertOf()));
claimedOriginal = ps.getRevision().get(); claimedOriginal = ps.getRevision().get();

View File

@@ -89,8 +89,6 @@ public class RebaseUtil {
} }
public Base parseBase(RevisionResource rsrc, String base) throws OrmException { public Base parseBase(RevisionResource rsrc, String base) throws OrmException {
ReviewDb db = dbProvider.get();
// Try parsing the base as a ref string. // Try parsing the base as a ref string.
PatchSet.Id basePatchSetId = PatchSet.Id.fromRef(base); PatchSet.Id basePatchSetId = PatchSet.Id.fromRef(base);
if (basePatchSetId != null) { if (basePatchSetId != null) {
@@ -98,8 +96,7 @@ public class RebaseUtil {
ChangeNotes baseNotes = notesFor(rsrc, baseChangeId); ChangeNotes baseNotes = notesFor(rsrc, baseChangeId);
if (baseNotes != null) { if (baseNotes != null) {
return Base.create( return Base.create(
notesFor(rsrc, basePatchSetId.getParentKey()), notesFor(rsrc, basePatchSetId.getParentKey()), psUtil.get(baseNotes, basePatchSetId));
psUtil.get(db, baseNotes, basePatchSetId));
} }
} }
@@ -108,7 +105,7 @@ public class RebaseUtil {
if (baseChangeId != null) { if (baseChangeId != null) {
ChangeNotes baseNotes = notesFor(rsrc, new Change.Id(baseChangeId)); ChangeNotes baseNotes = notesFor(rsrc, new Change.Id(baseChangeId));
if (baseNotes != null) { if (baseNotes != null) {
return Base.create(baseNotes, psUtil.current(db, baseNotes)); return Base.create(baseNotes, psUtil.current(baseNotes));
} }
} }

View File

@@ -123,7 +123,7 @@ public class WorkInProgressOp implements BatchUpdateOp {
public boolean updateChange(ChangeContext ctx) throws OrmException { public boolean updateChange(ChangeContext ctx) throws OrmException {
change = ctx.getChange(); change = ctx.getChange();
notes = ctx.getNotes(); notes = ctx.getNotes();
ps = psUtil.get(ctx.getDb(), ctx.getNotes(), change.currentPatchSetId()); ps = psUtil.get(ctx.getNotes(), change.currentPatchSetId());
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId()); ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
change.setWorkInProgress(workInProgress); change.setWorkInProgress(workInProgress);
if (!change.hasReviewStarted() && !workInProgress) { if (!change.hasReviewStarted() && !workInProgress) {

View File

@@ -457,7 +457,7 @@ public class ChangeEditModifier {
} }
private PatchSet lookupCurrentPatchSet(ChangeNotes notes) throws OrmException { private PatchSet lookupCurrentPatchSet(ChangeNotes notes) throws OrmException {
return patchSetUtil.current(reviewDb.get(), notes); return patchSetUtil.current(notes);
} }
private static boolean isBasedOn(ChangeEdit changeEdit, PatchSet patchSet) { private static boolean isBasedOn(ChangeEdit changeEdit, PatchSet patchSet) {

View File

@@ -238,8 +238,7 @@ public class ChangeEditUtil {
int pos = ref.getName().lastIndexOf('/'); int pos = ref.getName().lastIndexOf('/');
checkArgument(pos > 0, "invalid edit ref: %s", ref.getName()); checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
String psId = ref.getName().substring(pos + 1); String psId = ref.getName().substring(pos + 1);
return psUtil.get( return psUtil.get(notes, new PatchSet.Id(notes.getChange().getId(), Integer.parseInt(psId)));
db.get(), notes, new PatchSet.Id(notes.getChange().getId(), Integer.parseInt(psId)));
} catch (OrmException | NumberFormatException e) { } catch (OrmException | NumberFormatException e) {
throw new IOException(e); throw new IOException(e);
} }

View File

@@ -45,7 +45,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.data.AccountAttribute; import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ApprovalAttribute; import com.google.gerrit.server.data.ApprovalAttribute;
@@ -60,7 +59,6 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@@ -117,7 +115,6 @@ public class StreamEventsApiListener
} }
private final PluginItemContext<EventDispatcher> dispatcher; private final PluginItemContext<EventDispatcher> dispatcher;
private final Provider<ReviewDb> db;
private final EventFactory eventFactory; private final EventFactory eventFactory;
private final ProjectCache projectCache; private final ProjectCache projectCache;
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
@@ -127,14 +124,12 @@ public class StreamEventsApiListener
@Inject @Inject
StreamEventsApiListener( StreamEventsApiListener(
PluginItemContext<EventDispatcher> dispatcher, PluginItemContext<EventDispatcher> dispatcher,
Provider<ReviewDb> db,
EventFactory eventFactory, EventFactory eventFactory,
ProjectCache projectCache, ProjectCache projectCache,
GitRepositoryManager repoManager, GitRepositoryManager repoManager,
PatchSetUtil psUtil, PatchSetUtil psUtil,
ChangeNotes.Factory changeNotesFactory) { ChangeNotes.Factory changeNotesFactory) {
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
this.db = db;
this.eventFactory = eventFactory; this.eventFactory = eventFactory;
this.projectCache = projectCache; this.projectCache = projectCache;
this.repoManager = repoManager; this.repoManager = repoManager;
@@ -151,7 +146,7 @@ public class StreamEventsApiListener
} }
private PatchSet getPatchSet(ChangeNotes notes, RevisionInfo info) throws OrmException { private PatchSet getPatchSet(ChangeNotes notes, RevisionInfo info) throws OrmException {
return psUtil.get(db.get(), notes, PatchSet.Id.fromRef(info.ref)); return psUtil.get(notes, PatchSet.Id.fromRef(info.ref));
} }
private Supplier<ChangeAttribute> changeAttributeSupplier(Change change, ChangeNotes notes) { private Supplier<ChangeAttribute> changeAttributeSupplier(Change change, ChangeNotes notes) {
@@ -311,7 +306,7 @@ public class StreamEventsApiListener
Change change = notes.getChange(); Change change = notes.getChange();
ReviewerDeletedEvent event = new ReviewerDeletedEvent(change); ReviewerDeletedEvent event = new ReviewerDeletedEvent(change);
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.reviewer = accountAttributeSupplier(ev.getReviewer()); event.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho()); event.remover = accountAttributeSupplier(ev.getWho());
event.comment = ev.getComment(); event.comment = ev.getComment();
@@ -332,7 +327,7 @@ public class StreamEventsApiListener
ReviewerAddedEvent event = new ReviewerAddedEvent(change); ReviewerAddedEvent event = new ReviewerAddedEvent(change);
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
for (AccountInfo reviewer : ev.getReviewers()) { for (AccountInfo reviewer : ev.getReviewers()) {
event.reviewer = accountAttributeSupplier(reviewer); event.reviewer = accountAttributeSupplier(reviewer);
dispatcher.run(d -> d.postEvent(event)); dispatcher.run(d -> d.postEvent(event));
@@ -420,7 +415,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.restorer = accountAttributeSupplier(ev.getWho()); event.restorer = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.reason = ev.getReason(); event.reason = ev.getReason();
dispatcher.run(d -> d.postEvent(change, event)); dispatcher.run(d -> d.postEvent(change, event));
@@ -438,7 +433,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.submitter = accountAttributeSupplier(ev.getWho()); event.submitter = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.newRev = ev.getNewRevisionId(); event.newRev = ev.getNewRevisionId();
dispatcher.run(d -> d.postEvent(change, event)); dispatcher.run(d -> d.postEvent(change, event));
@@ -456,7 +451,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.abandoner = accountAttributeSupplier(ev.getWho()); event.abandoner = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.reason = ev.getReason(); event.reason = ev.getReason();
dispatcher.run(d -> d.postEvent(change, event)); dispatcher.run(d -> d.postEvent(change, event));
@@ -509,7 +504,7 @@ public class StreamEventsApiListener
VoteDeletedEvent event = new VoteDeletedEvent(change); VoteDeletedEvent event = new VoteDeletedEvent(change);
event.change = changeAttributeSupplier(change, notes); event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes)); event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.comment = ev.getMessage(); event.comment = ev.getMessage();
event.reviewer = accountAttributeSupplier(ev.getReviewer()); event.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho()); event.remover = accountAttributeSupplier(ev.getWho());

View File

@@ -117,7 +117,7 @@ public class GroupCollector {
public List<String> lookup(PatchSet.Id psId) throws OrmException { public List<String> lookup(PatchSet.Id psId) throws OrmException {
// TODO(dborowitz): Reuse open repository from caller. // TODO(dborowitz): Reuse open repository from caller.
ChangeNotes notes = notesFactory.createChecked(db, project, psId.getParentKey()); ChangeNotes notes = notesFactory.createChecked(db, project, psId.getParentKey());
PatchSet ps = psUtil.get(db, notes, psId); PatchSet ps = psUtil.get(notes, psId);
return ps != null ? ps.getGroups() : null; return ps != null ? ps.getGroups() : null;
} }
}); });

View File

@@ -120,7 +120,7 @@ public class MergedByPushOp implements BatchUpdateOp {
} else { } else {
patchSet = patchSet =
requireNonNull( requireNonNull(
psUtil.get(ctx.getDb(), ctx.getNotes(), psId), psUtil.get(ctx.getNotes(), psId),
() -> String.format("patch set %s not found", psId)); () -> String.format("patch set %s not found", psId));
} }
info = getPatchSetInfo(ctx); info = getPatchSetInfo(ctx);

View File

@@ -2881,7 +2881,7 @@ class ReceiveCommits {
new BatchUpdateOp() { new BatchUpdateOp() {
@Override @Override
public boolean updateChange(ChangeContext ctx) throws OrmException { public boolean updateChange(ChangeContext ctx) throws OrmException {
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
List<String> oldGroups = ps.getGroups(); List<String> oldGroups = ps.getGroups();
if (oldGroups == null) { if (oldGroups == null) {
if (groups == null) { if (groups == null) {
@@ -2890,7 +2890,7 @@ class ReceiveCommits {
} else if (sameGroups(oldGroups, groups)) { } else if (sameGroups(oldGroups, groups)) {
return false; return false;
} }
psUtil.setGroups(ctx.getDb(), ctx.getUpdate(psId), ps, groups); psUtil.setGroups(ctx.getUpdate(psId), ps, groups);
return true; return true;
} }
}); });

View File

@@ -255,7 +255,7 @@ public class ReplaceOp implements BatchUpdateOp {
return false; return false;
} }
if (groups.isEmpty()) { if (groups.isEmpty()) {
PatchSet prevPs = psUtil.current(ctx.getDb(), notes); PatchSet prevPs = psUtil.current(notes);
groups = prevPs != null ? prevPs.getGroups() : ImmutableList.<String>of(); groups = prevPs != null ? prevPs.getGroups() : ImmutableList.<String>of();
} }
@@ -305,7 +305,6 @@ public class ReplaceOp implements BatchUpdateOp {
newPatchSet = newPatchSet =
psUtil.insert( psUtil.insert(
ctx.getDb(),
ctx.getRevWalk(), ctx.getRevWalk(),
update, update,
patchSetId, patchSetId,

View File

@@ -283,7 +283,7 @@ public class MailProcessor {
@Override @Override
public boolean updateChange(ChangeContext ctx) public boolean updateChange(ChangeContext ctx)
throws OrmException, UnprocessableEntityException, PatchListNotAvailableException { throws OrmException, UnprocessableEntityException, PatchListNotAvailableException {
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); patchSet = psUtil.get(ctx.getNotes(), psId);
notes = ctx.getNotes(); notes = ctx.getNotes();
if (patchSet == null) { if (patchSet == null) {
throw new OrmException("patch set not found: " + psId); throw new OrmException("patch set not found: " + psId);
@@ -366,7 +366,6 @@ public class MailProcessor {
ChangeContext ctx, MailComment mailComment, PatchSet current) throws OrmException { ChangeContext ctx, MailComment mailComment, PatchSet current) throws OrmException {
if (mailComment.getInReplyTo() != null) { if (mailComment.getInReplyTo() != null) {
return psUtil.get( return psUtil.get(
ctx.getDb(),
ctx.getNotes(), ctx.getNotes(),
new PatchSet.Id(ctx.getChange().getId(), mailComment.getInReplyTo().key.patchSetId)); new PatchSet.Id(ctx.getChange().getId(), mailComment.getInReplyTo().key.patchSetId));
} }

View File

@@ -159,8 +159,7 @@ public abstract class ChangeEmail extends NotificationEmail {
setHeader(MailHeader.PATCH_SET.fieldName(), patchSet.getPatchSetId() + ""); setHeader(MailHeader.PATCH_SET.fieldName(), patchSet.getPatchSetId() + "");
if (patchSetInfo == null) { if (patchSetInfo == null) {
try { try {
patchSetInfo = patchSetInfo = args.patchSetInfoFactory.get(changeData.notes(), patchSet.getId());
args.patchSetInfoFactory.get(args.db.get(), changeData.notes(), patchSet.getId());
} catch (PatchSetInfoNotAvailableException | OrmException err) { } catch (PatchSetInfoNotAvailableException | OrmException err) {
patchSetInfo = null; patchSetInfo = null;
} }

View File

@@ -200,8 +200,8 @@ public class PatchScriptFactory implements Callable<PatchScript> {
} }
validatePatchSetId(psb); validatePatchSetId(psb);
PatchSet psEntityA = psa != null ? psUtil.get(db, notes, psa) : null; PatchSet psEntityA = psa != null ? psUtil.get(notes, psa) : null;
PatchSet psEntityB = psb.get() == 0 ? new PatchSet(psb) : psUtil.get(db, notes, psb); PatchSet psEntityB = psb.get() == 0 ? new PatchSet(psb) : psUtil.get(notes, psb);
if (psEntityA != null || psEntityB != null) { if (psEntityA != null || psEntityB != null) {
try { try {
permissionBackend.currentUser().change(notes).database(db).check(ChangePermission.READ); permissionBackend.currentUser().change(notes).database(db).check(ChangePermission.READ);
@@ -308,7 +308,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
// proper rename detection between the patch sets. // proper rename detection between the patch sets.
// //
history = new ArrayList<>(); history = new ArrayList<>();
for (PatchSet ps : psUtil.byChange(db, notes)) { for (PatchSet ps : psUtil.byChange(notes)) {
String name = fileName; String name = fileName;
if (psa != null) { if (psa != null) {
switch (changeType) { switch (changeType) {

View File

@@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.client.PatchSetInfo;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RevId; import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.client.UserIdentity; import com.google.gerrit.reviewdb.client.UserIdentity;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.account.Emails; import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
@@ -66,10 +65,10 @@ public class PatchSetInfoFactory {
return info; return info;
} }
public PatchSetInfo get(ReviewDb db, ChangeNotes notes, PatchSet.Id psId) public PatchSetInfo get(ChangeNotes notes, PatchSet.Id psId)
throws PatchSetInfoNotAvailableException { throws PatchSetInfoNotAvailableException {
try { try {
PatchSet patchSet = psUtil.get(db, notes, psId); PatchSet patchSet = psUtil.get(notes, psId);
return get(notes.getProjectName(), patchSet); return get(notes.getProjectName(), patchSet);
} catch (OrmException e) { } catch (OrmException e) {
throw new PatchSetInfoNotAvailableException(e); throw new PatchSetInfoNotAvailableException(e);

View File

@@ -714,7 +714,7 @@ public class ChangeData {
*/ */
public Collection<PatchSet> patchSets() throws OrmException { public Collection<PatchSet> patchSets() throws OrmException {
if (patchSets == null) { if (patchSets == null) {
patchSets = psUtil.byChange(db, notes()); patchSets = psUtil.byChange(notes());
} }
return patchSets; return patchSets;
} }

View File

@@ -187,8 +187,7 @@ public class DeleteDraftComments
for (Comment c : commentsUtil.draftByChangeAuthor(ctx.getNotes(), accountId)) { for (Comment c : commentsUtil.draftByChangeAuthor(ctx.getNotes(), accountId)) {
dirty = true; dirty = true;
PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), c.key.patchSetId); PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), c.key.patchSetId);
setCommentRevId( setCommentRevId(c, patchListCache, ctx.getChange(), psUtil.get(ctx.getNotes(), psId));
c, patchListCache, ctx.getChange(), psUtil.get(ctx.getDb(), ctx.getNotes(), psId));
commentsUtil.deleteComments(ctx.getUpdate(psId), Collections.singleton(c)); commentsUtil.deleteComments(ctx.getUpdate(psId), Collections.singleton(c));
comments.add(commentFormatter.format(c)); comments.add(commentFormatter.format(c));
} }

View File

@@ -18,25 +18,21 @@ import com.google.gerrit.extensions.api.changes.IncludedInInfo;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.ChangeResource; import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.IncludedIn; import com.google.gerrit.server.change.IncludedIn;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
@Singleton @Singleton
public class ChangeIncludedIn implements RestReadView<ChangeResource> { public class ChangeIncludedIn implements RestReadView<ChangeResource> {
private Provider<ReviewDb> db;
private PatchSetUtil psUtil; private PatchSetUtil psUtil;
private IncludedIn includedIn; private IncludedIn includedIn;
@Inject @Inject
ChangeIncludedIn(Provider<ReviewDb> db, PatchSetUtil psUtil, IncludedIn includedIn) { ChangeIncludedIn(PatchSetUtil psUtil, IncludedIn includedIn) {
this.db = db;
this.psUtil = psUtil; this.psUtil = psUtil;
this.includedIn = includedIn; this.includedIn = includedIn;
} }
@@ -44,7 +40,7 @@ public class ChangeIncludedIn implements RestReadView<ChangeResource> {
@Override @Override
public IncludedInInfo apply(ChangeResource rsrc) public IncludedInInfo apply(ChangeResource rsrc)
throws RestApiException, OrmException, IOException { throws RestApiException, OrmException, IOException {
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes()); PatchSet ps = psUtil.current(rsrc.getNotes());
return includedIn.apply(rsrc.getProject(), ps.getRevision().get()); return includedIn.apply(rsrc.getProject(), ps.getRevision().get());
} }
} }

View File

@@ -225,7 +225,7 @@ public class CreateChange
} catch (AuthException e) { } catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + input.baseChange); throw new UnprocessableEntityException("Read not permitted for " + input.baseChange);
} }
PatchSet ps = psUtil.current(db.get(), change); PatchSet ps = psUtil.current(change);
parentCommit = ObjectId.fromString(ps.getRevision().get()); parentCommit = ObjectId.fromString(ps.getRevision().get());
groups = ps.getGroups(); groups = ps.getGroups();
} else if (input.baseCommit != null) { } else if (input.baseCommit != null) {

View File

@@ -112,7 +112,7 @@ public class CreateDraftComment
public boolean updateChange(ChangeContext ctx) public boolean updateChange(ChangeContext ctx)
throws ResourceNotFoundException, OrmException, UnprocessableEntityException, throws ResourceNotFoundException, OrmException, UnprocessableEntityException,
PatchListNotAvailableException { PatchListNotAvailableException {
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
if (ps == null) { if (ps == null) {
throw new ResourceNotFoundException("patch set not found: " + psId); throw new ResourceNotFoundException("patch set not found: " + psId);
} }

View File

@@ -141,7 +141,7 @@ public class CreateMergePatchSet
} }
in.baseChange = Strings.nullToEmpty(in.baseChange).trim(); in.baseChange = Strings.nullToEmpty(in.baseChange).trim();
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes()); PatchSet ps = psUtil.current(rsrc.getNotes());
Change change = rsrc.getChange(); Change change = rsrc.getChange();
Project.NameKey project = change.getProject(); Project.NameKey project = change.getProject();
Branch.NameKey dest = change.getDest(); Branch.NameKey dest = change.getDest();
@@ -216,7 +216,7 @@ public class CreateMergePatchSet
} catch (AuthException e) { } catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + baseChange); throw new UnprocessableEntityException("Read not permitted for " + baseChange);
} }
return psUtil.current(db.get(), change); return psUtil.current(change);
} }
private RevCommit createMergeCommit( private RevCommit createMergeCommit(

View File

@@ -70,7 +70,7 @@ class DeleteChangeOp implements BatchUpdateOp {
checkState(id == null, "cannot reuse DeleteChangeOp"); checkState(id == null, "cannot reuse DeleteChangeOp");
id = ctx.getChange().getId(); id = ctx.getChange().getId();
Collection<PatchSet> patchSets = psUtil.byChange(ctx.getDb(), ctx.getNotes()); Collection<PatchSet> patchSets = psUtil.byChange(ctx.getNotes());
ensureDeletable(ctx, id, patchSets); ensureDeletable(ctx, id, patchSets);
// Cleaning up is only possible as long as the change and its elements are // Cleaning up is only possible as long as the change and its elements are

View File

@@ -96,7 +96,7 @@ public class DeleteDraftComment
return false; // Nothing to do. return false; // Nothing to do.
} }
PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), key.patchSetId); PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), key.patchSetId);
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
if (ps == null) { if (ps == null) {
throw new ResourceNotFoundException("patch set not found: " + psId); throw new ResourceNotFoundException("patch set not found: " + psId);
} }

View File

@@ -129,7 +129,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
currChange = ctx.getChange(); currChange = ctx.getChange();
currPs = psUtil.current(ctx.getDb(), ctx.getNotes()); currPs = psUtil.current(ctx.getNotes());
LabelTypes labelTypes = projectCache.checkedGet(ctx.getProject()).getLabelTypes(ctx.getNotes()); LabelTypes labelTypes = projectCache.checkedGet(ctx.getProject()).getLabelTypes(ctx.getNotes());
// removing a reviewer will remove all her votes // removing a reviewer will remove all her votes

View File

@@ -169,7 +169,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
PermissionBackendException { PermissionBackendException {
change = ctx.getChange(); change = ctx.getChange();
PatchSet.Id psId = change.currentPatchSetId(); PatchSet.Id psId = change.currentPatchSetId();
ps = psUtil.current(db.get(), ctx.getNotes()); ps = psUtil.current(ctx.getNotes());
boolean found = false; boolean found = false;
LabelTypes labelTypes = projectState.getLabelTypes(ctx.getNotes()); LabelTypes labelTypes = projectState.getLabelTypes(ctx.getNotes());

View File

@@ -34,7 +34,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.AccountPatchReviewStore; import com.google.gerrit.server.change.AccountPatchReviewStore;
@@ -114,7 +113,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
@Option(name = "-q") @Option(name = "-q")
String query; String query;
private final Provider<ReviewDb> db;
private final Provider<CurrentUser> self; private final Provider<CurrentUser> self;
private final FileInfoJson fileInfoJson; private final FileInfoJson fileInfoJson;
private final Revisions revisions; private final Revisions revisions;
@@ -125,7 +123,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
@Inject @Inject
ListFiles( ListFiles(
Provider<ReviewDb> db,
Provider<CurrentUser> self, Provider<CurrentUser> self,
FileInfoJson fileInfoJson, FileInfoJson fileInfoJson,
Revisions revisions, Revisions revisions,
@@ -133,7 +130,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
PatchListCache patchListCache, PatchListCache patchListCache,
PatchSetUtil psUtil, PatchSetUtil psUtil,
PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore) { PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore) {
this.db = db;
this.self = self; this.self = self;
this.fileInfoJson = fileInfoJson; this.fileInfoJson = fileInfoJson;
this.revisions = revisions; this.revisions = revisions;
@@ -268,7 +264,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
RevWalk rw = new RevWalk(reader); RevWalk rw = new RevWalk(reader);
TreeWalk tw = new TreeWalk(reader)) { TreeWalk tw = new TreeWalk(reader)) {
Change change = resource.getChange(); Change change = resource.getChange();
PatchSet patchSet = psUtil.get(db.get(), resource.getNotes(), old); PatchSet patchSet = psUtil.get(resource.getNotes(), old);
if (patchSet == null) { if (patchSet == null) {
throw new PatchListNotAvailableException( throw new PatchListNotAvailableException(
String.format( String.format(

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.FileContentUtil; import com.google.gerrit.server.change.FileContentUtil;
import com.google.gerrit.server.change.FileResource; import com.google.gerrit.server.change.FileResource;
@@ -33,7 +32,6 @@ import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@@ -43,7 +41,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
public class GetContent implements RestReadView<FileResource> { public class GetContent implements RestReadView<FileResource> {
private final Provider<ReviewDb> db;
private final GitRepositoryManager gitManager; private final GitRepositoryManager gitManager;
private final PatchSetUtil psUtil; private final PatchSetUtil psUtil;
private final FileContentUtil fileContentUtil; private final FileContentUtil fileContentUtil;
@@ -54,12 +51,10 @@ public class GetContent implements RestReadView<FileResource> {
@Inject @Inject
GetContent( GetContent(
Provider<ReviewDb> db,
GitRepositoryManager gitManager, GitRepositoryManager gitManager,
PatchSetUtil psUtil, PatchSetUtil psUtil,
FileContentUtil fileContentUtil, FileContentUtil fileContentUtil,
ProjectCache projectCache) { ProjectCache projectCache) {
this.db = db;
this.gitManager = gitManager; this.gitManager = gitManager;
this.psUtil = psUtil; this.psUtil = psUtil;
this.fileContentUtil = fileContentUtil; this.fileContentUtil = fileContentUtil;
@@ -90,7 +85,7 @@ public class GetContent implements RestReadView<FileResource> {
private String getMessage(ChangeNotes notes) throws OrmException, IOException { private String getMessage(ChangeNotes notes) throws OrmException, IOException {
Change.Id changeId = notes.getChangeId(); Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes); PatchSet ps = psUtil.current(notes);
if (ps == null) { if (ps == null) {
throw new NoSuchChangeException(changeId); throw new NoSuchChangeException(changeId);
} }
@@ -106,7 +101,7 @@ public class GetContent implements RestReadView<FileResource> {
private byte[] getMergeList(ChangeNotes notes) throws OrmException, IOException { private byte[] getMergeList(ChangeNotes notes) throws OrmException, IOException {
Change.Id changeId = notes.getChangeId(); Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes); PatchSet ps = psUtil.current(notes);
if (ps == null) { if (ps == null) {
throw new NoSuchChangeException(changeId); throw new NoSuchChangeException(changeId);
} }

View File

@@ -27,7 +27,6 @@ import com.google.gerrit.index.IndexConfig;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CommonConverters; import com.google.gerrit.server.CommonConverters;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.change.RevisionResource;
@@ -50,7 +49,6 @@ import org.eclipse.jgit.revwalk.RevCommit;
@Singleton @Singleton
public class GetRelated implements RestReadView<RevisionResource> { public class GetRelated implements RestReadView<RevisionResource> {
private final Provider<ReviewDb> db;
private final Provider<InternalChangeQuery> queryProvider; private final Provider<InternalChangeQuery> queryProvider;
private final PatchSetUtil psUtil; private final PatchSetUtil psUtil;
private final RelatedChangesSorter sorter; private final RelatedChangesSorter sorter;
@@ -58,12 +56,10 @@ public class GetRelated implements RestReadView<RevisionResource> {
@Inject @Inject
GetRelated( GetRelated(
Provider<ReviewDb> db,
Provider<InternalChangeQuery> queryProvider, Provider<InternalChangeQuery> queryProvider,
PatchSetUtil psUtil, PatchSetUtil psUtil,
RelatedChangesSorter sorter, RelatedChangesSorter sorter,
IndexConfig indexConfig) { IndexConfig indexConfig) {
this.db = db;
this.queryProvider = queryProvider; this.queryProvider = queryProvider;
this.psUtil = psUtil; this.psUtil = psUtil;
this.sorter = sorter; this.sorter = sorter;
@@ -81,7 +77,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
private List<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc) private List<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc)
throws OrmException, IOException, PermissionBackendException { throws OrmException, IOException, PermissionBackendException {
Set<String> groups = getAllGroups(rsrc.getNotes(), db.get(), psUtil); Set<String> groups = getAllGroups(rsrc.getNotes(), psUtil);
if (groups.isEmpty()) { if (groups.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -125,13 +121,9 @@ public class GetRelated implements RestReadView<RevisionResource> {
} }
@VisibleForTesting @VisibleForTesting
public static Set<String> getAllGroups(ChangeNotes notes, ReviewDb db, PatchSetUtil psUtil) public static Set<String> getAllGroups(ChangeNotes notes, PatchSetUtil psUtil)
throws OrmException { throws OrmException {
return psUtil return psUtil.byChange(notes).stream().flatMap(ps -> ps.getGroups().stream()).collect(toSet());
.byChange(db, notes)
.stream()
.flatMap(ps -> ps.getGroups().stream())
.collect(toSet());
} }
private void reloadChangeIfStale(List<ChangeData> cds, PatchSet wantedPs) throws OrmException { private void reloadChangeIfStale(List<ChangeData> cds, PatchSet wantedPs) throws OrmException {

View File

@@ -202,8 +202,7 @@ public class Move extends RetryingRestModifyView<ChangeResource, MoveInput, Chan
RevWalk revWalk = new RevWalk(repo)) { RevWalk revWalk = new RevWalk(repo)) {
RevCommit currPatchsetRevCommit = RevCommit currPatchsetRevCommit =
revWalk.parseCommit( revWalk.parseCommit(
ObjectId.fromString( ObjectId.fromString(psUtil.current(ctx.getNotes()).getRevision().get()));
psUtil.current(ctx.getDb(), ctx.getNotes()).getRevision().get()));
if (currPatchsetRevCommit.getParentCount() > 1) { if (currPatchsetRevCommit.getParentCount() > 1) {
throw new ResourceConflictException("Merge commit cannot be moved"); throw new ResourceConflictException("Merge commit cannot be moved");
} }

View File

@@ -896,7 +896,7 @@ public class PostReview
PatchListNotAvailableException { PatchListNotAvailableException {
user = ctx.getIdentifiedUser(); user = ctx.getIdentifiedUser();
notes = ctx.getNotes(); notes = ctx.getNotes();
ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); ps = psUtil.get(ctx.getNotes(), psId);
boolean dirty = false; boolean dirty = false;
dirty |= insertComments(ctx); dirty |= insertComments(ctx);
dirty |= insertRobotComments(ctx); dirty |= insertRobotComments(ctx);

View File

@@ -93,7 +93,7 @@ public class PutDescription
@Override @Override
public boolean updateChange(ChangeContext ctx) throws OrmException { public boolean updateChange(ChangeContext ctx) throws OrmException {
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
newDescription = Strings.nullToEmpty(input.description); newDescription = Strings.nullToEmpty(input.description);
oldDescription = Strings.nullToEmpty(ps.getDescription()); oldDescription = Strings.nullToEmpty(ps.getDescription());

View File

@@ -133,7 +133,7 @@ public class PutDraftComment
PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), origComment.key.patchSetId); PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), origComment.key.patchSetId);
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
if (ps == null) { if (ps == null) {
throw new ResourceNotFoundException("patch set not found: " + psId); throw new ResourceNotFoundException("patch set not found: " + psId);
} }

View File

@@ -105,7 +105,7 @@ public class PutMessage
BatchUpdate.Factory updateFactory, ChangeResource resource, CommitMessageInput input) BatchUpdate.Factory updateFactory, ChangeResource resource, CommitMessageInput input)
throws IOException, RestApiException, UpdateException, PermissionBackendException, throws IOException, RestApiException, UpdateException, PermissionBackendException,
OrmException, ConfigInvalidException { OrmException, ConfigInvalidException {
PatchSet ps = psUtil.current(db.get(), resource.getNotes()); PatchSet ps = psUtil.current(resource.getNotes());
if (ps == null) { if (ps == null) {
throw new ResourceConflictException("current revision is missing"); throw new ResourceConflictException("current revision is missing");
} }

View File

@@ -273,7 +273,7 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
BatchUpdate.Factory updateFactory, ChangeResource rsrc, RebaseInput input) BatchUpdate.Factory updateFactory, ChangeResource rsrc, RebaseInput input)
throws OrmException, UpdateException, RestApiException, IOException, throws OrmException, UpdateException, RestApiException, IOException,
PermissionBackendException { PermissionBackendException {
PatchSet ps = psUtil.current(rebase.dbProvider.get(), rsrc.getNotes()); PatchSet ps = psUtil.current(rsrc.getNotes());
if (ps == null) { if (ps == null) {
throw new ResourceConflictException("current revision is missing"); throw new ResourceConflictException("current revision is missing");
} }

View File

@@ -124,7 +124,7 @@ public class Restore extends RetryingRestModifyView<ChangeResource, RestoreInput
} }
PatchSet.Id psId = change.currentPatchSetId(); PatchSet.Id psId = change.currentPatchSetId();
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); patchSet = psUtil.get(ctx.getNotes(), psId);
change.setStatus(Status.NEW); change.setStatus(Status.NEW);
change.setLastUpdatedOn(ctx.getWhen()); change.setLastUpdatedOn(ctx.getWhen());
update.setStatus(change.getStatus()); update.setStatus(change.getStatus());

View File

@@ -168,7 +168,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
String message = Strings.emptyToNull(input.message); String message = Strings.emptyToNull(input.message);
Change.Id changeIdToRevert = notes.getChangeId(); Change.Id changeIdToRevert = notes.getChangeId();
PatchSet.Id patchSetId = notes.getChange().currentPatchSetId(); PatchSet.Id patchSetId = notes.getChange().currentPatchSetId();
PatchSet patch = psUtil.get(db.get(), notes, patchSetId); PatchSet patch = psUtil.get(notes, patchSetId);
if (patch == null) { if (patch == null) {
throw new ResourceNotFoundException(changeIdToRevert.toString()); throw new ResourceNotFoundException(changeIdToRevert.toString());
} }

View File

@@ -85,7 +85,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
throws ResourceNotFoundException, AuthException, OrmException, IOException, throws ResourceNotFoundException, AuthException, OrmException, IOException,
PermissionBackendException { PermissionBackendException {
if (id.get().equals("current")) { if (id.get().equals("current")) {
PatchSet ps = psUtil.current(dbProvider.get(), change.getNotes()); PatchSet ps = psUtil.current(change.getNotes());
if (ps != null && visible(change)) { if (ps != null && visible(change)) {
return RevisionResource.createNonCachable(change, ps); return RevisionResource.createNonCachable(change, ps);
} }
@@ -135,7 +135,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
return Collections.emptyList(); return Collections.emptyList();
} else { } else {
List<RevisionResource> out = new ArrayList<>(); List<RevisionResource> out = new ArrayList<>();
for (PatchSet ps : psUtil.byChange(dbProvider.get(), change.getNotes())) { for (PatchSet ps : psUtil.byChange(change.getNotes())) {
if (ps.getRevision() != null && ps.getRevision().get().startsWith(id)) { if (ps.getRevision() != null && ps.getRevision().get().startsWith(id)) {
out.add(new RevisionResource(change, ps)); out.add(new RevisionResource(change, ps));
} }
@@ -151,10 +151,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
private List<RevisionResource> byLegacyPatchSetId(ChangeResource change, String id) private List<RevisionResource> byLegacyPatchSetId(ChangeResource change, String id)
throws OrmException { throws OrmException {
PatchSet ps = PatchSet ps =
psUtil.get( psUtil.get(change.getNotes(), new PatchSet.Id(change.getId(), Integer.parseInt(id)));
dbProvider.get(),
change.getNotes(),
new PatchSet.Id(change.getId(), Integer.parseInt(id)));
if (ps != null) { if (ps != null) {
return Collections.singletonList(new RevisionResource(change, ps)); return Collections.singletonList(new RevisionResource(change, ps));
} }

View File

@@ -73,7 +73,7 @@ public class SetPrivateOp implements BatchUpdateOp {
public boolean updateChange(ChangeContext ctx) throws ResourceConflictException, OrmException { public boolean updateChange(ChangeContext ctx) throws ResourceConflictException, OrmException {
change = ctx.getChange(); change = ctx.getChange();
ChangeNotes notes = ctx.getNotes(); ChangeNotes notes = ctx.getNotes();
ps = psUtil.get(ctx.getDb(), notes, change.currentPatchSetId()); ps = psUtil.get(notes, change.currentPatchSetId());
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId()); ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
change.setPrivate(isPrivate); change.setPrivate(isPrivate);
change.setLastUpdatedOn(ctx.getWhen()); change.setLastUpdatedOn(ctx.getWhen());

View File

@@ -456,8 +456,7 @@ public class Submit
for (ChangeData change : changes) { for (ChangeData change : changes) {
RevCommit commit = RevCommit commit =
walk.parseCommit( walk.parseCommit(
ObjectId.fromString( ObjectId.fromString(psUtil.current(change.notes()).getRevision().get()));
psUtil.current(dbProvider.get(), change.notes()).getRevision().get()));
commits.put(change.getId(), commit); commits.put(change.getId(), commit);
} }
} }
@@ -495,18 +494,12 @@ public class Submit
} }
public static class CurrentRevision implements RestModifyView<ChangeResource, SubmitInput> { public static class CurrentRevision implements RestModifyView<ChangeResource, SubmitInput> {
private final Provider<ReviewDb> dbProvider;
private final Submit submit; private final Submit submit;
private final ChangeJson.Factory json; private final ChangeJson.Factory json;
private final PatchSetUtil psUtil; private final PatchSetUtil psUtil;
@Inject @Inject
CurrentRevision( CurrentRevision(Submit submit, ChangeJson.Factory json, PatchSetUtil psUtil) {
Provider<ReviewDb> dbProvider,
Submit submit,
ChangeJson.Factory json,
PatchSetUtil psUtil) {
this.dbProvider = dbProvider;
this.submit = submit; this.submit = submit;
this.json = json; this.json = json;
this.psUtil = psUtil; this.psUtil = psUtil;
@@ -516,7 +509,7 @@ public class Submit
public ChangeInfo apply(ChangeResource rsrc, SubmitInput input) public ChangeInfo apply(ChangeResource rsrc, SubmitInput input)
throws RestApiException, RepositoryNotFoundException, IOException, OrmException, throws RestApiException, RepositoryNotFoundException, IOException, OrmException,
PermissionBackendException, UpdateException, ConfigInvalidException { PermissionBackendException, UpdateException, ConfigInvalidException {
PatchSet ps = psUtil.current(dbProvider.get(), rsrc.getNotes()); PatchSet ps = psUtil.current(rsrc.getNotes());
if (ps == null) { if (ps == null) {
throw new ResourceConflictException("current revision is missing"); throw new ResourceConflictException("current revision is missing");
} }

View File

@@ -157,10 +157,9 @@ public class CherryPick extends SubmitStrategy {
String.format( String.format(
"no new commit produced by CherryPick of %s, expected to fail fast", "no new commit produced by CherryPick of %s, expected to fail fast",
toMerge.change().getId())); toMerge.change().getId()));
PatchSet prevPs = args.psUtil.current(ctx.getDb(), ctx.getNotes()); PatchSet prevPs = args.psUtil.current(ctx.getNotes());
PatchSet newPs = PatchSet newPs =
args.psUtil.insert( args.psUtil.insert(
ctx.getDb(),
ctx.getRevWalk(), ctx.getRevWalk(),
ctx.getUpdate(psId), ctx.getUpdate(psId),
psId, psId,

View File

@@ -170,7 +170,7 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
ctx.addRefUpdate(ObjectId.zeroId(), newCommit, newPatchSetId.toRefName()); ctx.addRefUpdate(ObjectId.zeroId(), newCommit, newPatchSetId.toRefName());
} else { } else {
// Stale read of patch set is ok; see comments in RebaseChangeOp. // Stale read of patch set is ok; see comments in RebaseChangeOp.
PatchSet origPs = args.psUtil.get(ctx.getDb(), toMerge.getNotes(), toMerge.getPatchsetId()); PatchSet origPs = args.psUtil.get(toMerge.getNotes(), toMerge.getPatchsetId());
rebaseOp = rebaseOp =
args.rebaseFactory args.rebaseFactory
.create(toMerge.notes(), origPs, args.mergeTip.getCurrentTip()) .create(toMerge.notes(), origPs, args.mergeTip.getCurrentTip())
@@ -227,10 +227,9 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
newPs = rebaseOp.getPatchSet(); newPs = rebaseOp.getPatchSet();
} else { } else {
// CherryPick // CherryPick
PatchSet prevPs = args.psUtil.current(ctx.getDb(), ctx.getNotes()); PatchSet prevPs = args.psUtil.current(ctx.getNotes());
newPs = newPs =
args.psUtil.insert( args.psUtil.insert(
ctx.getDb(),
ctx.getRevWalk(), ctx.getRevWalk(),
ctx.getUpdate(newPatchSetId), ctx.getUpdate(newPatchSetId),
newPatchSetId, newPatchSetId,

View File

@@ -250,7 +250,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
// during the submit strategy. // during the submit strategy.
mergedPatchSet = mergedPatchSet =
requireNonNull( requireNonNull(
args.psUtil.get(ctx.getDb(), ctx.getNotes(), oldPsId), args.psUtil.get(ctx.getNotes(), oldPsId),
() -> String.format("missing old patch set %s", oldPsId)); () -> String.format("missing old patch set %s", oldPsId));
} else { } else {
PatchSet.Id n = newPatchSet.getId(); PatchSet.Id n = newPatchSet.getId();
@@ -300,12 +300,12 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
throws IOException, OrmException { throws IOException, OrmException {
PatchSet.Id psId = alreadyMergedCommit.getPatchsetId(); PatchSet.Id psId = alreadyMergedCommit.getPatchsetId();
logger.atFine().log("Fixing up already-merged patch set %s", psId); logger.atFine().log("Fixing up already-merged patch set %s", psId);
PatchSet prevPs = args.psUtil.current(ctx.getDb(), ctx.getNotes()); PatchSet prevPs = args.psUtil.current(ctx.getNotes());
ctx.getRevWalk().parseBody(alreadyMergedCommit); ctx.getRevWalk().parseBody(alreadyMergedCommit);
ctx.getChange() ctx.getChange()
.setCurrentPatchSet( .setCurrentPatchSet(
psId, alreadyMergedCommit.getShortMessage(), ctx.getChange().getOriginalSubject()); psId, alreadyMergedCommit.getShortMessage(), ctx.getChange().getOriginalSubject());
PatchSet existing = args.psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet existing = args.psUtil.get(ctx.getNotes(), psId);
if (existing != null) { if (existing != null) {
logger.atFine().log("Patch set row exists, only updating change"); logger.atFine().log("Patch set row exists, only updating change");
return existing; return existing;
@@ -316,14 +316,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
List<String> groups = List<String> groups =
prevPs != null ? prevPs.getGroups() : GroupCollector.getDefaultGroups(alreadyMergedCommit); prevPs != null ? prevPs.getGroups() : GroupCollector.getDefaultGroups(alreadyMergedCommit);
return args.psUtil.insert( return args.psUtil.insert(
ctx.getDb(), ctx.getRevWalk(), ctx.getUpdate(psId), psId, alreadyMergedCommit, groups, null, null);
ctx.getRevWalk(),
ctx.getUpdate(psId),
psId,
alreadyMergedCommit,
groups,
null,
null);
} }
private void setApproval(ChangeContext ctx, IdentifiedUser user) private void setApproval(ChangeContext ctx, IdentifiedUser user)

View File

@@ -107,7 +107,7 @@ public class PatchSetParser {
throw error("\"" + token + "\" is not a valid patch set"); throw error("\"" + token + "\" is not a valid patch set");
} }
ChangeNotes notes = getNotes(projectState, patchSetId.getParentKey()); ChangeNotes notes = getNotes(projectState, patchSetId.getParentKey());
PatchSet patchSet = psUtil.get(db.get(), notes, patchSetId); PatchSet patchSet = psUtil.get(notes, patchSetId);
if (patchSet == null) { if (patchSet == null) {
throw error("\"" + token + "\" no such patch set"); throw error("\"" + token + "\" no such patch set");
} }

View File

@@ -160,7 +160,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
public void patchSetRefMissing() throws Exception { public void patchSetRefMissing() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
serverSideTestRepo.update( serverSideTestRepo.update(
"refs/other/foo", ObjectId.fromString(psUtil.current(db, notes).getRevision().get())); "refs/other/foo", ObjectId.fromString(psUtil.current(notes).getRevision().get()));
String refName = notes.getChange().currentPatchSetId().toRefName(); String refName = notes.getChange().currentPatchSetId().toRefName();
deleteRef(refName); deleteRef(refName);
@@ -170,7 +170,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void patchSetRefMissingWithFix() throws Exception { public void patchSetRefMissingWithFix() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
serverSideTestRepo.update("refs/other/foo", ObjectId.fromString(rev)); serverSideTestRepo.update("refs/other/foo", ObjectId.fromString(rev));
String refName = notes.getChange().currentPatchSetId().toRefName(); String refName = notes.getChange().currentPatchSetId().toRefName();
deleteRef(refName); deleteRef(refName);
@@ -184,7 +184,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void patchSetObjectAndRefMissingWithDeletingPatchSet() throws Exception { public void patchSetObjectAndRefMissingWithDeletingPatchSet() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
String rev2 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; String rev2 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
PatchSet ps2 = insertMissingPatchSet(notes, rev2); PatchSet ps2 = insertMissingPatchSet(notes, rev2);
@@ -200,20 +200,20 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(1); assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(1);
assertThat(psUtil.get(db, notes, ps1.getId())).isNotNull(); assertThat(psUtil.get(notes, ps1.getId())).isNotNull();
assertThat(psUtil.get(db, notes, ps2.getId())).isNull(); assertThat(psUtil.get(notes, ps2.getId())).isNull();
} }
@Test @Test
public void patchSetMultipleObjectsMissingWithDeletingPatchSets() throws Exception { public void patchSetMultipleObjectsMissingWithDeletingPatchSets() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
String rev2 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; String rev2 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
PatchSet ps2 = insertMissingPatchSet(notes, rev2); PatchSet ps2 = insertMissingPatchSet(notes, rev2);
notes = incrementPatchSet(reload(notes)); notes = incrementPatchSet(reload(notes));
PatchSet ps3 = psUtil.current(db, notes); PatchSet ps3 = psUtil.current(notes);
String rev4 = "c0ffeeeec0ffeeeec0ffeeeec0ffeeeec0ffeeee"; String rev4 = "c0ffeeeec0ffeeeec0ffeeeec0ffeeeec0ffeeee";
PatchSet ps4 = insertMissingPatchSet(notes, rev4); PatchSet ps4 = insertMissingPatchSet(notes, rev4);
@@ -231,10 +231,10 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(3); assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(3);
assertThat(psUtil.get(db, notes, ps1.getId())).isNotNull(); assertThat(psUtil.get(notes, ps1.getId())).isNotNull();
assertThat(psUtil.get(db, notes, ps2.getId())).isNull(); assertThat(psUtil.get(notes, ps2.getId())).isNull();
assertThat(psUtil.get(db, notes, ps3.getId())).isNotNull(); assertThat(psUtil.get(notes, ps3.getId())).isNotNull();
assertThat(psUtil.get(db, notes, ps4.getId())).isNull(); assertThat(psUtil.get(notes, ps4.getId())).isNull();
} }
@Test @Test
@@ -279,13 +279,13 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(1); assertThat(notes.getChange().currentPatchSetId().get()).isEqualTo(1);
assertThat(psUtil.current(db, notes)).isNotNull(); assertThat(psUtil.current(notes)).isNotNull();
} }
@Test @Test
public void duplicatePatchSetRevisions() throws Exception { public void duplicatePatchSetRevisions() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
String rev = ps1.getRevision().get(); String rev = ps1.getRevision().get();
notes = notes =
@@ -328,7 +328,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
} }
notes = reload(notes); notes = reload(notes);
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
ObjectId tip = getDestRef(notes); ObjectId tip = getDestRef(notes);
assertProblems( assertProblems(
notes, notes,
@@ -345,7 +345,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void newChangeIsMerged() throws Exception { public void newChangeIsMerged() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
serverSideTestRepo serverSideTestRepo
.branch(notes.getChange().getDest().get()) .branch(notes.getChange().getDest().get())
.update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev))); .update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)));
@@ -365,7 +365,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void newChangeIsMergedWithFix() throws Exception { public void newChangeIsMergedWithFix() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
serverSideTestRepo serverSideTestRepo
.branch(notes.getChange().getDest().get()) .branch(notes.getChange().getDest().get())
.update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev))); .update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)));
@@ -391,7 +391,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void extensionApiReturnsUpdatedValueAfterFix() throws Exception { public void extensionApiReturnsUpdatedValueAfterFix() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
serverSideTestRepo serverSideTestRepo
.branch(notes.getChange().getDest().get()) .branch(notes.getChange().getDest().get())
.update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev))); .update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)));
@@ -406,7 +406,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void expectedMergedCommitIsLatestPatchSet() throws Exception { public void expectedMergedCommitIsLatestPatchSet() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
serverSideTestRepo serverSideTestRepo
.branch(notes.getChange().getDest().get()) .branch(notes.getChange().getDest().get())
.update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev))); .update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)));
@@ -434,7 +434,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void expectedMergedCommitNotMergedIntoDestination() throws Exception { public void expectedMergedCommitNotMergedIntoDestination() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)); RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev));
serverSideTestRepo.branch(notes.getChange().getDest().get()).update(commit); serverSideTestRepo.branch(notes.getChange().getDest().get()).update(commit);
@@ -457,7 +457,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
public void createNewPatchSetForExpectedMergeCommitWithNoChangeId() throws Exception { public void createNewPatchSetForExpectedMergeCommitWithNoChangeId() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String dest = notes.getChange().getDest().get(); String dest = notes.getChange().getDest().get();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)); RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev));
RevCommit mergedAs = RevCommit mergedAs =
@@ -489,7 +489,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2); PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(psUtil.get(db, notes, psId2).getRevision().get()).isEqualTo(mergedAs.name()); assertThat(psUtil.get(notes, psId2).getRevision().get()).isEqualTo(mergedAs.name());
assertNoProblems(notes, null); assertNoProblems(notes, null);
} }
@@ -498,7 +498,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
public void createNewPatchSetForExpectedMergeCommitWithChangeId() throws Exception { public void createNewPatchSetForExpectedMergeCommitWithChangeId() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String dest = notes.getChange().getDest().get(); String dest = notes.getChange().getDest().get();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)); RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev));
RevCommit mergedAs = RevCommit mergedAs =
@@ -537,7 +537,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2); PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(psUtil.get(db, notes, psId2).getRevision().get()).isEqualTo(mergedAs.name()); assertThat(psUtil.get(notes, psId2).getRevision().get()).isEqualTo(mergedAs.name());
assertNoProblems(notes, null); assertNoProblems(notes, null);
} }
@@ -545,10 +545,10 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception { public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
String rev1 = ps1.getRevision().get(); String rev1 = ps1.getRevision().get();
notes = incrementPatchSet(notes); notes = incrementPatchSet(notes);
PatchSet ps2 = psUtil.current(db, notes); PatchSet ps2 = psUtil.current(notes);
serverSideTestRepo serverSideTestRepo
.branch(notes.getChange().getDest().get()) .branch(notes.getChange().getDest().get())
.update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev1))); .update(serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev1)));
@@ -578,14 +578,14 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
PatchSet.Id psId3 = new PatchSet.Id(notes.getChangeId(), 3); PatchSet.Id psId3 = new PatchSet.Id(notes.getChangeId(), 3);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(ps2.getId(), psId3); assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps2.getId(), psId3);
assertThat(psUtil.get(db, notes, psId3).getRevision().get()).isEqualTo(rev1); assertThat(psUtil.get(notes, psId3).getRevision().get()).isEqualTo(rev1);
} }
@Test @Test
public void expectedMergedCommitIsDanglingPatchSetOlderThanCurrent() throws Exception { public void expectedMergedCommitIsDanglingPatchSetOlderThanCurrent() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
// Create dangling ref so next ID in the database becomes 3. // Create dangling ref so next ID in the database becomes 3.
PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2); PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2);
@@ -594,7 +594,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
serverSideTestRepo.branch(psId2.toRefName()).update(commit2); serverSideTestRepo.branch(psId2.toRefName()).update(commit2);
notes = incrementPatchSet(notes); notes = incrementPatchSet(notes);
PatchSet ps3 = psUtil.current(db, notes); PatchSet ps3 = psUtil.current(notes);
assertThat(ps3.getId().get()).isEqualTo(3); assertThat(ps3.getId().get()).isEqualTo(3);
serverSideTestRepo serverSideTestRepo
@@ -626,15 +626,15 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
PatchSet.Id psId4 = new PatchSet.Id(notes.getChangeId(), 4); PatchSet.Id psId4 = new PatchSet.Id(notes.getChangeId(), 4);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId4); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId4);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()) assertThat(psUtil.byChangeAsMap(notes).keySet())
.containsExactly(ps1.getId(), ps3.getId(), psId4); .containsExactly(ps1.getId(), ps3.getId(), psId4);
assertThat(psUtil.get(db, notes, psId4).getRevision().get()).isEqualTo(rev2); assertThat(psUtil.get(notes, psId4).getRevision().get()).isEqualTo(rev2);
} }
@Test @Test
public void expectedMergedCommitIsDanglingPatchSetNewerThanCurrent() throws Exception { public void expectedMergedCommitIsDanglingPatchSetNewerThanCurrent() throws Exception {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(db, notes); PatchSet ps1 = psUtil.current(notes);
// Create dangling ref with no patch set. // Create dangling ref with no patch set.
PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2); PatchSet.Id psId2 = new PatchSet.Id(notes.getChangeId(), 2);
@@ -663,8 +663,8 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(ps1.getId(), psId2); assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps1.getId(), psId2);
assertThat(psUtil.get(db, notes, psId2).getRevision().get()).isEqualTo(rev2); assertThat(psUtil.get(notes, psId2).getRevision().get()).isEqualTo(rev2);
} }
@Test @Test
@@ -672,7 +672,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
ChangeNotes notes = insertChange(); ChangeNotes notes = insertChange();
String dest = notes.getChange().getDest().get(); String dest = notes.getChange().getDest().get();
RevCommit parent = serverSideTestRepo.branch(dest).commit().message("parent").create(); RevCommit parent = serverSideTestRepo.branch(dest).commit().message("parent").create();
String rev = psUtil.current(db, notes).getRevision().get(); String rev = psUtil.current(notes).getRevision().get();
RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)); RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev));
serverSideTestRepo.branch(dest).update(commit); serverSideTestRepo.branch(dest).update(commit);
@@ -706,19 +706,19 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
@Test @Test
public void expectedMergedCommitMatchesMultiplePatchSets() throws Exception { public void expectedMergedCommitMatchesMultiplePatchSets() throws Exception {
ChangeNotes notes1 = insertChange(); ChangeNotes notes1 = insertChange();
PatchSet.Id psId1 = psUtil.current(db, notes1).getId(); PatchSet.Id psId1 = psUtil.current(notes1).getId();
String dest = notes1.getChange().getDest().get(); String dest = notes1.getChange().getDest().get();
String rev = psUtil.current(db, notes1).getRevision().get(); String rev = psUtil.current(notes1).getRevision().get();
RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev)); RevCommit commit = serverSideTestRepo.getRevWalk().parseCommit(ObjectId.fromString(rev));
serverSideTestRepo.branch(dest).update(commit); serverSideTestRepo.branch(dest).update(commit);
ChangeNotes notes2 = insertChange(); ChangeNotes notes2 = insertChange();
notes2 = incrementPatchSet(notes2, commit); notes2 = incrementPatchSet(notes2, commit);
PatchSet.Id psId2 = psUtil.current(db, notes2).getId(); PatchSet.Id psId2 = psUtil.current(notes2).getId();
ChangeNotes notes3 = insertChange(); ChangeNotes notes3 = insertChange();
notes3 = incrementPatchSet(notes3, commit); notes3 = incrementPatchSet(notes3, commit);
PatchSet.Id psId3 = psUtil.current(db, notes3).getId(); PatchSet.Id psId3 = psUtil.current(notes3).getId();
FixInput fix = new FixInput(); FixInput fix = new FixInput();
fix.expectMergedAs = commit.name(); fix.expectMergedAs = commit.name();
@@ -863,7 +863,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
private ChangeNotes mergeChange(ChangeNotes notes) throws Exception { private ChangeNotes mergeChange(ChangeNotes notes) throws Exception {
final ObjectId oldId = getDestRef(notes); final ObjectId oldId = getDestRef(notes);
final ObjectId newId = ObjectId.fromString(psUtil.current(db, notes).getRevision().get()); final ObjectId newId = ObjectId.fromString(psUtil.current(notes).getRevision().get());
final String dest = notes.getChange().getDest().get(); final String dest = notes.getChange().getDest().get();
try (BatchUpdate bu = newUpdate(adminId)) { try (BatchUpdate bu = newUpdate(adminId)) {

View File

@@ -572,7 +572,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
ChangeData cd = getChange(last); ChangeData cd = getChange(last);
assertThat(cd.patchSets()).hasSize(n); assertThat(cd.patchSets()).hasSize(n);
assertThat(GetRelated.getAllGroups(cd.notes(), db, psUtil)).hasSize(n); assertThat(GetRelated.getAllGroups(cd.notes(), psUtil)).hasSize(n);
assertRelated(cd.change().currentPatchSetId()); assertRelated(cd.change().currentPatchSetId());
} }
@@ -610,8 +610,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
new BatchUpdateOp() { new BatchUpdateOp() {
@Override @Override
public boolean updateChange(ChangeContext ctx) throws OrmException { public boolean updateChange(ChangeContext ctx) throws OrmException {
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId); PatchSet ps = psUtil.get(ctx.getNotes(), psId);
psUtil.setGroups(ctx.getDb(), ctx.getUpdate(psId), ps, ImmutableList.<String>of()); psUtil.setGroups(ctx.getUpdate(psId), ps, ImmutableList.<String>of());
ctx.dontBumpLastUpdatedOn(); ctx.dontBumpLastUpdatedOn();
return true; return true;
} }

View File

@@ -2280,7 +2280,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
Change change = insert(repo, newChange(repo)); Change change = insert(repo, newChange(repo));
String changeId = change.getKey().get(); String changeId = change.getKey().get();
ChangeNotes notes = notesFactory.create(db, change.getProject(), change.getId()); ChangeNotes notes = notesFactory.create(db, change.getProject(), change.getId());
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId()); PatchSet ps = psUtil.get(notes, change.currentPatchSetId());
requestContext.setContext(newRequestContext(user)); requestContext.setContext(newRequestContext(user));
gApi.changes().id(changeId).edit().create(); gApi.changes().id(changeId).edit().create();