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;
}
} else {
PatchSet patchSet = psUtil.get(requestDb.get(), notes, patchKey.getParentKey());
PatchSet patchSet = psUtil.get(notes, patchKey.getParentKey());
if (patchSet == null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;

View File

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

View File

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

View File

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

View File

@@ -99,7 +99,7 @@ public class AbandonOp implements BatchUpdateOp {
if (!change.getStatus().isOpen()) {
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.setLastUpdatedOn(ctx.getWhen());

View File

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

View File

@@ -412,14 +412,7 @@ public class ChangeInserter implements InsertChangeOp {
}
patchSet =
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
* (byStatusClosed() in AbstractQueryChangesTest)

View File

@@ -154,11 +154,7 @@ public class ChangeResource implements RestResource, HasETag {
accounts.add(getChange().getAssignee());
}
try {
patchSetUtil
.byChange(db.get(), notes)
.stream()
.map(PatchSet::getUploader)
.forEach(accounts::add);
patchSetUtil.byChange(notes).stream().map(PatchSet::getUploader).forEach(accounts::add);
// 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.

View File

@@ -230,7 +230,7 @@ public class ConsistencyChecker {
private void checkCurrentPatchSetEntity() {
try {
currPs = psUtil.current(db.get(), notes);
currPs = psUtil.current(notes);
if (currPs == null) {
problem(
String.format("Current patch set %d not found", change().currentPatchSetId().get()));
@@ -258,7 +258,7 @@ public class ConsistencyChecker {
List<PatchSet> all;
try {
// 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) {
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
// 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.
for (PatchSet ps : psUtil.byChange(ctx.getDb(), ctx.getNotes())) {
for (PatchSet ps : psUtil.byChange(ctx.getNotes())) {
if (!toDelete.contains(ps.getId())) {
all.add(ps.getId());
}
@@ -714,8 +714,7 @@ public class ConsistencyChecker {
throw new NoPatchSetsWouldRemainException();
}
PatchSet.Id latest = ReviewDbUtil.intKeyOrdering().max(all);
ctx.getChange()
.setCurrentPatchSet(patchSetInfoFactory.get(ctx.getDb(), ctx.getNotes(), latest));
ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getNotes(), latest));
return true;
}
}

View File

@@ -233,21 +233,14 @@ public class PatchSetInserter implements BatchUpdateOp {
List<String> newGroups = groups;
if (newGroups.isEmpty()) {
PatchSet prevPs = psUtil.current(db, ctx.getNotes());
PatchSet prevPs = psUtil.current(ctx.getNotes());
if (prevPs != null) {
newGroups = prevPs.getGroups();
}
}
patchSet =
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) {
oldReviewers = approvalsUtil.getReviewers(ctx.getNotes());

View File

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

View File

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

View File

@@ -457,7 +457,7 @@ public class ChangeEditModifier {
}
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) {

View File

@@ -238,8 +238,7 @@ public class ChangeEditUtil {
int pos = ref.getName().lastIndexOf('/');
checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
String psId = ref.getName().substring(pos + 1);
return psUtil.get(
db.get(), notes, new PatchSet.Id(notes.getChange().getId(), Integer.parseInt(psId)));
return psUtil.get(notes, new PatchSet.Id(notes.getChange().getId(), Integer.parseInt(psId)));
} catch (OrmException | NumberFormatException 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.Change;
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.data.AccountAttribute;
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.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.Collection;
@@ -117,7 +115,6 @@ public class StreamEventsApiListener
}
private final PluginItemContext<EventDispatcher> dispatcher;
private final Provider<ReviewDb> db;
private final EventFactory eventFactory;
private final ProjectCache projectCache;
private final GitRepositoryManager repoManager;
@@ -127,14 +124,12 @@ public class StreamEventsApiListener
@Inject
StreamEventsApiListener(
PluginItemContext<EventDispatcher> dispatcher,
Provider<ReviewDb> db,
EventFactory eventFactory,
ProjectCache projectCache,
GitRepositoryManager repoManager,
PatchSetUtil psUtil,
ChangeNotes.Factory changeNotesFactory) {
this.dispatcher = dispatcher;
this.db = db;
this.eventFactory = eventFactory;
this.projectCache = projectCache;
this.repoManager = repoManager;
@@ -151,7 +146,7 @@ public class StreamEventsApiListener
}
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) {
@@ -311,7 +306,7 @@ public class StreamEventsApiListener
Change change = notes.getChange();
ReviewerDeletedEvent event = new ReviewerDeletedEvent(change);
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.remover = accountAttributeSupplier(ev.getWho());
event.comment = ev.getComment();
@@ -332,7 +327,7 @@ public class StreamEventsApiListener
ReviewerAddedEvent event = new ReviewerAddedEvent(change);
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()) {
event.reviewer = accountAttributeSupplier(reviewer);
dispatcher.run(d -> d.postEvent(event));
@@ -420,7 +415,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes);
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();
dispatcher.run(d -> d.postEvent(change, event));
@@ -438,7 +433,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes);
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();
dispatcher.run(d -> d.postEvent(change, event));
@@ -456,7 +451,7 @@ public class StreamEventsApiListener
event.change = changeAttributeSupplier(change, notes);
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();
dispatcher.run(d -> d.postEvent(change, event));
@@ -509,7 +504,7 @@ public class StreamEventsApiListener
VoteDeletedEvent event = new VoteDeletedEvent(change);
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.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho());

View File

@@ -117,7 +117,7 @@ public class GroupCollector {
public List<String> lookup(PatchSet.Id psId) throws OrmException {
// TODO(dborowitz): Reuse open repository from caller.
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;
}
});

View File

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

View File

@@ -2881,7 +2881,7 @@ class ReceiveCommits {
new BatchUpdateOp() {
@Override
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();
if (oldGroups == null) {
if (groups == null) {
@@ -2890,7 +2890,7 @@ class ReceiveCommits {
} else if (sameGroups(oldGroups, groups)) {
return false;
}
psUtil.setGroups(ctx.getDb(), ctx.getUpdate(psId), ps, groups);
psUtil.setGroups(ctx.getUpdate(psId), ps, groups);
return true;
}
});

View File

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

View File

@@ -283,7 +283,7 @@ public class MailProcessor {
@Override
public boolean updateChange(ChangeContext ctx)
throws OrmException, UnprocessableEntityException, PatchListNotAvailableException {
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
patchSet = psUtil.get(ctx.getNotes(), psId);
notes = ctx.getNotes();
if (patchSet == null) {
throw new OrmException("patch set not found: " + psId);
@@ -366,7 +366,6 @@ public class MailProcessor {
ChangeContext ctx, MailComment mailComment, PatchSet current) throws OrmException {
if (mailComment.getInReplyTo() != null) {
return psUtil.get(
ctx.getDb(),
ctx.getNotes(),
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() + "");
if (patchSetInfo == null) {
try {
patchSetInfo =
args.patchSetInfoFactory.get(args.db.get(), changeData.notes(), patchSet.getId());
patchSetInfo = args.patchSetInfoFactory.get(changeData.notes(), patchSet.getId());
} catch (PatchSetInfoNotAvailableException | OrmException err) {
patchSetInfo = null;
}

View File

@@ -200,8 +200,8 @@ public class PatchScriptFactory implements Callable<PatchScript> {
}
validatePatchSetId(psb);
PatchSet psEntityA = psa != null ? psUtil.get(db, notes, psa) : null;
PatchSet psEntityB = psb.get() == 0 ? new PatchSet(psb) : psUtil.get(db, notes, psb);
PatchSet psEntityA = psa != null ? psUtil.get(notes, psa) : null;
PatchSet psEntityB = psb.get() == 0 ? new PatchSet(psb) : psUtil.get(notes, psb);
if (psEntityA != null || psEntityB != null) {
try {
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.
//
history = new ArrayList<>();
for (PatchSet ps : psUtil.byChange(db, notes)) {
for (PatchSet ps : psUtil.byChange(notes)) {
String name = fileName;
if (psa != null) {
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.RevId;
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.account.Emails;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -66,10 +65,10 @@ public class PatchSetInfoFactory {
return info;
}
public PatchSetInfo get(ReviewDb db, ChangeNotes notes, PatchSet.Id psId)
public PatchSetInfo get(ChangeNotes notes, PatchSet.Id psId)
throws PatchSetInfoNotAvailableException {
try {
PatchSet patchSet = psUtil.get(db, notes, psId);
PatchSet patchSet = psUtil.get(notes, psId);
return get(notes.getProjectName(), patchSet);
} catch (OrmException e) {
throw new PatchSetInfoNotAvailableException(e);

View File

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

View File

@@ -187,8 +187,7 @@ public class DeleteDraftComments
for (Comment c : commentsUtil.draftByChangeAuthor(ctx.getNotes(), accountId)) {
dirty = true;
PatchSet.Id psId = new PatchSet.Id(ctx.getChange().getId(), c.key.patchSetId);
setCommentRevId(
c, patchListCache, ctx.getChange(), psUtil.get(ctx.getDb(), ctx.getNotes(), psId));
setCommentRevId(c, patchListCache, ctx.getChange(), psUtil.get(ctx.getNotes(), psId));
commentsUtil.deleteComments(ctx.getUpdate(psId), Collections.singleton(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.RestReadView;
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.change.ChangeResource;
import com.google.gerrit.server.change.IncludedIn;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
@Singleton
public class ChangeIncludedIn implements RestReadView<ChangeResource> {
private Provider<ReviewDb> db;
private PatchSetUtil psUtil;
private IncludedIn includedIn;
@Inject
ChangeIncludedIn(Provider<ReviewDb> db, PatchSetUtil psUtil, IncludedIn includedIn) {
this.db = db;
ChangeIncludedIn(PatchSetUtil psUtil, IncludedIn includedIn) {
this.psUtil = psUtil;
this.includedIn = includedIn;
}
@@ -44,7 +40,7 @@ public class ChangeIncludedIn implements RestReadView<ChangeResource> {
@Override
public IncludedInInfo apply(ChangeResource rsrc)
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());
}
}

View File

@@ -225,7 +225,7 @@ public class CreateChange
} catch (AuthException e) {
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());
groups = ps.getGroups();
} else if (input.baseCommit != null) {

View File

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

View File

@@ -141,7 +141,7 @@ public class CreateMergePatchSet
}
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();
Project.NameKey project = change.getProject();
Branch.NameKey dest = change.getDest();
@@ -216,7 +216,7 @@ public class CreateMergePatchSet
} catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + baseChange);
}
return psUtil.current(db.get(), change);
return psUtil.current(change);
}
private RevCommit createMergeCommit(

View File

@@ -70,7 +70,7 @@ class DeleteChangeOp implements BatchUpdateOp {
checkState(id == null, "cannot reuse DeleteChangeOp");
id = ctx.getChange().getId();
Collection<PatchSet> patchSets = psUtil.byChange(ctx.getDb(), ctx.getNotes());
Collection<PatchSet> patchSets = psUtil.byChange(ctx.getNotes());
ensureDeletable(ctx, id, patchSets);
// 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.
}
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) {
throw new ResourceNotFoundException("patch set not found: " + psId);
}

View File

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

View File

@@ -169,7 +169,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
PermissionBackendException {
change = ctx.getChange();
PatchSet.Id psId = change.currentPatchSetId();
ps = psUtil.current(db.get(), ctx.getNotes());
ps = psUtil.current(ctx.getNotes());
boolean found = false;
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.PatchSet;
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.PatchSetUtil;
import com.google.gerrit.server.change.AccountPatchReviewStore;
@@ -114,7 +113,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
@Option(name = "-q")
String query;
private final Provider<ReviewDb> db;
private final Provider<CurrentUser> self;
private final FileInfoJson fileInfoJson;
private final Revisions revisions;
@@ -125,7 +123,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
@Inject
ListFiles(
Provider<ReviewDb> db,
Provider<CurrentUser> self,
FileInfoJson fileInfoJson,
Revisions revisions,
@@ -133,7 +130,6 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
PatchListCache patchListCache,
PatchSetUtil psUtil,
PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore) {
this.db = db;
this.self = self;
this.fileInfoJson = fileInfoJson;
this.revisions = revisions;
@@ -268,7 +264,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
RevWalk rw = new RevWalk(reader);
TreeWalk tw = new TreeWalk(reader)) {
Change change = resource.getChange();
PatchSet patchSet = psUtil.get(db.get(), resource.getNotes(), old);
PatchSet patchSet = psUtil.get(resource.getNotes(), old);
if (patchSet == null) {
throw new PatchListNotAvailableException(
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.Patch;
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.change.FileContentUtil;
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.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId;
@@ -43,7 +41,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.kohsuke.args4j.Option;
public class GetContent implements RestReadView<FileResource> {
private final Provider<ReviewDb> db;
private final GitRepositoryManager gitManager;
private final PatchSetUtil psUtil;
private final FileContentUtil fileContentUtil;
@@ -54,12 +51,10 @@ public class GetContent implements RestReadView<FileResource> {
@Inject
GetContent(
Provider<ReviewDb> db,
GitRepositoryManager gitManager,
PatchSetUtil psUtil,
FileContentUtil fileContentUtil,
ProjectCache projectCache) {
this.db = db;
this.gitManager = gitManager;
this.psUtil = psUtil;
this.fileContentUtil = fileContentUtil;
@@ -90,7 +85,7 @@ public class GetContent implements RestReadView<FileResource> {
private String getMessage(ChangeNotes notes) throws OrmException, IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes);
PatchSet ps = psUtil.current(notes);
if (ps == null) {
throw new NoSuchChangeException(changeId);
}
@@ -106,7 +101,7 @@ public class GetContent implements RestReadView<FileResource> {
private byte[] getMergeList(ChangeNotes notes) throws OrmException, IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes);
PatchSet ps = psUtil.current(notes);
if (ps == null) {
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.PatchSet;
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.PatchSetUtil;
import com.google.gerrit.server.change.RevisionResource;
@@ -50,7 +49,6 @@ import org.eclipse.jgit.revwalk.RevCommit;
@Singleton
public class GetRelated implements RestReadView<RevisionResource> {
private final Provider<ReviewDb> db;
private final Provider<InternalChangeQuery> queryProvider;
private final PatchSetUtil psUtil;
private final RelatedChangesSorter sorter;
@@ -58,12 +56,10 @@ public class GetRelated implements RestReadView<RevisionResource> {
@Inject
GetRelated(
Provider<ReviewDb> db,
Provider<InternalChangeQuery> queryProvider,
PatchSetUtil psUtil,
RelatedChangesSorter sorter,
IndexConfig indexConfig) {
this.db = db;
this.queryProvider = queryProvider;
this.psUtil = psUtil;
this.sorter = sorter;
@@ -81,7 +77,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
private List<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc)
throws OrmException, IOException, PermissionBackendException {
Set<String> groups = getAllGroups(rsrc.getNotes(), db.get(), psUtil);
Set<String> groups = getAllGroups(rsrc.getNotes(), psUtil);
if (groups.isEmpty()) {
return Collections.emptyList();
}
@@ -125,13 +121,9 @@ public class GetRelated implements RestReadView<RevisionResource> {
}
@VisibleForTesting
public static Set<String> getAllGroups(ChangeNotes notes, ReviewDb db, PatchSetUtil psUtil)
public static Set<String> getAllGroups(ChangeNotes notes, PatchSetUtil psUtil)
throws OrmException {
return psUtil
.byChange(db, notes)
.stream()
.flatMap(ps -> ps.getGroups().stream())
.collect(toSet());
return psUtil.byChange(notes).stream().flatMap(ps -> ps.getGroups().stream()).collect(toSet());
}
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)) {
RevCommit currPatchsetRevCommit =
revWalk.parseCommit(
ObjectId.fromString(
psUtil.current(ctx.getDb(), ctx.getNotes()).getRevision().get()));
ObjectId.fromString(psUtil.current(ctx.getNotes()).getRevision().get()));
if (currPatchsetRevCommit.getParentCount() > 1) {
throw new ResourceConflictException("Merge commit cannot be moved");
}

View File

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

View File

@@ -93,7 +93,7 @@ public class PutDescription
@Override
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);
newDescription = Strings.nullToEmpty(input.description);
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);
ChangeUpdate update = ctx.getUpdate(psId);
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
PatchSet ps = psUtil.get(ctx.getNotes(), psId);
if (ps == null) {
throw new ResourceNotFoundException("patch set not found: " + psId);
}

View File

@@ -105,7 +105,7 @@ public class PutMessage
BatchUpdate.Factory updateFactory, ChangeResource resource, CommitMessageInput input)
throws IOException, RestApiException, UpdateException, PermissionBackendException,
OrmException, ConfigInvalidException {
PatchSet ps = psUtil.current(db.get(), resource.getNotes());
PatchSet ps = psUtil.current(resource.getNotes());
if (ps == null) {
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)
throws OrmException, UpdateException, RestApiException, IOException,
PermissionBackendException {
PatchSet ps = psUtil.current(rebase.dbProvider.get(), rsrc.getNotes());
PatchSet ps = psUtil.current(rsrc.getNotes());
if (ps == null) {
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();
ChangeUpdate update = ctx.getUpdate(psId);
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
patchSet = psUtil.get(ctx.getNotes(), psId);
change.setStatus(Status.NEW);
change.setLastUpdatedOn(ctx.getWhen());
update.setStatus(change.getStatus());

View File

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

View File

@@ -85,7 +85,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
throws ResourceNotFoundException, AuthException, OrmException, IOException,
PermissionBackendException {
if (id.get().equals("current")) {
PatchSet ps = psUtil.current(dbProvider.get(), change.getNotes());
PatchSet ps = psUtil.current(change.getNotes());
if (ps != null && visible(change)) {
return RevisionResource.createNonCachable(change, ps);
}
@@ -135,7 +135,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
return Collections.emptyList();
} else {
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)) {
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)
throws OrmException {
PatchSet ps =
psUtil.get(
dbProvider.get(),
change.getNotes(),
new PatchSet.Id(change.getId(), Integer.parseInt(id)));
psUtil.get(change.getNotes(), new PatchSet.Id(change.getId(), Integer.parseInt(id)));
if (ps != null) {
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 {
change = ctx.getChange();
ChangeNotes notes = ctx.getNotes();
ps = psUtil.get(ctx.getDb(), notes, change.currentPatchSetId());
ps = psUtil.get(notes, change.currentPatchSetId());
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
change.setPrivate(isPrivate);
change.setLastUpdatedOn(ctx.getWhen());

View File

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

View File

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

View File

@@ -170,7 +170,7 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
ctx.addRefUpdate(ObjectId.zeroId(), newCommit, newPatchSetId.toRefName());
} else {
// 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 =
args.rebaseFactory
.create(toMerge.notes(), origPs, args.mergeTip.getCurrentTip())
@@ -227,10 +227,9 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
newPs = rebaseOp.getPatchSet();
} else {
// CherryPick
PatchSet prevPs = args.psUtil.current(ctx.getDb(), ctx.getNotes());
PatchSet prevPs = args.psUtil.current(ctx.getNotes());
newPs =
args.psUtil.insert(
ctx.getDb(),
ctx.getRevWalk(),
ctx.getUpdate(newPatchSetId),
newPatchSetId,

View File

@@ -250,7 +250,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
// during the submit strategy.
mergedPatchSet =
requireNonNull(
args.psUtil.get(ctx.getDb(), ctx.getNotes(), oldPsId),
args.psUtil.get(ctx.getNotes(), oldPsId),
() -> String.format("missing old patch set %s", oldPsId));
} else {
PatchSet.Id n = newPatchSet.getId();
@@ -300,12 +300,12 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
throws IOException, OrmException {
PatchSet.Id psId = alreadyMergedCommit.getPatchsetId();
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.getChange()
.setCurrentPatchSet(
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) {
logger.atFine().log("Patch set row exists, only updating change");
return existing;
@@ -316,14 +316,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
List<String> groups =
prevPs != null ? prevPs.getGroups() : GroupCollector.getDefaultGroups(alreadyMergedCommit);
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)

View File

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

View File

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

View File

@@ -572,7 +572,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
ChangeData cd = getChange(last);
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());
}
@@ -610,8 +610,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
new BatchUpdateOp() {
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException {
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
psUtil.setGroups(ctx.getDb(), ctx.getUpdate(psId), ps, ImmutableList.<String>of());
PatchSet ps = psUtil.get(ctx.getNotes(), psId);
psUtil.setGroups(ctx.getUpdate(psId), ps, ImmutableList.<String>of());
ctx.dontBumpLastUpdatedOn();
return true;
}

View File

@@ -2280,7 +2280,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
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());
PatchSet ps = psUtil.get(notes, change.currentPatchSetId());
requestContext.setContext(newRequestContext(user));
gApi.changes().id(changeId).edit().create();