Merge "Pass ReviewDb to ChangeNotes.Factory"
This commit is contained in:
@@ -274,7 +274,7 @@ public class PushOneCommit {
|
||||
private void assertReviewers(Change c, TestAccount... expectedReviewers)
|
||||
throws OrmException {
|
||||
Iterable<Account.Id> actualIds =
|
||||
approvalsUtil.getReviewers(db, notesFactory.create(c)).values();
|
||||
approvalsUtil.getReviewers(db, notesFactory.create(db, c)).values();
|
||||
assertThat(actualIds).containsExactlyElementsIn(
|
||||
Sets.newHashSet(TestAccount.ids(expectedReviewers)));
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
|
||||
private PatchSetApproval getSubmitter(PatchSet.Id patchSetId)
|
||||
throws OrmException {
|
||||
Change c = db.changes().get(patchSetId.getParentKey());
|
||||
ChangeNotes notes = changeNotesFactory.create(c).load();
|
||||
ChangeNotes notes = changeNotesFactory.create(db, c).load();
|
||||
return approvalsUtil.getSubmitter(db, notes, patchSetId);
|
||||
}
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
|
||||
protected void assertSubmitter(String changeId, int psId)
|
||||
throws OrmException {
|
||||
ChangeNotes cn = notesFactory.create(
|
||||
ChangeNotes cn = notesFactory.create(db,
|
||||
getOnlyElement(queryProvider.get().byKeyPrefix(changeId)).change());
|
||||
PatchSetApproval submitter = approvalsUtil.getSubmitter(
|
||||
db, cn, new PatchSet.Id(cn.getChangeId(), psId));
|
||||
@@ -324,7 +324,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
|
||||
protected void assertNoSubmitter(String changeId, int psId)
|
||||
throws OrmException {
|
||||
ChangeNotes cn = notesFactory.create(
|
||||
ChangeNotes cn = notesFactory.create(db,
|
||||
getOnlyElement(queryProvider.get().byKeyPrefix(changeId)).change());
|
||||
PatchSetApproval submitter = approvalsUtil.getSubmitter(
|
||||
db, cn, new PatchSet.Id(cn.getChangeId(), psId));
|
||||
|
||||
@@ -309,8 +309,8 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
.build());
|
||||
}
|
||||
|
||||
private ChangeNotes newNotes(Change change) {
|
||||
return notesFactory.create(change);
|
||||
private ChangeNotes newNotes(ReviewDb db, Change change) {
|
||||
return notesFactory.create(db, change);
|
||||
}
|
||||
|
||||
private static Optional<Path> hook(Config config, Path path, String name) {
|
||||
@@ -403,7 +403,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
@Override
|
||||
public void doPatchsetCreatedHook(Change change,
|
||||
PatchSet patchSet, ReviewDb db) throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
PatchSetCreatedEvent event = new PatchSetCreatedEvent(change);
|
||||
Supplier<AccountState> uploader =
|
||||
getAccountSupplier(patchSet.getUploader());
|
||||
@@ -441,7 +441,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
@Override
|
||||
public void doDraftPublishedHook(Change change, PatchSet patchSet,
|
||||
ReviewDb db) throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
DraftPublishedEvent event = new DraftPublishedEvent(change);
|
||||
Supplier<AccountState> uploader =
|
||||
getAccountSupplier(patchSet.getUploader());
|
||||
@@ -478,7 +478,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
public void doCommentAddedHook(final Change change, Account account,
|
||||
PatchSet patchSet, String comment, final Map<String, Short> approvals,
|
||||
ReviewDb db) throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
CommentAddedEvent event = new CommentAddedEvent(change);
|
||||
Supplier<AccountState> owner = getAccountSupplier(change.getOwner());
|
||||
|
||||
@@ -540,7 +540,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
public void doChangeMergedHook(Change change, Account account,
|
||||
PatchSet patchSet, ReviewDb db, String mergeResultRev)
|
||||
throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
ChangeMergedEvent event = new ChangeMergedEvent(change);
|
||||
Supplier<AccountState> owner = getAccountSupplier(change.getOwner());
|
||||
|
||||
@@ -576,7 +576,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
public void doMergeFailedHook(Change change, Account account,
|
||||
PatchSet patchSet, String reason,
|
||||
ReviewDb db) throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
MergeFailedEvent event = new MergeFailedEvent(change);
|
||||
Supplier<AccountState> owner = getAccountSupplier(change.getOwner());
|
||||
|
||||
@@ -612,7 +612,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
public void doChangeAbandonedHook(Change change, Account account,
|
||||
PatchSet patchSet, String reason, ReviewDb db)
|
||||
throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
ChangeAbandonedEvent event = new ChangeAbandonedEvent(change);
|
||||
AccountState owner = accountCache.get(change.getOwner());
|
||||
|
||||
@@ -648,7 +648,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
public void doChangeRestoredHook(Change change, Account account,
|
||||
PatchSet patchSet, String reason, ReviewDb db)
|
||||
throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
ChangeRestoredEvent event = new ChangeRestoredEvent(change);
|
||||
AccountState owner = accountCache.get(change.getOwner());
|
||||
|
||||
@@ -725,7 +725,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
@Override
|
||||
public void doReviewerAddedHook(Change change, Account account,
|
||||
PatchSet patchSet, ReviewDb db) throws OrmException {
|
||||
ChangeNotes notes = newNotes(change);
|
||||
ChangeNotes notes = newNotes(db, change);
|
||||
ReviewerAddedEvent event = new ReviewerAddedEvent(change);
|
||||
Supplier<AccountState> owner = getAccountSupplier(change.getOwner());
|
||||
|
||||
|
||||
@@ -587,7 +587,7 @@ public class ConsistencyChecker {
|
||||
if (c == null) {
|
||||
throw new OrmException("Change missing: " + cid);
|
||||
}
|
||||
ChangeNotes notes = notesFactory.create(c);
|
||||
ChangeNotes notes = notesFactory.create(db, c);
|
||||
|
||||
if (psId.equals(c.currentPatchSetId())) {
|
||||
List<PatchSet> all = Lists.newArrayList(db.patchSets().byChange(cid));
|
||||
|
||||
@@ -126,7 +126,7 @@ public class GroupCollector {
|
||||
if (c == null) {
|
||||
return null;
|
||||
}
|
||||
ChangeNotes notes = notesFactory.create(c);
|
||||
ChangeNotes notes = notesFactory.create(db, c);
|
||||
PatchSet ps = psUtil.get(db, notes, psId);
|
||||
return ps != null ? ps.getGroups() : null;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.config.AllUsersNameProvider;
|
||||
@@ -115,7 +116,8 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
this.allUsersProvider = allUsersProvider;
|
||||
}
|
||||
|
||||
public ChangeNotes create(Change change) {
|
||||
public ChangeNotes create(@SuppressWarnings("unused") ReviewDb db,
|
||||
Change change) {
|
||||
return new ChangeNotes(repoManager, migration, allUsersProvider, change);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +121,11 @@ public class ChangeControl {
|
||||
ChangeData.Factory changeDataFactory,
|
||||
ChangeNotes.Factory notesFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
ReviewDb db,
|
||||
@Assisted RefControl refControl,
|
||||
@Assisted Change change) {
|
||||
this(changeDataFactory, approvalsUtil, refControl,
|
||||
notesFactory.create(change));
|
||||
notesFactory.create(db, change));
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
|
||||
@@ -597,7 +597,7 @@ public class ChangeData {
|
||||
|
||||
public ChangeNotes notes() throws OrmException {
|
||||
if (notes == null) {
|
||||
notes = notesFactory.create(change());
|
||||
notes = notesFactory.create(db, change());
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
import com.google.gerrit.server.account.AuthRequest;
|
||||
@@ -41,11 +42,14 @@ import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.git.LabelNormalizer.Result;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.schema.SchemaCreator;
|
||||
import com.google.gerrit.server.util.RequestContext;
|
||||
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||
import com.google.gerrit.testutil.InMemoryDatabase;
|
||||
import com.google.gerrit.testutil.InMemoryModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
@@ -66,6 +70,7 @@ public class LabelNormalizerTest {
|
||||
@Inject private MetaDataUpdate.User metaDataUpdateFactory;
|
||||
@Inject private ProjectCache projectCache;
|
||||
@Inject private SchemaCreator schemaCreator;
|
||||
@Inject protected ThreadLocalRequestContext requestContext;
|
||||
|
||||
private LifecycleManager lifecycle;
|
||||
private ReviewDb db;
|
||||
@@ -87,6 +92,18 @@ public class LabelNormalizerTest {
|
||||
.getAccountId();
|
||||
user = userFactory.create(Providers.of(db), userId);
|
||||
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
|
||||
configureProject();
|
||||
setUpChange();
|
||||
}
|
||||
@@ -123,6 +140,7 @@ public class LabelNormalizerTest {
|
||||
if (lifecycle != null) {
|
||||
lifecycle.stop();
|
||||
}
|
||||
requestContext.setContext(null);
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PatchSetParser {
|
||||
if (c == null) {
|
||||
throw error("\"" + changeId + "\" no such change");
|
||||
}
|
||||
return notesFactory.create(c);
|
||||
return notesFactory.create(db.get(), c);
|
||||
}
|
||||
|
||||
private static boolean inProject(Change change,
|
||||
|
||||
Reference in New Issue
Block a user