BatchUpdate: Extract interfaces for *Context

Keep the current implementations, which depend on reaching into
BatchUpdate internal state. This results in parallel inheritance for the
interfaces and implementations, which is a little sketchy and we might
eventually get rid of. But it keeps the change pretty minimal for now.

While we're extracting new public interfaces, document them.

Change-Id: I4f9ec67b1a2a560428aef01e41a3a94cb6ce6912
This commit is contained in:
Dave Borowitz 2017-03-10 13:11:59 -05:00
parent ea11b28e66
commit b91cf223be
55 changed files with 383 additions and 155 deletions

View File

@ -1309,7 +1309,7 @@ public Object apply(RevisionResource rcrs, Input in) {
db, project.getNameKey(), user, TimeUtil.nowTs())) {
bu.addOp(change.getId(), new BatchUpdate.Op() {
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx) {
public boolean updateChange(ChangeContext ctx) {
return true;
}
});

View File

@ -109,6 +109,7 @@ import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.Util;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.testutil.FakeEmailSender.Message;
import com.google.gerrit.testutil.TestTimeUtil;
import com.google.inject.Inject;
@ -2517,7 +2518,7 @@ public class ChangeIT extends AbstractDaemonTest {
}
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx) throws Exception {
public boolean updateChange(ChangeContext ctx) throws Exception {
Change change = ctx.getChange();
// Change status in database.

View File

@ -70,7 +70,7 @@ import com.google.gerrit.server.git.validators.OnSubmitValidationListener;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.Util;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gerrit.testutil.ConfigSuite;
import com.google.gerrit.testutil.TestTimeUtil;

View File

@ -42,6 +42,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.notedb.PatchSetState;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.testutil.ConfigSuite;
import com.google.inject.Inject;
import java.util.Collection;
@ -277,7 +278,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
private class MarkChangeAsDraftUpdateOp extends BatchUpdate.Op {
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx) throws Exception {
public boolean updateChange(ChangeContext ctx) throws Exception {
Change change = ctx.getChange();
// Change status in database.
@ -299,7 +300,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
}
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx) throws Exception {
public boolean updateChange(ChangeContext ctx) throws Exception {
Collection<PatchSet> patchSets = psUtil.byChange(db, ctx.getNotes());
// Change status in database.

View File

@ -50,8 +50,8 @@ import com.google.gerrit.server.notedb.ChangeNoteUtil;
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.testutil.InMemoryRepositoryManager;
import com.google.gerrit.testutil.TestChanges;
import com.google.gwtorm.server.OrmException;

View File

@ -36,7 +36,7 @@ import com.google.gerrit.server.change.GetRelated.ChangeAndCommit;
import com.google.gerrit.server.change.GetRelated.RelatedInfo;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.testutil.TestTimeUtil;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -78,7 +78,7 @@ import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.Util;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.testutil.ConfigSuite;
import com.google.gerrit.testutil.NoteDbChecker;

View File

@ -26,7 +26,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
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.update.BatchUpdate;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@ -58,8 +58,7 @@ public class ChangeMessagesUtil {
public static final String TAG_SET_TOPIC = "autogenerated:gerrit:setTopic";
public static final String TAG_UPLOADED_PATCH_SET = "autogenerated:gerrit:newPatchSet";
public static ChangeMessage newMessage(
BatchUpdate.ChangeContext ctx, String body, @Nullable String tag) {
public static ChangeMessage newMessage(ChangeContext ctx, String body, @Nullable String tag) {
return newMessage(ctx.getChange().currentPatchSetId(), ctx.getUser(), ctx.getWhen(), body, tag);
}

View File

@ -46,7 +46,7 @@ import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;

View File

@ -58,9 +58,9 @@ import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.ssh.NoSshInfo;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.util.RequestScopePropagator;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -48,7 +48,7 @@ import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -51,8 +51,8 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -35,7 +35,7 @@ import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -31,8 +31,8 @@ import com.google.gerrit.server.change.DeleteAssignee.Input;
import com.google.gerrit.server.extensions.events.AssigneeChanged;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -110,8 +110,7 @@ public class DeleteAssignee implements RestModifyView<ChangeResource, Input> {
return deletedAssignee != null ? deletedAssignee.getId() : null;
}
private void addMessage(
BatchUpdate.ChangeContext ctx, ChangeUpdate update, IdentifiedUser deletedAssignee)
private void addMessage(ChangeContext ctx, ChangeUpdate update, IdentifiedUser deletedAssignee)
throws OrmException {
ChangeMessage cmsg =
ChangeMessagesUtil.newMessage(

View File

@ -26,6 +26,7 @@ import com.google.gerrit.server.change.DeleteChange.Input;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.Order;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -61,7 +62,7 @@ public class DeleteChange
try (BatchUpdate bu =
updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
Change.Id id = rsrc.getChange().getId();
bu.setOrder(BatchUpdate.Order.DB_BEFORE_REPO);
bu.setOrder(Order.DB_BEFORE_REPO);
bu.addOp(id, opProvider.get());
bu.execute();
}

View File

@ -30,9 +30,10 @@ import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.BatchUpdateReviewDb;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Order;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
@ -84,8 +85,7 @@ class DeleteChangeOp extends BatchUpdate.Op {
public boolean updateChange(ChangeContext ctx)
throws RestApiException, OrmException, IOException, NoSuchChangeException {
checkState(
ctx.getOrder() == BatchUpdate.Order.DB_BEFORE_REPO,
"must use DeleteChangeOp with DB_BEFORE_REPO");
ctx.getOrder() == Order.DB_BEFORE_REPO, "must use DeleteChangeOp with DB_BEFORE_REPO");
checkState(id == null, "cannot reuse DeleteChangeOp");
id = ctx.getChange().getId();

View File

@ -30,7 +30,7 @@ import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.DeleteDraftComment.Input;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -34,8 +34,9 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Order;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -83,7 +84,7 @@ public class DeleteDraftPatchSet
throws RestApiException, UpdateException {
try (BatchUpdate bu =
updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
bu.setOrder(BatchUpdate.Order.DB_BEFORE_REPO);
bu.setOrder(Order.DB_BEFORE_REPO);
bu.addOp(rsrc.getChange().getId(), new Op(rsrc.getPatchSet().getId()));
bu.execute();
}

View File

@ -43,9 +43,9 @@ import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdateReviewDb;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -43,8 +43,8 @@ import com.google.gerrit.server.mail.send.DeleteVoteSender;
import com.google.gerrit.server.mail.send.ReplyToChangeSender;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.LabelVote;
import com.google.gwtorm.server.OrmException;

View File

@ -39,7 +39,7 @@ import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -46,9 +46,9 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.ssh.NoSshInfo;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;

View File

@ -93,8 +93,8 @@ import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.LabelVote;
import com.google.gwtorm.server.OrmException;

View File

@ -59,8 +59,8 @@ import com.google.gerrit.server.notedb.NotesMigration;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -46,8 +46,8 @@ import com.google.gerrit.server.mail.send.ReplacePatchSetSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -30,7 +30,7 @@ import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -34,7 +34,7 @@ import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -31,8 +31,8 @@ import com.google.gerrit.server.extensions.events.TopicEdited;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -32,9 +32,9 @@ import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;

View File

@ -36,8 +36,8 @@ import com.google.gerrit.server.mail.send.RestoredSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -47,8 +47,8 @@ import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -31,7 +31,8 @@ import com.google.gerrit.server.extensions.events.AssigneeChanged;
import com.google.gerrit.server.mail.send.SetAssigneeSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.validators.AssigneeValidationListener;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;
@ -82,7 +83,7 @@ public class SetAssigneeOp extends BatchUpdate.Op {
}
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx) throws OrmException, RestApiException {
public boolean updateChange(ChangeContext ctx) throws OrmException, RestApiException {
change = ctx.getChange();
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
IdentifiedUser newAssigneeUser = accounts.parse(assignee);
@ -119,7 +120,7 @@ public class SetAssigneeOp extends BatchUpdate.Op {
}
private void addMessage(
BatchUpdate.ChangeContext ctx,
ChangeContext ctx,
ChangeUpdate update,
IdentifiedUser previousAssignee,
IdentifiedUser newAssignee)

View File

@ -34,8 +34,8 @@ 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.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.validators.HashtagValidationListener;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;

View File

@ -41,7 +41,7 @@ import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;

View File

@ -31,8 +31,8 @@ import com.google.gerrit.server.mail.send.AbandonedSender;
import com.google.gerrit.server.mail.send.ReplyToChangeSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server.git;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import org.eclipse.jgit.lib.ProgressMonitor;
/** Trivial op to update a counter during {@code updateChange} */

View File

@ -64,7 +64,7 @@ import com.google.gerrit.server.project.SubmitRuleOptions;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.RequestId;
import com.google.gwtorm.server.OrmException;

View File

@ -30,8 +30,8 @@ import com.google.gerrit.server.mail.send.MergedSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.util.RequestScopePropagator;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;

View File

@ -115,7 +115,7 @@ import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.LabelVote;
import com.google.gerrit.server.util.MagicBranch;

View File

@ -50,9 +50,9 @@ import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.util.RequestScopePropagator;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;

View File

@ -32,7 +32,7 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.Listener;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;

View File

@ -27,8 +27,8 @@ import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.git.MergeTip;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -16,7 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.RepoContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

View File

@ -16,7 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.RepoContext;
class FastForwardOp extends SubmitStrategyOp {
FastForwardOp(SubmitStrategy.Arguments args, CodeReviewCommit toMerge) {

View File

@ -16,7 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.RepoContext;
import java.io.IOException;
import org.eclipse.jgit.lib.PersonIdent;

View File

@ -32,9 +32,9 @@ import com.google.gerrit.server.git.RebaseSorter;
import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -47,9 +47,9 @@ import com.google.gerrit.server.git.SubmoduleException;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.BatchUpdate.Context;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.RepoContext;
import com.google.gwtorm.server.OrmException;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -47,6 +47,8 @@ import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.ManualRequestContext;
import com.google.gerrit.server.util.OneOffRequestContext;
@ -221,7 +223,7 @@ public class MailProcessor {
}
@Override
public boolean updateChange(BatchUpdate.ChangeContext ctx)
public boolean updateChange(ChangeContext ctx)
throws OrmException, UnprocessableEntityException {
changeControl = ctx.getControl();
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
@ -296,7 +298,7 @@ public class MailProcessor {
}
@Override
public void postUpdate(BatchUpdate.Context ctx) throws Exception {
public void postUpdate(Context ctx) throws Exception {
String patchSetComment = null;
if (parsedComments.get(0).type == MailComment.CommentType.CHANGE_MESSAGE) {
patchSetComment = parsedComments.get(0).message;

View File

@ -50,7 +50,7 @@ import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.ChangeContext;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.AtomicUpdate;
import com.google.gwtorm.server.OrmException;

View File

@ -39,7 +39,6 @@ import com.google.gerrit.metrics.Description.Units;
import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.metrics.Timer1;
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;
@ -47,7 +46,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbWrapper;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
@ -127,28 +125,10 @@ public class BatchUpdate implements AutoCloseable {
BatchUpdate create(ReviewDb db, Project.NameKey project, CurrentUser user, Timestamp when);
}
/** Order of execution of the various phases. */
public enum Order {
/**
* Update the repository and execute all ref updates before touching the database.
*
* <p>The default and most common, as Gerrit does not behave well when a patch set has no
* corresponding ref in the repo.
*/
REPO_BEFORE_DB,
/**
* Update the database before touching the repository.
*
* <p>Generally only used when deleting patch sets, which should be deleted first from the
* database (for the same reason as above.)
*/
DB_BEFORE_REPO;
}
public class Context {
private class ContextImpl implements Context {
private Repository repoWrapper;
@Override
public Repository getRepository() throws IOException {
if (repoWrapper == null) {
repoWrapper = new ReadOnlyRepository(BatchUpdate.this.getRepository());
@ -156,67 +136,61 @@ public class BatchUpdate implements AutoCloseable {
return repoWrapper;
}
@Override
public RevWalk getRevWalk() throws IOException {
return BatchUpdate.this.getRevWalk();
}
@Override
public Project.NameKey getProject() {
return project;
}
@Override
public Timestamp getWhen() {
return when;
}
@Override
public TimeZone getTimeZone() {
return tz;
}
@Override
public ReviewDb getDb() {
return db;
}
@Override
public CurrentUser getUser() {
return user;
}
public IdentifiedUser getIdentifiedUser() {
checkNotNull(user);
return user.asIdentifiedUser();
}
public Account getAccount() {
checkNotNull(user);
return user.asIdentifiedUser().getAccount();
}
public Account.Id getAccountId() {
checkNotNull(user);
return user.getAccountId();
}
@Override
public Order getOrder() {
return order;
}
}
public class RepoContext extends Context {
private class RepoContextImpl extends ContextImpl implements RepoContext {
@Override
public Repository getRepository() throws IOException {
return BatchUpdate.this.getRepository();
}
@Override
public ObjectInserter getInserter() throws IOException {
return BatchUpdate.this.getObjectInserter();
}
@Override
public void addRefUpdate(ReceiveCommand cmd) throws IOException {
initRepository();
commands.add(cmd);
}
public TimeZone getTimeZone() {
return tz;
}
}
public class ChangeContext extends Context {
private class ChangeContextImpl extends ContextImpl implements ChangeContext {
private final ChangeControl ctl;
private final Map<PatchSet.Id, ChangeUpdate> updates;
private final ReviewDbWrapper dbWrapper;
@ -226,7 +200,7 @@ public class BatchUpdate implements AutoCloseable {
private boolean deleted;
private boolean bumpLastUpdatedOn = true;
protected ChangeContext(
protected ChangeContextImpl(
ChangeControl ctl, ReviewDbWrapper dbWrapper, Repository repo, RevWalk rw) {
this.ctl = ctl;
this.dbWrapper = dbWrapper;
@ -251,6 +225,7 @@ public class BatchUpdate implements AutoCloseable {
return threadLocalRevWalk;
}
@Override
public ChangeUpdate getUpdate(PatchSet.Id psId) {
ChangeUpdate u = updates.get(psId);
if (u == null) {
@ -264,27 +239,18 @@ public class BatchUpdate implements AutoCloseable {
return u;
}
public ChangeNotes getNotes() {
ChangeNotes n = ctl.getNotes();
checkNotNull(n);
return n;
}
@Override
public ChangeControl getControl() {
checkNotNull(ctl);
return ctl;
}
public Change getChange() {
Change c = ctl.getChange();
checkNotNull(c);
return c;
}
@Override
public void bumpLastUpdatedOn(boolean bump) {
bumpLastUpdatedOn = bump;
}
@Override
public void deleteChange() {
deleted = true;
}
@ -651,7 +617,7 @@ public class BatchUpdate implements AutoCloseable {
}
public BatchUpdate insertChange(InsertChangeOp op) {
Context ctx = new Context();
ContextImpl ctx = new ContextImpl();
Change c = op.createChange(ctx);
checkArgument(
!newChanges.containsKey(c.getId()), "only one op allowed to create change %s", c.getId());
@ -675,7 +641,7 @@ public class BatchUpdate implements AutoCloseable {
private void executeUpdateRepo() throws UpdateException, RestApiException {
try {
logDebug("Executing updateRepo on {} ops", ops.size());
RepoContext ctx = new RepoContext();
RepoContextImpl ctx = new RepoContextImpl();
for (Op op : ops.values()) {
op.updateRepo(ctx);
}
@ -952,7 +918,7 @@ public class BatchUpdate implements AutoCloseable {
try {
db.changes().beginTransaction(id);
try {
ChangeContext ctx = newChangeContext(db, repo, rw, id);
ChangeContextImpl ctx = newChangeContext(db, repo, rw, id);
NoteDbChangeState oldState = NoteDbChangeState.parse(ctx.getChange());
NoteDbChangeState.checkNotReadOnly(oldState, skewMs);
@ -1038,8 +1004,8 @@ public class BatchUpdate implements AutoCloseable {
}
}
private ChangeContext newChangeContext(ReviewDb db, Repository repo, RevWalk rw, Change.Id id)
throws OrmException {
private ChangeContextImpl newChangeContext(
ReviewDb db, Repository repo, RevWalk rw, Change.Id id) throws OrmException {
Change c = newChanges.get(id);
boolean isNew = c != null;
if (isNew) {
@ -1075,10 +1041,10 @@ public class BatchUpdate implements AutoCloseable {
}
ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
ChangeControl ctl = changeControlFactory.controlFor(notes, user);
return new ChangeContext(ctl, new BatchUpdateReviewDb(db), repo, rw);
return new ChangeContextImpl(ctl, new BatchUpdateReviewDb(db), repo, rw);
}
private NoteDbUpdateManager stageNoteDbUpdate(ChangeContext ctx, boolean deleted)
private NoteDbUpdateManager stageNoteDbUpdate(ChangeContextImpl ctx, boolean deleted)
throws OrmException, IOException {
logDebug("Staging NoteDb update");
NoteDbUpdateManager updateManager =
@ -1129,7 +1095,7 @@ public class BatchUpdate implements AutoCloseable {
}
}
private static Iterable<Change> changesToUpdate(ChangeContext ctx) {
private static Iterable<Change> changesToUpdate(ChangeContextImpl ctx) {
Change c = ctx.getChange();
if (ctx.bumpLastUpdatedOn && c.getLastUpdatedOn().before(ctx.getWhen())) {
c.setLastUpdatedOn(ctx.getWhen());
@ -1138,7 +1104,7 @@ public class BatchUpdate implements AutoCloseable {
}
private void executePostOps() throws Exception {
Context ctx = new Context();
ContextImpl ctx = new ContextImpl();
for (Op op : ops.values()) {
op.postUpdate(ctx);
}

View File

@ -0,0 +1,75 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.update;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
/**
* Context for performing the {@link BatchUpdate.Op#updateChange} phase.
*
* <p>A single {@code ChangeContext} corresponds to updating a single change; if a {@link
* BatchUpdate} spans multiple changes, then multiple {@code ChangeContext} instances will be
* created.
*/
public interface ChangeContext extends Context {
/**
* Get an update for this change at a given patch set.
*
* <p>A single operation can modify changes at different patch sets. Commits in the NoteDb graph
* within this update are created in patch set order.
*
* <p>To get the current patch set ID, use {@link com.google.gerrit.server.PatchSetUtil#current}.
*
* @param psId patch set ID.
* @return handle for change updates.
*/
ChangeUpdate getUpdate(PatchSet.Id psId);
/**
* @return control for this change. The user will be the same as {@link #getUser()}, and the
* change data is read within the same transaction that {@code updateChange} is executing.
*/
ChangeControl getControl();
/**
* @param bump whether to bump the value of {@link Change#getLastUpdatedOn()} field before storing
* to ReviewDb. For NoteDb, the value is always incremented (assuming the update is not
* otherwise a no-op).
*/
void bumpLastUpdatedOn(boolean bump);
/**
* Instruct {@link BatchUpdate} to delete this change.
*
* <p>If called, all other updates are ignored.
*/
void deleteChange();
/** @return notes corresponding to {@link #getControl()}. */
default ChangeNotes getNotes() {
return checkNotNull(getControl().getNotes());
}
/** @return change corresponding to {@link #getControl()}. */
default Change getChange() {
return checkNotNull(getControl().getChange());
}
}

View File

@ -0,0 +1,108 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.update;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gerrit.reviewdb.client.Account;
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.IdentifiedUser;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.TimeZone;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk;
/**
* Context for performing a {@link BatchUpdate}.
*
* <p>A single update may span multiple changes, but they all belong to a single repo.
*/
public interface Context {
/** @return the project name this update operates on. */
Project.NameKey getProject();
/**
* Get an open repository instance for this project.
*
* <p>Will be opened lazily if necessary; callers should not close the repo. In some phases of the
* update, the repository might be read-only; see {@link BatchUpdate.Op} for details.
*
* @return repository instance.
* @throws IOException if an error occurred opening the repo.
*/
Repository getRepository() throws IOException;
/**
* Get a walk for this project.
*
* <p>The repository will be opened lazily if necessary; callers should not close the walk.
*
* @return walk.
* @throws IOException if an error occurred opening the repo.
*/
RevWalk getRevWalk() throws IOException;
/** @return the timestamp at which this update takes place. */
Timestamp getWhen();
/**
* @return the time zone in which this update takes place. In the current implementation, this is
* always the time zone of the server.
*/
TimeZone getTimeZone();
/**
* @return an open ReviewDb database. Callers should not manage transactions or call mutating
* methods on the Changes table. Mutations on other tables (including other entities in the
* change entity group) are fine.
*/
ReviewDb getDb();
/**
* @return user performing the update. In the current implementation, this is always an {@link
* IdentifiedUser} or {@link com.google.gerrit.server.InternalUser}.
*/
CurrentUser getUser();
/** @return order in which operations are executed in this update. */
Order getOrder();
/**
* @return identified user performing the update; throws an unchecked exception if the user is not
* an {@link IdentifiedUser}
*/
default IdentifiedUser getIdentifiedUser() {
return checkNotNull(getUser()).asIdentifiedUser();
}
/**
* @return account of the user performing the update; throws if the user is not an {@link
* IdentifiedUser}
*/
default Account getAccount() {
return getIdentifiedUser().getAccount();
}
/**
* @return account ID of the user performing the update; throws if the user is not an {@link
* IdentifiedUser}
*/
default Account.Id getAccountId() {
return getIdentifiedUser().getAccountId();
}
}

View File

@ -0,0 +1,34 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.update;
/** Order of execution of the various phases of a {@link BatchUpdate}. */
public enum Order {
/**
* Update the repository and execute all ref updates before touching the database.
*
* <p>The default and most common, as Gerrit does not behave well when a patch set has no
* corresponding ref in the repo.
*/
REPO_BEFORE_DB,
/**
* Update the database before touching the repository.
*
* <p>Generally only used when deleting patch sets, which should be deleted first from the
* database (for the same reason as above.)
*/
DB_BEFORE_REPO;
}

View File

@ -0,0 +1,41 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.update;
import java.io.IOException;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.transport.ReceiveCommand;
/** Context for performing the {@link BatchUpdate.Op#updateRepo} phase. */
public interface RepoContext extends Context {
/**
* @return inserter for writing to the repo. Callers should not flush; the walk returned by {@link
* #getRevWalk()} is able to read back objects inserted by this inserter without flushing
* first.
* @throws IOException if an error occurred opening the repo.
*/
ObjectInserter getInserter() throws IOException;
/**
* Add a command to the pending list of commands.
*
* <p>Callers should use this method instead of writing directly to the repository returned by
* {@link #getRepository()}.
*
* @param cmd ref update command.
* @throws IOException if an error occurred opening the repo.
*/
void addRefUpdate(ReceiveCommand cmd) throws IOException;
}

View File

@ -12,7 +12,6 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountManager;
import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.schema.SchemaCreator;
import com.google.gerrit.server.update.BatchUpdate.RepoContext;
import com.google.gerrit.server.update.BatchUpdate.RepoOnlyOp;
import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext;