Start factoring out PatchSet accesses into a PatchSetUtil class
Replaces the simplest get calls in most callers that didn't require substantial refactoring. Doesn't actually read notedb yet because there is no notedb support for patch sets yet. Change-Id: I7ef198dd1257b833a3a4b21180f5012f6fdc56d4
This commit is contained in:
@@ -40,6 +40,7 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
|||||||
import com.google.gerrit.extensions.common.EditInfo;
|
import com.google.gerrit.extensions.common.EditInfo;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.AnonymousUser;
|
import com.google.gerrit.server.AnonymousUser;
|
||||||
@@ -58,10 +59,12 @@ import com.google.gerrit.server.index.ChangeIndexer;
|
|||||||
import com.google.gerrit.server.notedb.NotesMigration;
|
import com.google.gerrit.server.notedb.NotesMigration;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
import com.google.gerrit.server.project.Util;
|
import com.google.gerrit.server.project.Util;
|
||||||
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gerrit.testutil.ConfigSuite;
|
import com.google.gerrit.testutil.ConfigSuite;
|
||||||
import com.google.gerrit.testutil.TempFileUtil;
|
import com.google.gerrit.testutil.TempFileUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
@@ -164,6 +167,9 @@ public abstract class AbstractDaemonTest {
|
|||||||
@GerritPersonIdent
|
@GerritPersonIdent
|
||||||
protected Provider<PersonIdent> serverIdent;
|
protected Provider<PersonIdent> serverIdent;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ChangeData.Factory changeDataFactory;
|
||||||
|
|
||||||
protected TestRepository<InMemoryRepository> testRepo;
|
protected TestRepository<InMemoryRepository> testRepo;
|
||||||
protected GerritServer server;
|
protected GerritServer server;
|
||||||
protected TestAccount admin;
|
protected TestAccount admin;
|
||||||
@@ -624,4 +630,8 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
})).containsExactly((Object[])expected).inOrder();
|
})).containsExactly((Object[])expected).inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PatchSet getPatchSet(PatchSet.Id psId) throws OrmException {
|
||||||
|
return changeDataFactory.create(db, psId.getParentKey()).patchSet(psId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@@ -145,9 +146,9 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
|
|||||||
"other content", r.getChangeId());
|
"other content", r.getChangeId());
|
||||||
r.assertOkStatus();
|
r.assertOkStatus();
|
||||||
r.assertChange(Change.Status.MERGED, null, admin);
|
r.assertChange(Change.Status.MERGED, null, admin);
|
||||||
Change c = Iterables.getOnlyElement(
|
ChangeData cd = Iterables.getOnlyElement(
|
||||||
queryProvider.get().byKeyPrefix(r.getChangeId())).change();
|
queryProvider.get().byKeyPrefix(r.getChangeId()));
|
||||||
assertThat(db.patchSets().byChange(c.getId()).toList()).hasSize(2);
|
assertThat(cd.patchSets()).hasSize(2);
|
||||||
assertSubmitApproval(r.getPatchSetId());
|
assertSubmitApproval(r.getPatchSetId());
|
||||||
assertCommit(project, "refs/heads/master");
|
assertCommit(project, "refs/heads/master");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
|||||||
deny(Permission.READ, REGISTERED_USERS, "refs/heads/branch");
|
deny(Permission.READ, REGISTERED_USERS, "refs/heads/branch");
|
||||||
|
|
||||||
Change change1 = db.changes().get(c1);
|
Change change1 = db.changes().get(c1);
|
||||||
PatchSet ps1 = db.patchSets().get(new PatchSet.Id(c1, 1));
|
PatchSet ps1 = getPatchSet(new PatchSet.Id(c1, 1));
|
||||||
|
|
||||||
// Admin's edit is not visible.
|
// Admin's edit is not visible.
|
||||||
setApiUser(admin);
|
setApiUser(admin);
|
||||||
@@ -214,7 +214,7 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
|||||||
allow(Permission.READ, REGISTERED_USERS, "refs/heads/branch");
|
allow(Permission.READ, REGISTERED_USERS, "refs/heads/branch");
|
||||||
|
|
||||||
Change change1 = db.changes().get(c1);
|
Change change1 = db.changes().get(c1);
|
||||||
PatchSet ps1 = db.patchSets().get(new PatchSet.Id(c1, 1));
|
PatchSet ps1 = getPatchSet(new PatchSet.Id(c1, 1));
|
||||||
setApiUser(admin);
|
setApiUser(admin);
|
||||||
editModifier.createEdit(change1, ps1);
|
editModifier.createEdit(change1, ps1);
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
|||||||
@@ -208,8 +208,8 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
c = db.changes().get(c.getId());
|
c = db.changes().get(c.getId());
|
||||||
assertThat(c.currentPatchSetId().get()).isEqualTo(1);
|
assertThat(c.currentPatchSetId().get()).isEqualTo(1);
|
||||||
assertThat(db.patchSets().get(ps1.getId())).isNotNull();
|
assertThat(getPatchSet(ps1.getId())).isNotNull();
|
||||||
assertThat(db.patchSets().get(ps2.getId())).isNull();
|
assertThat(getPatchSet(ps2.getId())).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -256,10 +256,10 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
c = db.changes().get(c.getId());
|
c = db.changes().get(c.getId());
|
||||||
assertThat(c.currentPatchSetId().get()).isEqualTo(3);
|
assertThat(c.currentPatchSetId().get()).isEqualTo(3);
|
||||||
assertThat(db.patchSets().get(ps1.getId())).isNotNull();
|
assertThat(getPatchSet(ps1.getId())).isNotNull();
|
||||||
assertThat(db.patchSets().get(ps2.getId())).isNull();
|
assertThat(getPatchSet(ps2.getId())).isNull();
|
||||||
assertThat(db.patchSets().get(ps3.getId())).isNotNull();
|
assertThat(getPatchSet(ps3.getId())).isNotNull();
|
||||||
assertThat(db.patchSets().get(ps4.getId())).isNull();
|
assertThat(getPatchSet(ps4.getId())).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -284,7 +284,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
c = db.changes().get(c.getId());
|
c = db.changes().get(c.getId());
|
||||||
assertThat(c.currentPatchSetId().get()).isEqualTo(1);
|
assertThat(c.currentPatchSetId().get()).isEqualTo(1);
|
||||||
assertThat(db.patchSets().get(ps1.getId())).isNotNull();
|
assertThat(getPatchSet(ps1.getId())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -442,7 +442,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
c = db.changes().get(c.getId());
|
c = db.changes().get(c.getId());
|
||||||
PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
|
PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
|
||||||
assertThat(c.currentPatchSetId()).isEqualTo(psId2);
|
assertThat(c.currentPatchSetId()).isEqualTo(psId2);
|
||||||
assertThat(db.patchSets().get(psId2).getRevision().get())
|
assertThat(getPatchSet(psId2).getRevision().get())
|
||||||
.isEqualTo(mergedAs.name());
|
.isEqualTo(mergedAs.name());
|
||||||
|
|
||||||
assertProblems(c);
|
assertProblems(c);
|
||||||
@@ -484,7 +484,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
c = db.changes().get(c.getId());
|
c = db.changes().get(c.getId());
|
||||||
PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
|
PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
|
||||||
assertThat(c.currentPatchSetId()).isEqualTo(psId2);
|
assertThat(c.currentPatchSetId()).isEqualTo(psId2);
|
||||||
assertThat(db.patchSets().get(psId2).getRevision().get())
|
assertThat(getPatchSet(psId2).getRevision().get())
|
||||||
.isEqualTo(mergedAs.name());
|
.isEqualTo(mergedAs.name());
|
||||||
|
|
||||||
assertProblems(c);
|
assertProblems(c);
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
@Inject
|
@Inject
|
||||||
private ChangeEditModifier editModifier;
|
private ChangeEditModifier editModifier;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ChangeData.Factory changeDataFactory;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRelatedNoResult() throws Exception {
|
public void getRelatedNoResult() throws Exception {
|
||||||
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo);
|
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo);
|
||||||
@@ -521,7 +518,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
pushHead(testRepo, "refs/for/master", false);
|
pushHead(testRepo, "refs/for/master", false);
|
||||||
|
|
||||||
Change ch2 = getChange(c2_1).change();
|
Change ch2 = getChange(c2_1).change();
|
||||||
editModifier.createEdit(ch2, getPatchSet(ch2));
|
editModifier.createEdit(ch2, getPatchSet(ch2.currentPatchSetId()));
|
||||||
editModifier.modifyFile(editUtil.byChange(ch2).get(), "a.txt",
|
editModifier.modifyFile(editUtil.byChange(ch2).get(), "a.txt",
|
||||||
RestSession.newRawInput(new byte[] {'a'}));
|
RestSession.newRawInput(new byte[] {'a'}));
|
||||||
ObjectId editRev =
|
ObjectId editRev =
|
||||||
@@ -569,7 +566,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pretend PS1,1 was pushed before the groups field was added.
|
// Pretend PS1,1 was pushed before the groups field was added.
|
||||||
PatchSet ps1_1 = db.patchSets().get(psId1_1);
|
PatchSet ps1_1 = getPatchSet(psId1_1);
|
||||||
ps1_1.setGroups(null);
|
ps1_1.setGroups(null);
|
||||||
db.patchSets().update(ImmutableList.of(ps1_1));
|
db.patchSets().update(ImmutableList.of(ps1_1));
|
||||||
indexer.index(changeDataFactory.create(db, psId1_1.getParentKey()));
|
indexer.index(changeDataFactory.create(db, psId1_1.getParentKey()));
|
||||||
@@ -614,10 +611,6 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
return getChange(c).change().currentPatchSetId();
|
return getChange(c).change().currentPatchSetId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PatchSet getPatchSet(Change c) throws OrmException {
|
|
||||||
return db.patchSets().get(c.currentPatchSetId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChangeData getChange(ObjectId c) throws OrmException {
|
private ChangeData getChange(ObjectId c) throws OrmException {
|
||||||
return Iterables.getOnlyElement(queryProvider.get().byCommit(c));
|
return Iterables.getOnlyElement(queryProvider.get().byCommit(c));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.client.Patch;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
@@ -53,16 +54,19 @@ public class CatServlet extends HttpServlet {
|
|||||||
private final Provider<CurrentUser> userProvider;
|
private final Provider<CurrentUser> userProvider;
|
||||||
private final ChangeControl.GenericFactory changeControl;
|
private final ChangeControl.GenericFactory changeControl;
|
||||||
private final ChangeEditUtil changeEditUtil;
|
private final ChangeEditUtil changeEditUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CatServlet(Provider<ReviewDb> sf,
|
CatServlet(Provider<ReviewDb> sf,
|
||||||
ChangeControl.GenericFactory ccf,
|
ChangeControl.GenericFactory ccf,
|
||||||
Provider<CurrentUser> usrprv,
|
Provider<CurrentUser> usrprv,
|
||||||
ChangeEditUtil ceu) {
|
ChangeEditUtil ceu,
|
||||||
|
PatchSetUtil psu) {
|
||||||
requestDb = sf;
|
requestDb = sf;
|
||||||
changeControl = ccf;
|
changeControl = ccf;
|
||||||
userProvider = usrprv;
|
userProvider = usrprv;
|
||||||
changeEditUtil = ceu;
|
changeEditUtil = ceu;
|
||||||
|
psUtil = psu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,7 +139,8 @@ public class CatServlet extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PatchSet patchSet = db.patchSets().get(patchKey.getParentKey());
|
PatchSet patchSet =
|
||||||
|
psUtil.get(db, control.getNotes(), patchKey.getParentKey());
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd.rpc.changedetail;
|
package com.google.gerrit.httpd.rpc.changedetail;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.PatchSetDetail;
|
import com.google.gerrit.common.data.PatchSetDetail;
|
||||||
@@ -24,7 +26,6 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
|||||||
import com.google.gerrit.httpd.rpc.Handler;
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountPatchReview;
|
import com.google.gerrit.reviewdb.client.AccountPatchReview;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
|
||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
@@ -32,6 +33,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
@@ -76,6 +78,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
private final Provider<CurrentUser> userProvider;
|
private final Provider<CurrentUser> userProvider;
|
||||||
private final ChangeControl.GenericFactory changeControlFactory;
|
private final ChangeControl.GenericFactory changeControlFactory;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
|
|
||||||
private Project.NameKey project;
|
private Project.NameKey project;
|
||||||
@@ -95,6 +98,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
final Provider<CurrentUser> userProvider,
|
final Provider<CurrentUser> userProvider,
|
||||||
final ChangeControl.GenericFactory changeControlFactory,
|
final ChangeControl.GenericFactory changeControlFactory,
|
||||||
final PatchLineCommentsUtil plcUtil,
|
final PatchLineCommentsUtil plcUtil,
|
||||||
|
final PatchSetUtil psUtil,
|
||||||
ChangeEditUtil editUtil,
|
ChangeEditUtil editUtil,
|
||||||
@Assisted("psIdBase") @Nullable final PatchSet.Id psIdBase,
|
@Assisted("psIdBase") @Nullable final PatchSet.Id psIdBase,
|
||||||
@Assisted("psIdNew") final PatchSet.Id psIdNew,
|
@Assisted("psIdNew") final PatchSet.Id psIdNew,
|
||||||
@@ -105,10 +109,16 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
this.userProvider = userProvider;
|
this.userProvider = userProvider;
|
||||||
this.changeControlFactory = changeControlFactory;
|
this.changeControlFactory = changeControlFactory;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
|
|
||||||
this.psIdBase = psIdBase;
|
this.psIdBase = psIdBase;
|
||||||
this.psIdNew = psIdNew;
|
this.psIdNew = psIdNew;
|
||||||
|
if (psIdBase != null && psIdNew != null) {
|
||||||
|
checkArgument(psIdBase.getParentKey().equals(psIdNew.getParentKey()),
|
||||||
|
"cannot compare PatchSets from different changes: %s and %s",
|
||||||
|
psIdBase, psIdNew);
|
||||||
|
}
|
||||||
this.diffPrefs = diffPrefs;
|
this.diffPrefs = diffPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,32 +127,35 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
PatchSetInfoNotAvailableException, NoSuchChangeException, AuthException,
|
PatchSetInfoNotAvailableException, NoSuchChangeException, AuthException,
|
||||||
IOException {
|
IOException {
|
||||||
Optional<ChangeEdit> edit = null;
|
Optional<ChangeEdit> edit = null;
|
||||||
|
ChangeNotes notes;
|
||||||
if (control == null || patchSet == null) {
|
if (control == null || patchSet == null) {
|
||||||
control = changeControlFactory.validateFor(psIdNew.getParentKey(),
|
control = changeControlFactory.validateFor(psIdNew.getParentKey(),
|
||||||
userProvider.get());
|
userProvider.get());
|
||||||
|
notes = control.getNotes();
|
||||||
if (psIdNew.get() == 0) {
|
if (psIdNew.get() == 0) {
|
||||||
Change change = db.changes().get(psIdNew.getParentKey());
|
edit = editUtil.byChange(control.getChange());
|
||||||
edit = editUtil.byChange(change);
|
|
||||||
if (edit.isPresent()) {
|
if (edit.isPresent()) {
|
||||||
patchSet = edit.get().getBasePatchSet();
|
patchSet = edit.get().getBasePatchSet();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
patchSet = db.patchSets().get(psIdNew);
|
patchSet = psUtil.get(db, notes, psIdNew);
|
||||||
}
|
}
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
throw new NoSuchEntityException();
|
throw new NoSuchEntityException();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
notes = control.getNotes();
|
||||||
}
|
}
|
||||||
project = control.getProject().getNameKey();
|
project = control.getProject().getNameKey();
|
||||||
final PatchList list;
|
final PatchList list;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (psIdBase != null) {
|
if (psIdBase != null) {
|
||||||
oldId = toObjectId(psIdBase);
|
oldId = toObjectId(psUtil.get(db, notes, psIdBase));
|
||||||
if (edit != null && edit.isPresent()) {
|
if (edit != null && edit.isPresent()) {
|
||||||
newId = edit.get().getEditCommit().toObjectId();
|
newId = edit.get().getEditCommit().toObjectId();
|
||||||
} else {
|
} else {
|
||||||
newId = toObjectId(psIdNew);
|
newId = toObjectId(patchSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
list = listFor(keyFor(diffPrefs.ignoreWhitespace));
|
list = listFor(keyFor(diffPrefs.ignoreWhitespace));
|
||||||
@@ -159,7 +172,6 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
byKey.put(p.getKey(), p);
|
byKey.put(p.getKey(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeNotes notes = control.getNotes();
|
|
||||||
if (edit == null) {
|
if (edit == null) {
|
||||||
for (PatchLineComment c : plcUtil.publishedByPatchSet(db, notes, psIdNew)) {
|
for (PatchLineComment c : plcUtil.publishedByPatchSet(db, notes, psIdNew)) {
|
||||||
final Patch p = byKey.get(c.getKey().getParentKey());
|
final Patch p = byKey.get(c.getKey().getParentKey());
|
||||||
@@ -202,17 +214,11 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectId toObjectId(final PatchSet.Id psId) throws OrmException,
|
private ObjectId toObjectId(PatchSet ps) throws NoSuchEntityException {
|
||||||
NoSuchEntityException {
|
|
||||||
final PatchSet ps = db.patchSets().get(psId);
|
|
||||||
if (ps == null) {
|
|
||||||
throw new NoSuchEntityException();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return ObjectId.fromString(ps.getRevision().get());
|
return ObjectId.fromString(ps.getRevision().get());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.error("Patch set " + psId + " has invalid revision");
|
log.error("Patch set " + ps.getId() + " has invalid revision");
|
||||||
throw new NoSuchEntityException();
|
throw new NoSuchEntityException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,18 +67,21 @@ public class ApprovalCopier {
|
|||||||
private final ChangeKindCache changeKindCache;
|
private final ChangeKindCache changeKindCache;
|
||||||
private final LabelNormalizer labelNormalizer;
|
private final LabelNormalizer labelNormalizer;
|
||||||
private final ChangeData.Factory changeDataFactory;
|
private final ChangeData.Factory changeDataFactory;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApprovalCopier(GitRepositoryManager repoManager,
|
ApprovalCopier(GitRepositoryManager repoManager,
|
||||||
ProjectCache projectCache,
|
ProjectCache projectCache,
|
||||||
ChangeKindCache changeKindCache,
|
ChangeKindCache changeKindCache,
|
||||||
LabelNormalizer labelNormalizer,
|
LabelNormalizer labelNormalizer,
|
||||||
ChangeData.Factory changeDataFactory) {
|
ChangeData.Factory changeDataFactory,
|
||||||
|
PatchSetUtil psUtil) {
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
this.changeKindCache = changeKindCache;
|
this.changeKindCache = changeKindCache;
|
||||||
this.labelNormalizer = labelNormalizer;
|
this.labelNormalizer = labelNormalizer;
|
||||||
this.changeDataFactory = changeDataFactory;
|
this.changeDataFactory = changeDataFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copy(ReviewDb db, ChangeControl ctl, PatchSet ps)
|
public void copy(ReviewDb db, ChangeControl ctl, PatchSet ps)
|
||||||
@@ -88,7 +91,7 @@ public class ApprovalCopier {
|
|||||||
|
|
||||||
Iterable<PatchSetApproval> getForPatchSet(ReviewDb db,
|
Iterable<PatchSetApproval> getForPatchSet(ReviewDb db,
|
||||||
ChangeControl ctl, PatchSet.Id psId) throws OrmException {
|
ChangeControl ctl, PatchSet.Id psId) throws OrmException {
|
||||||
PatchSet ps = db.patchSets().get(psId);
|
PatchSet ps = psUtil.get(db, ctl.getNotes(), psId);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
|||||||
import com.google.gerrit.server.git.UpdateException;
|
import com.google.gerrit.server.git.UpdateException;
|
||||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||||
import com.google.gerrit.server.mail.RevertedSender;
|
import com.google.gerrit.server.mail.RevertedSender;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
@@ -164,6 +165,7 @@ public class ChangeUtil {
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final Sequences seq;
|
private final Sequences seq;
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final ChangeControl.GenericFactory changeControlFactory;
|
private final ChangeControl.GenericFactory changeControlFactory;
|
||||||
private final RevertedSender.Factory revertedSenderFactory;
|
private final RevertedSender.Factory revertedSenderFactory;
|
||||||
private final ChangeInserter.Factory changeInserterFactory;
|
private final ChangeInserter.Factory changeInserterFactory;
|
||||||
@@ -177,6 +179,7 @@ public class ChangeUtil {
|
|||||||
Provider<ReviewDb> db,
|
Provider<ReviewDb> db,
|
||||||
Sequences seq,
|
Sequences seq,
|
||||||
Provider<InternalChangeQuery> queryProvider,
|
Provider<InternalChangeQuery> queryProvider,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
ChangeControl.GenericFactory changeControlFactory,
|
ChangeControl.GenericFactory changeControlFactory,
|
||||||
RevertedSender.Factory revertedSenderFactory,
|
RevertedSender.Factory revertedSenderFactory,
|
||||||
ChangeInserter.Factory changeInserterFactory,
|
ChangeInserter.Factory changeInserterFactory,
|
||||||
@@ -188,6 +191,7 @@ public class ChangeUtil {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.seq = seq;
|
this.seq = seq;
|
||||||
this.queryProvider = queryProvider;
|
this.queryProvider = queryProvider;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.changeControlFactory = changeControlFactory;
|
this.changeControlFactory = changeControlFactory;
|
||||||
this.revertedSenderFactory = revertedSenderFactory;
|
this.revertedSenderFactory = revertedSenderFactory;
|
||||||
this.changeInserterFactory = changeInserterFactory;
|
this.changeInserterFactory = changeInserterFactory;
|
||||||
@@ -203,7 +207,7 @@ public class ChangeUtil {
|
|||||||
MissingObjectException, IncorrectObjectTypeException, IOException,
|
MissingObjectException, IncorrectObjectTypeException, IOException,
|
||||||
RestApiException, UpdateException {
|
RestApiException, UpdateException {
|
||||||
Change.Id changeIdToRevert = patchSetId.getParentKey();
|
Change.Id changeIdToRevert = patchSetId.getParentKey();
|
||||||
PatchSet patch = db.get().patchSets().get(patchSetId);
|
PatchSet patch = psUtil.get(db.get(), ctl.getNotes(), patchSetId);
|
||||||
if (patch == null) {
|
if (patch == null) {
|
||||||
throw new NoSuchChangeException(changeIdToRevert);
|
throw new NoSuchChangeException(changeIdToRevert);
|
||||||
}
|
}
|
||||||
@@ -295,16 +299,17 @@ public class ChangeUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage(Change change)
|
public String getMessage(ChangeNotes notes)
|
||||||
throws NoSuchChangeException, OrmException,
|
throws NoSuchChangeException, OrmException,
|
||||||
MissingObjectException, IncorrectObjectTypeException, IOException {
|
MissingObjectException, IncorrectObjectTypeException, IOException {
|
||||||
Change.Id changeId = change.getId();
|
Change.Id changeId = notes.getChangeId();
|
||||||
PatchSet ps = db.get().patchSets().get(change.currentPatchSetId());
|
PatchSet ps = psUtil.current(db.get(), notes);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
throw new NoSuchChangeException(changeId);
|
throw new NoSuchChangeException(changeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Repository git = gitManager.openRepository(change.getProject());
|
try (Repository git =
|
||||||
|
gitManager.openRepository(notes.getChange().getProject());
|
||||||
RevWalk revWalk = new RevWalk(git)) {
|
RevWalk revWalk = new RevWalk(git)) {
|
||||||
RevCommit commit = revWalk.parseCommit(
|
RevCommit commit = revWalk.parseCommit(
|
||||||
ObjectId.fromString(ps.getRevision().get()));
|
ObjectId.fromString(ps.getRevision().get()));
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (C) 2016 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;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
/** Utilities for manipulating patch sets. */
|
||||||
|
@Singleton
|
||||||
|
public class PatchSetUtil {
|
||||||
|
@Inject
|
||||||
|
PatchSetUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PatchSet current(ReviewDb db, ChangeNotes notes)
|
||||||
|
throws OrmException {
|
||||||
|
return get(db, notes, notes.getChange().currentPatchSetId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") // TODO(dborowitz): Read from notedb.
|
||||||
|
public PatchSet get(ReviewDb db, ChangeNotes notes, PatchSet.Id psId)
|
||||||
|
throws OrmException {
|
||||||
|
return db.patchSets().get(psId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableList<PatchSet> byChange(ReviewDb db, ChangeNotes notes)
|
||||||
|
throws OrmException {
|
||||||
|
return ChangeUtil.PS_ID_ORDER.immutableSortedCopy(
|
||||||
|
db.patchSets().byChange(notes.getChangeId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.Context;
|
import com.google.gerrit.server.git.BatchUpdate.Context;
|
||||||
@@ -58,6 +59,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
|||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ChangeJson.Factory json;
|
private final ChangeJson.Factory json;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final BatchUpdate.Factory batchUpdateFactory;
|
private final BatchUpdate.Factory batchUpdateFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -66,12 +68,14 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
|||||||
Provider<ReviewDb> dbProvider,
|
Provider<ReviewDb> dbProvider,
|
||||||
ChangeJson.Factory json,
|
ChangeJson.Factory json,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
BatchUpdate.Factory batchUpdateFactory) {
|
BatchUpdate.Factory batchUpdateFactory) {
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
this.abandonedSenderFactory = abandonedSenderFactory;
|
this.abandonedSenderFactory = abandonedSenderFactory;
|
||||||
this.dbProvider = dbProvider;
|
this.dbProvider = dbProvider;
|
||||||
this.json = json;
|
this.json = json;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.batchUpdateFactory = batchUpdateFactory;
|
this.batchUpdateFactory = batchUpdateFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +129,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
|||||||
throw new ResourceConflictException(
|
throw new ResourceConflictException(
|
||||||
"draft changes cannot be abandoned");
|
"draft changes cannot be abandoned");
|
||||||
}
|
}
|
||||||
patchSet = ctx.getDb().patchSets().get(psId);
|
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
change.setStatus(Change.Status.ABANDONED);
|
change.setStatus(Change.Status.ABANDONED);
|
||||||
change.setLastUpdatedOn(ctx.getWhen());
|
change.setLastUpdatedOn(ctx.getWhen());
|
||||||
ctx.saveChange();
|
ctx.saveChange();
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import com.google.gerrit.extensions.restapi.RestView;
|
|||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.WebLinks;
|
import com.google.gerrit.server.WebLinks;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditJson;
|
import com.google.gerrit.server.edit.ChangeEditJson;
|
||||||
@@ -150,6 +151,7 @@ public class ChangeEdits implements
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
private final ChangeEditModifier editModifier;
|
private final ChangeEditModifier editModifier;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Put putEdit;
|
private final Put putEdit;
|
||||||
private final Change change;
|
private final Change change;
|
||||||
private final String path;
|
private final String path;
|
||||||
@@ -158,12 +160,14 @@ public class ChangeEdits implements
|
|||||||
Create(Provider<ReviewDb> db,
|
Create(Provider<ReviewDb> db,
|
||||||
ChangeEditUtil editUtil,
|
ChangeEditUtil editUtil,
|
||||||
ChangeEditModifier editModifier,
|
ChangeEditModifier editModifier,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
Put putEdit,
|
Put putEdit,
|
||||||
@Assisted Change change,
|
@Assisted Change change,
|
||||||
@Assisted @Nullable String path) {
|
@Assisted @Nullable String path) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
this.editModifier = editModifier;
|
this.editModifier = editModifier;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.putEdit = putEdit;
|
this.putEdit = putEdit;
|
||||||
this.change = change;
|
this.change = change;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
@@ -179,7 +183,7 @@ public class ChangeEdits implements
|
|||||||
"edit already exists for the change %s",
|
"edit already exists for the change %s",
|
||||||
resource.getId()));
|
resource.getId()));
|
||||||
}
|
}
|
||||||
edit = createEdit();
|
edit = createEdit(resource);
|
||||||
if (!Strings.isNullOrEmpty(path)) {
|
if (!Strings.isNullOrEmpty(path)) {
|
||||||
putEdit.apply(new ChangeEditResource(resource, edit.get(), path),
|
putEdit.apply(new ChangeEditResource(resource, edit.get(), path),
|
||||||
input);
|
input);
|
||||||
@@ -187,10 +191,11 @@ public class ChangeEdits implements
|
|||||||
return Response.none();
|
return Response.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ChangeEdit> createEdit() throws AuthException,
|
private Optional<ChangeEdit> createEdit(ChangeResource resource)
|
||||||
IOException, ResourceConflictException, OrmException {
|
throws AuthException, IOException, ResourceConflictException,
|
||||||
|
OrmException {
|
||||||
editModifier.createEdit(change,
|
editModifier.createEdit(change,
|
||||||
db.get().patchSets().get(change.currentPatchSetId()));
|
psUtil.current(db.get(), resource.getNotes()));
|
||||||
return editUtil.byChange(change);
|
return editUtil.byChange(change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,16 +211,19 @@ public class ChangeEdits implements
|
|||||||
|
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
private final ChangeEditModifier editModifier;
|
private final ChangeEditModifier editModifier;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final String path;
|
private final String path;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DeleteFile(ChangeEditUtil editUtil,
|
DeleteFile(ChangeEditUtil editUtil,
|
||||||
ChangeEditModifier editModifier,
|
ChangeEditModifier editModifier,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
Provider<ReviewDb> db,
|
Provider<ReviewDb> db,
|
||||||
@Assisted String path) {
|
@Assisted String path) {
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
this.editModifier = editModifier;
|
this.editModifier = editModifier;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
@@ -233,8 +241,8 @@ public class ChangeEdits implements
|
|||||||
// Even if the latest patch set changed since the user triggered
|
// Even if the latest patch set changed since the user triggered
|
||||||
// the operation, deleting the whole file is probably still what
|
// the operation, deleting the whole file is probably still what
|
||||||
// they intended.
|
// they intended.
|
||||||
editModifier.createEdit(rsrc.getChange(), db.get().patchSets().get(
|
editModifier.createEdit(rsrc.getChange(),
|
||||||
rsrc.getChange().currentPatchSetId()));
|
psUtil.current(db.get(), rsrc.getNotes()));
|
||||||
edit = editUtil.byChange(rsrc.getChange());
|
edit = editUtil.byChange(rsrc.getChange());
|
||||||
editModifier.deleteFile(edit.get(), path);
|
editModifier.deleteFile(edit.get(), path);
|
||||||
}
|
}
|
||||||
@@ -321,14 +329,17 @@ public class ChangeEdits implements
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
private final ChangeEditModifier editModifier;
|
private final ChangeEditModifier editModifier;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Post(Provider<ReviewDb> db,
|
Post(Provider<ReviewDb> db,
|
||||||
ChangeEditUtil editUtil,
|
ChangeEditUtil editUtil,
|
||||||
ChangeEditModifier editModifier) {
|
ChangeEditModifier editModifier,
|
||||||
|
PatchSetUtil psUtil) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
this.editModifier = editModifier;
|
this.editModifier = editModifier;
|
||||||
|
this.psUtil = psUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -337,7 +348,7 @@ public class ChangeEdits implements
|
|||||||
ResourceConflictException, OrmException {
|
ResourceConflictException, OrmException {
|
||||||
Optional<ChangeEdit> edit = editUtil.byChange(resource.getChange());
|
Optional<ChangeEdit> edit = editUtil.byChange(resource.getChange());
|
||||||
if (!edit.isPresent()) {
|
if (!edit.isPresent()) {
|
||||||
edit = createEdit(resource.getChange());
|
edit = createEdit(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@@ -351,12 +362,12 @@ public class ChangeEdits implements
|
|||||||
return Response.none();
|
return Response.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ChangeEdit> createEdit(Change change)
|
private Optional<ChangeEdit> createEdit(ChangeResource resource)
|
||||||
throws AuthException, IOException, ResourceConflictException,
|
throws AuthException, IOException, ResourceConflictException,
|
||||||
OrmException {
|
OrmException {
|
||||||
editModifier.createEdit(change,
|
editModifier.createEdit(resource.getChange(),
|
||||||
db.get().patchSets().get(change.currentPatchSetId()));
|
psUtil.current(db.get(), resource.getNotes()));
|
||||||
return editUtil.byChange(change);
|
return editUtil.byChange(resource.getChange());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,14 +507,17 @@ public class ChangeEdits implements
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final ChangeEditModifier editModifier;
|
private final ChangeEditModifier editModifier;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EditMessage(Provider<ReviewDb> db,
|
EditMessage(Provider<ReviewDb> db,
|
||||||
ChangeEditModifier editModifier,
|
ChangeEditModifier editModifier,
|
||||||
ChangeEditUtil editUtil) {
|
ChangeEditUtil editUtil,
|
||||||
|
PatchSetUtil psUtil) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.editModifier = editModifier;
|
this.editModifier = editModifier;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -513,7 +527,7 @@ public class ChangeEdits implements
|
|||||||
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
|
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
|
||||||
if (!edit.isPresent()) {
|
if (!edit.isPresent()) {
|
||||||
editModifier.createEdit(rsrc.getChange(),
|
editModifier.createEdit(rsrc.getChange(),
|
||||||
db.get().patchSets().get(rsrc.getChange().currentPatchSetId()));
|
psUtil.current(db.get(), rsrc.getNotes()));
|
||||||
edit = editUtil.byChange(rsrc.getChange());
|
edit = editUtil.byChange(rsrc.getChange());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.google.gerrit.server.ChangeMessagesUtil;
|
|||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.Sequences;
|
import com.google.gerrit.server.Sequences;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.CodeReviewCommit;
|
import com.google.gerrit.server.git.CodeReviewCommit;
|
||||||
@@ -81,6 +82,7 @@ public class CherryPickChange {
|
|||||||
private final PatchSetInserter.Factory patchSetInserterFactory;
|
private final PatchSetInserter.Factory patchSetInserterFactory;
|
||||||
private final MergeUtil.Factory mergeUtilFactory;
|
private final MergeUtil.Factory mergeUtilFactory;
|
||||||
private final ChangeMessagesUtil changeMessagesUtil;
|
private final ChangeMessagesUtil changeMessagesUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final ChangeUpdate.Factory updateFactory;
|
private final ChangeUpdate.Factory updateFactory;
|
||||||
private final BatchUpdate.Factory batchUpdateFactory;
|
private final BatchUpdate.Factory batchUpdateFactory;
|
||||||
|
|
||||||
@@ -95,6 +97,7 @@ public class CherryPickChange {
|
|||||||
PatchSetInserter.Factory patchSetInserterFactory,
|
PatchSetInserter.Factory patchSetInserterFactory,
|
||||||
MergeUtil.Factory mergeUtilFactory,
|
MergeUtil.Factory mergeUtilFactory,
|
||||||
ChangeMessagesUtil changeMessagesUtil,
|
ChangeMessagesUtil changeMessagesUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
ChangeUpdate.Factory updateFactory,
|
ChangeUpdate.Factory updateFactory,
|
||||||
BatchUpdate.Factory batchUpdateFactory) {
|
BatchUpdate.Factory batchUpdateFactory) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -107,6 +110,7 @@ public class CherryPickChange {
|
|||||||
this.patchSetInserterFactory = patchSetInserterFactory;
|
this.patchSetInserterFactory = patchSetInserterFactory;
|
||||||
this.mergeUtilFactory = mergeUtilFactory;
|
this.mergeUtilFactory = mergeUtilFactory;
|
||||||
this.changeMessagesUtil = changeMessagesUtil;
|
this.changeMessagesUtil = changeMessagesUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.batchUpdateFactory = batchUpdateFactory;
|
this.batchUpdateFactory = batchUpdateFactory;
|
||||||
}
|
}
|
||||||
@@ -177,10 +181,13 @@ public class CherryPickChange {
|
|||||||
throw new InvalidChangeOperationException("Several changes with key "
|
throw new InvalidChangeOperationException("Several changes with key "
|
||||||
+ changeKey + " reside on the same branch. "
|
+ changeKey + " reside on the same branch. "
|
||||||
+ "Cannot create a new patch set.");
|
+ "Cannot create a new patch set.");
|
||||||
} else if (destChanges.size() == 1) {
|
}
|
||||||
|
if (destChanges.size() == 1) {
|
||||||
// The change key exists on the destination branch. The cherry pick
|
// The change key exists on the destination branch. The cherry pick
|
||||||
// will be added as a new patch set.
|
// will be added as a new patch set.
|
||||||
return insertPatchSet(git, revWalk, oi, destChanges.get(0).change(),
|
ChangeControl destCtl = refControl.getProjectControl()
|
||||||
|
.controlFor(destChanges.get(0).change());
|
||||||
|
return insertPatchSet(git, revWalk, oi, destCtl,
|
||||||
cherryPickCommit, refControl, identifiedUser);
|
cherryPickCommit, refControl, identifiedUser);
|
||||||
} else {
|
} else {
|
||||||
// Change key not found on destination branch. We can create a new
|
// Change key not found on destination branch. We can create a new
|
||||||
@@ -208,15 +215,16 @@ public class CherryPickChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Change.Id insertPatchSet(Repository git, RevWalk revWalk,
|
private Change.Id insertPatchSet(Repository git, RevWalk revWalk,
|
||||||
ObjectInserter oi, Change change, CodeReviewCommit cherryPickCommit,
|
ObjectInserter oi, ChangeControl ctl, CodeReviewCommit cherryPickCommit,
|
||||||
RefControl refControl, IdentifiedUser identifiedUser)
|
RefControl refControl, IdentifiedUser identifiedUser)
|
||||||
throws IOException, OrmException, UpdateException, RestApiException {
|
throws IOException, OrmException, UpdateException, RestApiException {
|
||||||
|
Change change = ctl.getChange();
|
||||||
PatchSet.Id psId =
|
PatchSet.Id psId =
|
||||||
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
|
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
|
||||||
PatchSetInserter inserter = patchSetInserterFactory
|
PatchSetInserter inserter = patchSetInserterFactory
|
||||||
.create(refControl, psId, cherryPickCommit);
|
.create(refControl, psId, cherryPickCommit);
|
||||||
PatchSet.Id newPatchSetId = inserter.getPatchSetId();
|
PatchSet.Id newPatchSetId = inserter.getPatchSetId();
|
||||||
PatchSet current = db.get().patchSets().get(change.currentPatchSetId());
|
PatchSet current = psUtil.current(db.get(), ctl.getNotes());
|
||||||
|
|
||||||
try (BatchUpdate bu = batchUpdateFactory.create(
|
try (BatchUpdate bu = batchUpdateFactory.create(
|
||||||
db.get(), change.getDest().getParentKey(), identifiedUser,
|
db.get(), change.getDest().getParentKey(), identifiedUser,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.google.gerrit.server.ChangeUtil;
|
|||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.Sequences;
|
import com.google.gerrit.server.Sequences;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
@@ -84,6 +85,7 @@ public class CreateChange implements
|
|||||||
private final ChangeJson.Factory jsonFactory;
|
private final ChangeJson.Factory jsonFactory;
|
||||||
private final ChangeUtil changeUtil;
|
private final ChangeUtil changeUtil;
|
||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final boolean allowDrafts;
|
private final boolean allowDrafts;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -97,6 +99,7 @@ public class CreateChange implements
|
|||||||
ChangeJson.Factory json,
|
ChangeJson.Factory json,
|
||||||
ChangeUtil changeUtil,
|
ChangeUtil changeUtil,
|
||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
@GerritServerConfig Config config) {
|
@GerritServerConfig Config config) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.gitManager = gitManager;
|
this.gitManager = gitManager;
|
||||||
@@ -108,6 +111,7 @@ public class CreateChange implements
|
|||||||
this.jsonFactory = json;
|
this.jsonFactory = json;
|
||||||
this.changeUtil = changeUtil;
|
this.changeUtil = changeUtil;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.allowDrafts = config.getBoolean("change", "allowDrafts", true);
|
this.allowDrafts = config.getBoolean("change", "allowDrafts", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,8 +172,7 @@ public class CreateChange implements
|
|||||||
throw new InvalidChangeOperationException(
|
throw new InvalidChangeOperationException(
|
||||||
"Base change not found: " + input.baseChange);
|
"Base change not found: " + input.baseChange);
|
||||||
}
|
}
|
||||||
PatchSet ps =
|
PatchSet ps = psUtil.current(db.get(), ctl.getNotes());
|
||||||
db.get().patchSets().get(ctl.getChange().currentPatchSetId());
|
|
||||||
parentCommit = ObjectId.fromString(ps.getRevision().get());
|
parentCommit = ObjectId.fromString(ps.getRevision().get());
|
||||||
groups = ps.getGroups();
|
groups = ps.getGroups();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.UpdateException;
|
import com.google.gerrit.server.git.UpdateException;
|
||||||
@@ -50,6 +51,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
|
|||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
private final Provider<CommentJson> commentJson;
|
private final Provider<CommentJson> commentJson;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -57,11 +59,13 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
|
|||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
Provider<CommentJson> commentJson,
|
Provider<CommentJson> commentJson,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
PatchListCache patchListCache) {
|
PatchListCache patchListCache) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.commentJson = commentJson;
|
this.commentJson = commentJson;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +106,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
|
|||||||
@Override
|
@Override
|
||||||
public void updateChange(ChangeContext ctx)
|
public void updateChange(ChangeContext ctx)
|
||||||
throws ResourceNotFoundException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
PatchSet ps = ctx.getDb().patchSets().get(psId);
|
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
throw new ResourceNotFoundException("patch set not found: " + psId);
|
throw new ResourceNotFoundException("patch set not found: " + psId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.change;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -23,6 +24,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
|||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.StarredChangesUtil;
|
import com.google.gerrit.server.StarredChangesUtil;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
@@ -44,14 +46,17 @@ class DeleteDraftChangeOp extends BatchUpdate.Op {
|
|||||||
return cfg.getBoolean("change", "allowDrafts", true);
|
return cfg.getBoolean("change", "allowDrafts", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final StarredChangesUtil starredChangesUtil;
|
private final StarredChangesUtil starredChangesUtil;
|
||||||
private final boolean allowDrafts;
|
private final boolean allowDrafts;
|
||||||
|
|
||||||
private Change.Id id;
|
private Change.Id id;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DeleteDraftChangeOp(StarredChangesUtil starredChangesUtil,
|
DeleteDraftChangeOp(PatchSetUtil psUtil,
|
||||||
|
StarredChangesUtil starredChangesUtil,
|
||||||
@GerritServerConfig Config cfg) {
|
@GerritServerConfig Config cfg) {
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.starredChangesUtil = starredChangesUtil;
|
this.starredChangesUtil = starredChangesUtil;
|
||||||
this.allowDrafts = allowDrafts(cfg);
|
this.allowDrafts = allowDrafts(cfg);
|
||||||
}
|
}
|
||||||
@@ -76,7 +81,8 @@ class DeleteDraftChangeOp extends BatchUpdate.Op {
|
|||||||
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
|
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
|
||||||
throw new AuthException("Not permitted to delete this draft change");
|
throw new AuthException("Not permitted to delete this draft change");
|
||||||
}
|
}
|
||||||
List<PatchSet> patchSets = ctx.getDb().patchSets().byChange(id).toList();
|
List<PatchSet> patchSets = ImmutableList.copyOf(
|
||||||
|
psUtil.byChange(ctx.getDb(), ctx.getNotes()));
|
||||||
for (PatchSet ps : patchSets) {
|
for (PatchSet ps : patchSets) {
|
||||||
if (!ps.isDraft()) {
|
if (!ps.isDraft()) {
|
||||||
throw new ResourceConflictException("Cannot delete draft change " + id
|
throw new ResourceConflictException("Cannot delete draft change " + id
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.change.DeleteDraftComment.Input;
|
import com.google.gerrit.server.change.DeleteDraftComment.Input;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
@@ -47,16 +48,19 @@ public class DeleteDraftComment
|
|||||||
|
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DeleteDraftComment(Provider<ReviewDb> db,
|
DeleteDraftComment(Provider<ReviewDb> db,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
PatchListCache patchListCache) {
|
PatchListCache patchListCache) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
}
|
}
|
||||||
@@ -90,7 +94,7 @@ public class DeleteDraftComment
|
|||||||
return; // Nothing to do.
|
return; // Nothing to do.
|
||||||
}
|
}
|
||||||
PatchSet.Id psId = key.getParentKey().getParentKey();
|
PatchSet.Id psId = key.getParentKey().getParentKey();
|
||||||
PatchSet ps = ctx.getDb().patchSets().get(psId);
|
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
throw new ResourceNotFoundException("patch set not found: " + psId);
|
throw new ResourceNotFoundException("patch set not found: " + psId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.change.DeleteDraftPatchSet.Input;
|
import com.google.gerrit.server.change.DeleteDraftPatchSet.Input;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
@@ -57,6 +58,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Provider<DeleteDraftChangeOp> deleteChangeOpProvider;
|
private final Provider<DeleteDraftChangeOp> deleteChangeOpProvider;
|
||||||
private final boolean allowDrafts;
|
private final boolean allowDrafts;
|
||||||
|
|
||||||
@@ -64,11 +66,13 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
|||||||
public DeleteDraftPatchSet(Provider<ReviewDb> db,
|
public DeleteDraftPatchSet(Provider<ReviewDb> db,
|
||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
PatchSetInfoFactory patchSetInfoFactory,
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
Provider<DeleteDraftChangeOp> deleteChangeOpProvider,
|
Provider<DeleteDraftChangeOp> deleteChangeOpProvider,
|
||||||
@GerritServerConfig Config cfg) {
|
@GerritServerConfig Config cfg) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.deleteChangeOpProvider = deleteChangeOpProvider;
|
this.deleteChangeOpProvider = deleteChangeOpProvider;
|
||||||
this.allowDrafts = cfg.getBoolean("change", "allowDrafts", true);
|
this.allowDrafts = cfg.getBoolean("change", "allowDrafts", true);
|
||||||
}
|
}
|
||||||
@@ -98,7 +102,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
|||||||
@Override
|
@Override
|
||||||
public void updateChange(ChangeContext ctx)
|
public void updateChange(ChangeContext ctx)
|
||||||
throws RestApiException, OrmException, IOException {
|
throws RestApiException, OrmException, IOException {
|
||||||
patchSet = ctx.getDb().patchSets().get(psId);
|
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
return; // Nothing to do.
|
return; // Nothing to do.
|
||||||
}
|
}
|
||||||
@@ -143,7 +147,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
|||||||
private void deleteOrUpdateDraftChange(ChangeContext ctx)
|
private void deleteOrUpdateDraftChange(ChangeContext ctx)
|
||||||
throws OrmException, RestApiException {
|
throws OrmException, RestApiException {
|
||||||
Change c = ctx.getChange();
|
Change c = ctx.getChange();
|
||||||
if (Iterables.isEmpty(ctx.getDb().patchSets().byChange(c.getId()))) {
|
if (Iterables.isEmpty(psUtil.byChange(ctx.getDb(), ctx.getNotes()))) {
|
||||||
deleteChangeOp = deleteChangeOpProvider.get();
|
deleteChangeOp = deleteChangeOpProvider.get();
|
||||||
deleteChangeOp.updateChange(ctx);
|
deleteChangeOp.updateChange(ctx);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.patch.PatchList;
|
import com.google.gerrit.server.patch.PatchList;
|
||||||
import com.google.gerrit.server.patch.PatchListCache;
|
import com.google.gerrit.server.patch.PatchListCache;
|
||||||
@@ -108,6 +109,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
|||||||
private final Revisions revisions;
|
private final Revisions revisions;
|
||||||
private final GitRepositoryManager gitManager;
|
private final GitRepositoryManager gitManager;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ListFiles(Provider<ReviewDb> db,
|
ListFiles(Provider<ReviewDb> db,
|
||||||
@@ -115,13 +117,15 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
|||||||
FileInfoJson fileInfoJson,
|
FileInfoJson fileInfoJson,
|
||||||
Revisions revisions,
|
Revisions revisions,
|
||||||
GitRepositoryManager gitManager,
|
GitRepositoryManager gitManager,
|
||||||
PatchListCache patchListCache) {
|
PatchListCache patchListCache,
|
||||||
|
PatchSetUtil psUtil) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.fileInfoJson = fileInfoJson;
|
this.fileInfoJson = fileInfoJson;
|
||||||
this.revisions = revisions;
|
this.revisions = revisions;
|
||||||
this.gitManager = gitManager;
|
this.gitManager = gitManager;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
|
this.psUtil = psUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListFiles setReviewed(boolean r) {
|
public ListFiles setReviewed(boolean r) {
|
||||||
@@ -262,7 +266,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
|||||||
TreeWalk tw = new TreeWalk(reader)) {
|
TreeWalk tw = new TreeWalk(reader)) {
|
||||||
PatchList oldList = patchListCache.get(
|
PatchList oldList = patchListCache.get(
|
||||||
resource.getChange(),
|
resource.getChange(),
|
||||||
db.get().patchSets().get(old));
|
psUtil.get(db.get(), resource.getNotes(), old));
|
||||||
|
|
||||||
PatchList curList = patchListCache.get(
|
PatchList curList = patchListCache.get(
|
||||||
resource.getChange(),
|
resource.getChange(),
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ public class GetContent implements RestReadView<FileResource> {
|
|||||||
OrmException {
|
OrmException {
|
||||||
String path = rsrc.getPatchKey().get();
|
String path = rsrc.getPatchKey().get();
|
||||||
if (Patch.COMMIT_MSG.equals(path)) {
|
if (Patch.COMMIT_MSG.equals(path)) {
|
||||||
String msg = changeUtil.getMessage(rsrc.getRevision().getChange());
|
String msg = changeUtil.getMessage(
|
||||||
|
rsrc.getRevision().getChangeResource().getNotes());
|
||||||
return BinaryResult.create(msg)
|
return BinaryResult.create(msg)
|
||||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||||
.base64();
|
.base64();
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CommonConverters;
|
import com.google.gerrit.server.CommonConverters;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.change.RelatedChangesSorter.PatchSetData;
|
import com.google.gerrit.server.change.RelatedChangesSorter.PatchSetData;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -45,14 +47,17 @@ import java.util.Set;
|
|||||||
public class GetRelated implements RestReadView<RevisionResource> {
|
public class GetRelated implements RestReadView<RevisionResource> {
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final RelatedChangesSorter sorter;
|
private final RelatedChangesSorter sorter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GetRelated(Provider<ReviewDb> db,
|
GetRelated(Provider<ReviewDb> db,
|
||||||
Provider<InternalChangeQuery> queryProvider,
|
Provider<InternalChangeQuery> queryProvider,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
RelatedChangesSorter sorter) {
|
RelatedChangesSorter sorter) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.queryProvider = queryProvider;
|
this.queryProvider = queryProvider;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.sorter = sorter;
|
this.sorter = sorter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
|||||||
|
|
||||||
private List<ChangeAndCommit> getRelated(RevisionResource rsrc)
|
private List<ChangeAndCommit> getRelated(RevisionResource rsrc)
|
||||||
throws OrmException, IOException {
|
throws OrmException, IOException {
|
||||||
Set<String> groups = getAllGroups(rsrc.getChange().getId());
|
Set<String> groups = getAllGroups(rsrc.getNotes());
|
||||||
if (groups.isEmpty()) {
|
if (groups.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@@ -109,9 +114,9 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getAllGroups(Change.Id changeId) throws OrmException {
|
private Set<String> getAllGroups(ChangeNotes notes) throws OrmException {
|
||||||
Set<String> result = new HashSet<>();
|
Set<String> result = new HashSet<>();
|
||||||
for (PatchSet ps : db.get().patchSets().byChange(changeId)) {
|
for (PatchSet ps : psUtil.byChange(db.get(), notes)) {
|
||||||
List<String> groups = ps.getGroups();
|
List<String> groups = ps.getGroups();
|
||||||
if (groups != null) {
|
if (groups != null) {
|
||||||
result.addAll(groups);
|
result.addAll(groups);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.restapi.RestReadView;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -47,14 +48,17 @@ class IncludedIn implements RestReadView<ChangeResource> {
|
|||||||
|
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final DynamicMap<ExternalIncludedIn> includedIn;
|
private final DynamicMap<ExternalIncludedIn> includedIn;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
IncludedIn(Provider<ReviewDb> db,
|
IncludedIn(Provider<ReviewDb> db,
|
||||||
GitRepositoryManager repoManager,
|
GitRepositoryManager repoManager,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
DynamicMap<ExternalIncludedIn> includedIn) {
|
DynamicMap<ExternalIncludedIn> includedIn) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.includedIn = includedIn;
|
this.includedIn = includedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +66,7 @@ class IncludedIn implements RestReadView<ChangeResource> {
|
|||||||
public IncludedInInfo apply(ChangeResource rsrc) throws BadRequestException,
|
public IncludedInInfo apply(ChangeResource rsrc) throws BadRequestException,
|
||||||
ResourceConflictException, OrmException, IOException {
|
ResourceConflictException, OrmException, IOException {
|
||||||
ChangeControl ctl = rsrc.getControl();
|
ChangeControl ctl = rsrc.getControl();
|
||||||
PatchSet ps =
|
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes());
|
||||||
db.get().patchSets().get(ctl.getChange().currentPatchSetId());
|
|
||||||
Project.NameKey project = ctl.getProject().getNameKey();
|
Project.NameKey project = ctl.getProject().getNameKey();
|
||||||
try (Repository r = repoManager.openRepository(project);
|
try (Repository r = repoManager.openRepository(project);
|
||||||
RevWalk rw = new RevWalk(r)) {
|
RevWalk rw = new RevWalk(r)) {
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ import com.google.gerrit.server.ApprovalCopier;
|
|||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.events.CommitReceivedEvent;
|
import com.google.gerrit.server.events.CommitReceivedEvent;
|
||||||
import com.google.gerrit.server.git.BanCommit;
|
import com.google.gerrit.server.git.BanCommit;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.Context;
|
import com.google.gerrit.server.git.BatchUpdate.Context;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
|
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
|
||||||
import com.google.gerrit.server.git.GroupCollector;
|
|
||||||
import com.google.gerrit.server.git.validators.CommitValidationException;
|
import com.google.gerrit.server.git.validators.CommitValidationException;
|
||||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||||
import com.google.gerrit.server.mail.ReplacePatchSetSender;
|
import com.google.gerrit.server.mail.ReplacePatchSetSender;
|
||||||
@@ -84,6 +84,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
|||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
private final ApprovalCopier approvalCopier;
|
private final ApprovalCopier approvalCopier;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
// Assisted-injected fields.
|
// Assisted-injected fields.
|
||||||
private final PatchSet.Id psId;
|
private final PatchSet.Id psId;
|
||||||
@@ -119,6 +120,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
|||||||
PatchSetInfoFactory patchSetInfoFactory,
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
CommitValidators.Factory commitValidatorsFactory,
|
CommitValidators.Factory commitValidatorsFactory,
|
||||||
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
@Assisted RefControl refControl,
|
@Assisted RefControl refControl,
|
||||||
@Assisted PatchSet.Id psId,
|
@Assisted PatchSet.Id psId,
|
||||||
@Assisted RevCommit commit) {
|
@Assisted RevCommit commit) {
|
||||||
@@ -130,6 +132,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
|||||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||||
this.commitValidatorsFactory = commitValidatorsFactory;
|
this.commitValidatorsFactory = commitValidatorsFactory;
|
||||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
|
|
||||||
this.refControl = refControl;
|
this.refControl = refControl;
|
||||||
this.psId = psId;
|
this.psId = psId;
|
||||||
@@ -232,7 +235,8 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
|||||||
if (groups != null) {
|
if (groups != null) {
|
||||||
patchSet.setGroups(groups);
|
patchSet.setGroups(groups);
|
||||||
} else {
|
} else {
|
||||||
patchSet.setGroups(GroupCollector.getCurrentGroups(db, change));
|
PatchSet prevPs = psUtil.current(ctx.getDb(), ctx.getNotes());
|
||||||
|
patchSet.setGroups(prevPs != null ? prevPs.getGroups() : null);
|
||||||
}
|
}
|
||||||
db.patchSets().insert(Collections.singleton(patchSet));
|
db.patchSets().insert(Collections.singleton(patchSet));
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import com.google.gerrit.server.ChangeMessagesUtil;
|
|||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountsCollection;
|
import com.google.gerrit.server.account.AccountsCollection;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
@@ -102,6 +103,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
private final AccountsCollection accounts;
|
private final AccountsCollection accounts;
|
||||||
private final EmailReviewComments.Factory email;
|
private final EmailReviewComments.Factory email;
|
||||||
@@ -115,6 +117,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
AccountsCollection accounts,
|
AccountsCollection accounts,
|
||||||
EmailReviewComments.Factory email,
|
EmailReviewComments.Factory email,
|
||||||
@@ -124,6 +127,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
this.changes = changes;
|
this.changes = changes;
|
||||||
this.changeDataFactory = changeDataFactory;
|
this.changeDataFactory = changeDataFactory;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
@@ -354,7 +358,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
throws OrmException, ResourceConflictException {
|
throws OrmException, ResourceConflictException {
|
||||||
user = ctx.getUser().asIdentifiedUser();
|
user = ctx.getUser().asIdentifiedUser();
|
||||||
change = ctx.getChange();
|
change = ctx.getChange();
|
||||||
ps = ctx.getDb().patchSets().get(psId);
|
ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
boolean dirty = false;
|
boolean dirty = false;
|
||||||
dirty |= insertComments(ctx);
|
dirty |= insertComments(ctx);
|
||||||
dirty |= updateLabels(ctx);
|
dirty |= updateLabels(ctx);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountCache;
|
import com.google.gerrit.server.account.AccountCache;
|
||||||
import com.google.gerrit.server.account.AccountLoader;
|
import com.google.gerrit.server.account.AccountLoader;
|
||||||
import com.google.gerrit.server.account.AccountsCollection;
|
import com.google.gerrit.server.account.AccountsCollection;
|
||||||
@@ -76,6 +77,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
private final AccountsCollection accounts;
|
private final AccountsCollection accounts;
|
||||||
private final ReviewerResource.Factory reviewerFactory;
|
private final ReviewerResource.Factory reviewerFactory;
|
||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final AddReviewerSender.Factory addReviewerSenderFactory;
|
private final AddReviewerSender.Factory addReviewerSenderFactory;
|
||||||
private final GroupsCollection groupsCollection;
|
private final GroupsCollection groupsCollection;
|
||||||
private final GroupMembers.Factory groupMembersFactory;
|
private final GroupMembers.Factory groupMembersFactory;
|
||||||
@@ -94,6 +96,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
PostReviewers(AccountsCollection accounts,
|
PostReviewers(AccountsCollection accounts,
|
||||||
ReviewerResource.Factory reviewerFactory,
|
ReviewerResource.Factory reviewerFactory,
|
||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
AddReviewerSender.Factory addReviewerSenderFactory,
|
AddReviewerSender.Factory addReviewerSenderFactory,
|
||||||
GroupsCollection groupsCollection,
|
GroupsCollection groupsCollection,
|
||||||
GroupMembers.Factory groupMembersFactory,
|
GroupMembers.Factory groupMembersFactory,
|
||||||
@@ -110,6 +113,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
this.accounts = accounts;
|
this.accounts = accounts;
|
||||||
this.reviewerFactory = reviewerFactory;
|
this.reviewerFactory = reviewerFactory;
|
||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.addReviewerSenderFactory = addReviewerSenderFactory;
|
this.addReviewerSenderFactory = addReviewerSenderFactory;
|
||||||
this.groupsCollection = groupsCollection;
|
this.groupsCollection = groupsCollection;
|
||||||
this.groupMembersFactory = groupMembersFactory;
|
this.groupMembersFactory = groupMembersFactory;
|
||||||
@@ -257,7 +261,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
indexFuture.checkedGet();
|
indexFuture.checkedGet();
|
||||||
emailReviewers(rsrc.getChange(), added);
|
emailReviewers(rsrc.getChange(), added);
|
||||||
if (!added.isEmpty()) {
|
if (!added.isEmpty()) {
|
||||||
PatchSet patchSet = dbProvider.get().patchSets().get(rsrc.getChange().currentPatchSetId());
|
PatchSet patchSet = psUtil.current(dbProvider.get(), rsrc.getNotes());
|
||||||
for (PatchSetApproval psa : added) {
|
for (PatchSetApproval psa : added) {
|
||||||
Account account = accountCache.get(psa.getAccountId()).getAccount();
|
Account account = accountCache.get(psa.getAccountId()).getAccount();
|
||||||
hooks.doReviewerAddedHook(rsrc.getChange(), account, patchSet, dbProvider.get());
|
hooks.doReviewerAddedHook(rsrc.getChange(), account, patchSet, dbProvider.get());
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountResolver;
|
import com.google.gerrit.server.account.AccountResolver;
|
||||||
import com.google.gerrit.server.change.PublishDraftPatchSet.Input;
|
import com.google.gerrit.server.change.PublishDraftPatchSet.Input;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
@@ -73,32 +74,35 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
|||||||
public static class Input {
|
public static class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final AccountResolver accountResolver;
|
||||||
|
private final ApprovalsUtil approvalsUtil;
|
||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
private final ApprovalsUtil approvalsUtil;
|
|
||||||
private final AccountResolver accountResolver;
|
|
||||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
|
||||||
private final CreateChangeSender.Factory createChangeSenderFactory;
|
private final CreateChangeSender.Factory createChangeSenderFactory;
|
||||||
|
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PublishDraftPatchSet(
|
public PublishDraftPatchSet(
|
||||||
Provider<ReviewDb> dbProvider,
|
AccountResolver accountResolver,
|
||||||
|
ApprovalsUtil approvalsUtil,
|
||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
ChangeHooks hooks,
|
ChangeHooks hooks,
|
||||||
ApprovalsUtil approvalsUtil,
|
|
||||||
AccountResolver accountResolver,
|
|
||||||
PatchSetInfoFactory patchSetInfoFactory,
|
|
||||||
CreateChangeSender.Factory createChangeSenderFactory,
|
CreateChangeSender.Factory createChangeSenderFactory,
|
||||||
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
|
Provider<ReviewDb> dbProvider,
|
||||||
ReplacePatchSetSender.Factory replacePatchSetFactory) {
|
ReplacePatchSetSender.Factory replacePatchSetFactory) {
|
||||||
this.dbProvider = dbProvider;
|
this.accountResolver = accountResolver;
|
||||||
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
this.approvalsUtil = approvalsUtil;
|
|
||||||
this.accountResolver = accountResolver;
|
|
||||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
|
||||||
this.createChangeSenderFactory = createChangeSenderFactory;
|
this.createChangeSenderFactory = createChangeSenderFactory;
|
||||||
|
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
|
this.dbProvider = dbProvider;
|
||||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +174,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
|||||||
throw new AuthException("Cannot publish this draft patch set");
|
throw new AuthException("Cannot publish this draft patch set");
|
||||||
}
|
}
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
patchSet = ctx.getDb().patchSets().get(psId);
|
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
throw new ResourceNotFoundException(psId.toString());
|
throw new ResourceNotFoundException(psId.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.UpdateException;
|
import com.google.gerrit.server.git.UpdateException;
|
||||||
@@ -50,6 +51,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
|||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
private final DeleteDraftComment delete;
|
private final DeleteDraftComment delete;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final BatchUpdate.Factory updateFactory;
|
private final BatchUpdate.Factory updateFactory;
|
||||||
private final Provider<CommentJson> commentJson;
|
private final Provider<CommentJson> commentJson;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
@@ -58,12 +60,14 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
|||||||
PutDraftComment(Provider<ReviewDb> db,
|
PutDraftComment(Provider<ReviewDb> db,
|
||||||
DeleteDraftComment delete,
|
DeleteDraftComment delete,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
BatchUpdate.Factory updateFactory,
|
BatchUpdate.Factory updateFactory,
|
||||||
Provider<CommentJson> commentJson,
|
Provider<CommentJson> commentJson,
|
||||||
PatchListCache patchListCache) {
|
PatchListCache patchListCache) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.delete = delete;
|
this.delete = delete;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
this.commentJson = commentJson;
|
this.commentJson = commentJson;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
@@ -118,7 +122,8 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
|||||||
|
|
||||||
PatchSet.Id psId = comment.getKey().getParentKey().getParentKey();
|
PatchSet.Id psId = comment.getKey().getParentKey().getParentKey();
|
||||||
ChangeUpdate update = ctx.getUpdate(psId);
|
ChangeUpdate update = ctx.getUpdate(psId);
|
||||||
PatchSet ps = ctx.getDb().patchSets().get(psId);
|
|
||||||
|
PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
throw new ResourceNotFoundException("patch set not found: " + psId);
|
throw new ResourceNotFoundException("patch set not found: " + psId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,8 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
|||||||
return db.patchSets().get(basePatchSetId);
|
return db.patchSets().get(basePatchSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(dborowitz): Use PatchSetUtil; requires additional refactoring as we
|
||||||
|
// just turn around and get the change at the caller.
|
||||||
// Try parsing base as a change number (assume current patch set).
|
// Try parsing base as a change number (assume current patch set).
|
||||||
PatchSet basePatchSet = null;
|
PatchSet basePatchSet = null;
|
||||||
Integer baseChangeId = Ints.tryParse(base);
|
Integer baseChangeId = Ints.tryParse(base);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
|||||||
import com.google.gerrit.extensions.restapi.RestView;
|
import com.google.gerrit.extensions.restapi.RestView;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditModifier;
|
import com.google.gerrit.server.edit.ChangeEditModifier;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
@@ -79,14 +80,17 @@ public class RebaseChangeEdit implements
|
|||||||
|
|
||||||
private final ChangeEditModifier editModifier;
|
private final ChangeEditModifier editModifier;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Rebase(ChangeEditModifier editModifier,
|
Rebase(ChangeEditModifier editModifier,
|
||||||
ChangeEditUtil editUtil,
|
ChangeEditUtil editUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
Provider<ReviewDb> db) {
|
Provider<ReviewDb> db) {
|
||||||
this.editModifier = editModifier;
|
this.editModifier = editModifier;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +105,7 @@ public class RebaseChangeEdit implements
|
|||||||
rsrc.getChange().getChangeId()));
|
rsrc.getChange().getChangeId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
PatchSet current = db.get().patchSets().get(
|
PatchSet current = psUtil.current(db.get(), rsrc.getNotes());
|
||||||
rsrc.getChange().currentPatchSetId());
|
|
||||||
if (current.getId().equals(edit.get().getBasePatchSet().getId())) {
|
if (current.getId().equals(edit.get().getBasePatchSet().getId())) {
|
||||||
throw new ResourceConflictException(String.format(
|
throw new ResourceConflictException(String.format(
|
||||||
"edit for change %s is already on latest patch set: %s",
|
"edit for change %s is already on latest patch set: %s",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.Context;
|
import com.google.gerrit.server.git.BatchUpdate.Context;
|
||||||
@@ -58,6 +59,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
|||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ChangeJson.Factory json;
|
private final ChangeJson.Factory json;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final BatchUpdate.Factory batchUpdateFactory;
|
private final BatchUpdate.Factory batchUpdateFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -66,12 +68,14 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
|||||||
Provider<ReviewDb> dbProvider,
|
Provider<ReviewDb> dbProvider,
|
||||||
ChangeJson.Factory json,
|
ChangeJson.Factory json,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
BatchUpdate.Factory batchUpdateFactory) {
|
BatchUpdate.Factory batchUpdateFactory) {
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
this.restoredSenderFactory = restoredSenderFactory;
|
this.restoredSenderFactory = restoredSenderFactory;
|
||||||
this.dbProvider = dbProvider;
|
this.dbProvider = dbProvider;
|
||||||
this.json = json;
|
this.json = json;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.batchUpdateFactory = batchUpdateFactory;
|
this.batchUpdateFactory = batchUpdateFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +117,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
|||||||
if (change == null || change.getStatus() != Status.ABANDONED) {
|
if (change == null || change.getStatus() != Status.ABANDONED) {
|
||||||
throw new ResourceConflictException("change is " + status(change));
|
throw new ResourceConflictException("change is " + status(change));
|
||||||
}
|
}
|
||||||
patchSet = ctx.getDb().patchSets().get(psId);
|
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
change.setStatus(Status.NEW);
|
change.setStatus(Status.NEW);
|
||||||
change.setLastUpdatedOn(ctx.getWhen());
|
change.setLastUpdatedOn(ctx.getWhen());
|
||||||
ctx.saveChange();
|
ctx.saveChange();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.google.gerrit.extensions.restapi.RestView;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.RevId;
|
import com.google.gerrit.reviewdb.client.RevId;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -42,14 +43,17 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
|||||||
private final DynamicMap<RestView<RevisionResource>> views;
|
private final DynamicMap<RestView<RevisionResource>> views;
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ChangeEditUtil editUtil;
|
private final ChangeEditUtil editUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Revisions(DynamicMap<RestView<RevisionResource>> views,
|
Revisions(DynamicMap<RestView<RevisionResource>> views,
|
||||||
Provider<ReviewDb> dbProvider,
|
Provider<ReviewDb> dbProvider,
|
||||||
ChangeEditUtil editUtil) {
|
ChangeEditUtil editUtil,
|
||||||
|
PatchSetUtil psUtil) {
|
||||||
this.views = views;
|
this.views = views;
|
||||||
this.dbProvider = dbProvider;
|
this.dbProvider = dbProvider;
|
||||||
this.editUtil = editUtil;
|
this.editUtil = editUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,8 +71,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
|||||||
throws ResourceNotFoundException, AuthException, OrmException,
|
throws ResourceNotFoundException, AuthException, OrmException,
|
||||||
IOException {
|
IOException {
|
||||||
if (id.equals("current")) {
|
if (id.equals("current")) {
|
||||||
PatchSet.Id p = change.getChange().currentPatchSetId();
|
PatchSet ps = psUtil.current(dbProvider.get(), change.getNotes());
|
||||||
PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
|
|
||||||
if (ps != null && visible(change, ps)) {
|
if (ps != null && visible(change, ps)) {
|
||||||
return new RevisionResource(change, ps).doNotCache();
|
return new RevisionResource(change, ps).doNotCache();
|
||||||
}
|
}
|
||||||
@@ -123,9 +126,8 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
|||||||
|
|
||||||
private List<RevisionResource> byLegacyPatchSetId(ChangeResource change,
|
private List<RevisionResource> byLegacyPatchSetId(ChangeResource change,
|
||||||
String id) throws OrmException {
|
String id) throws OrmException {
|
||||||
PatchSet ps = dbProvider.get().patchSets().get(new PatchSet.Id(
|
PatchSet ps = psUtil.get(dbProvider.get(), change.getNotes(),
|
||||||
change.getId(),
|
new PatchSet.Id(change.getId(), Integer.parseInt(id)));
|
||||||
Integer.parseInt(id)));
|
|
||||||
if (ps != null) {
|
if (ps != null) {
|
||||||
return Collections.singletonList(new RevisionResource(change, ps));
|
return Collections.singletonList(new RevisionResource(change, ps));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ public class ChangeEditUtil {
|
|||||||
int pos = ref.getName().lastIndexOf("/");
|
int pos = ref.getName().lastIndexOf("/");
|
||||||
checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
|
checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
|
||||||
String psId = ref.getName().substring(pos + 1);
|
String psId = ref.getName().substring(pos + 1);
|
||||||
|
// TODO(dborowitz): Use PatchSetUtil. Requires signature changes to pass
|
||||||
|
// in ChangeNotes.
|
||||||
return db.get().patchSets().get(new PatchSet.Id(
|
return db.get().patchSets().get(new PatchSet.Id(
|
||||||
change.getId(), Integer.parseInt(psId)));
|
change.getId(), Integer.parseInt(psId)));
|
||||||
} catch (OrmException | NumberFormatException e) {
|
} catch (OrmException | NumberFormatException e) {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import com.google.common.collect.MultimapBuilder;
|
|||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
import com.google.common.collect.SetMultimap;
|
import com.google.common.collect.SetMultimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.change.RevisionResource;
|
import com.google.gerrit.server.change.RevisionResource;
|
||||||
@@ -82,12 +81,6 @@ public class GroupCollector {
|
|||||||
private static final Logger log =
|
private static final Logger log =
|
||||||
LoggerFactory.getLogger(GroupCollector.class);
|
LoggerFactory.getLogger(GroupCollector.class);
|
||||||
|
|
||||||
public static List<String> getCurrentGroups(ReviewDb db, Change c)
|
|
||||||
throws OrmException {
|
|
||||||
PatchSet ps = db.patchSets().get(c.currentPatchSetId());
|
|
||||||
return ps != null ? ps.getGroups() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getDefaultGroups(PatchSet ps) {
|
public static List<String> getDefaultGroups(PatchSet ps) {
|
||||||
return ImmutableList.of(ps.getRevision().get());
|
return ImmutableList.of(ps.getRevision().get());
|
||||||
}
|
}
|
||||||
@@ -136,6 +129,7 @@ public class GroupCollector {
|
|||||||
new Lookup() {
|
new Lookup() {
|
||||||
@Override
|
@Override
|
||||||
public List<String> lookup(PatchSet.Id psId) throws OrmException {
|
public List<String> lookup(PatchSet.Id psId) throws OrmException {
|
||||||
|
// TODO(dborowitz): PatchSetUtil.
|
||||||
PatchSet ps = db.patchSets().get(psId);
|
PatchSet ps = db.patchSets().get(psId);
|
||||||
return ps != null ? ps.getGroups() : null;
|
return ps != null ? ps.getGroups() : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1032,6 +1032,7 @@ public class MergeOp implements AutoCloseable {
|
|||||||
// modified when using the cherry-pick merge strategy.
|
// modified when using the cherry-pick merge strategy.
|
||||||
CodeReviewCommit commit = commits.get(c.getId());
|
CodeReviewCommit commit = commits.get(c.getId());
|
||||||
PatchSet.Id mergedId = commit.change().currentPatchSetId();
|
PatchSet.Id mergedId = commit.change().currentPatchSetId();
|
||||||
|
// TODO(dborowitz): Use PatchSetUtil after BatchUpdate migration.
|
||||||
merged = db.patchSets().get(mergedId);
|
merged = db.patchSets().get(mergedId);
|
||||||
c = setMergedPatchSet(c.getId(), mergedId);
|
c = setMergedPatchSet(c.getId(), mergedId);
|
||||||
submitter = approvalsUtil.getSubmitter(db, commit.notes(), mergedId);
|
submitter = approvalsUtil.getSubmitter(db, commit.notes(), mergedId);
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import com.google.gerrit.server.ApprovalsUtil;
|
|||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.Sequences;
|
import com.google.gerrit.server.Sequences;
|
||||||
import com.google.gerrit.server.account.AccountCache;
|
import com.google.gerrit.server.account.AccountCache;
|
||||||
import com.google.gerrit.server.account.AccountResolver;
|
import com.google.gerrit.server.account.AccountResolver;
|
||||||
@@ -300,6 +301,7 @@ public class ReceiveCommits {
|
|||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
private final ApprovalCopier approvalCopier;
|
private final ApprovalCopier approvalCopier;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final ProjectCache projectCache;
|
private final ProjectCache projectCache;
|
||||||
private final String canonicalWebUrl;
|
private final String canonicalWebUrl;
|
||||||
@@ -372,6 +374,7 @@ public class ReceiveCommits {
|
|||||||
final ApprovalsUtil approvalsUtil,
|
final ApprovalsUtil approvalsUtil,
|
||||||
final ApprovalCopier approvalCopier,
|
final ApprovalCopier approvalCopier,
|
||||||
final ChangeMessagesUtil cmUtil,
|
final ChangeMessagesUtil cmUtil,
|
||||||
|
final PatchSetUtil psUtil,
|
||||||
final ProjectCache projectCache,
|
final ProjectCache projectCache,
|
||||||
final GitRepositoryManager repoManager,
|
final GitRepositoryManager repoManager,
|
||||||
final TagCache tagCache,
|
final TagCache tagCache,
|
||||||
@@ -419,6 +422,7 @@ public class ReceiveCommits {
|
|||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.approvalCopier = approvalCopier;
|
this.approvalCopier = approvalCopier;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.canonicalWebUrl = canonicalWebUrl;
|
this.canonicalWebUrl = canonicalWebUrl;
|
||||||
@@ -512,7 +516,7 @@ public class ReceiveCommits {
|
|||||||
});
|
});
|
||||||
advHooks.add(rp.getAdvertiseRefsHook());
|
advHooks.add(rp.getAdvertiseRefsHook());
|
||||||
advHooks.add(new ReceiveCommitsAdvertiseRefsHook(
|
advHooks.add(new ReceiveCommitsAdvertiseRefsHook(
|
||||||
db, queryProvider, projectControl.getProject().getNameKey()));
|
queryProvider, projectControl.getProject().getNameKey()));
|
||||||
advHooks.add(new HackPushNegotiateHook());
|
advHooks.add(new HackPushNegotiateHook());
|
||||||
rp.setAdvertiseRefsHook(AdvertiseRefsHookChain.newChain(advHooks));
|
rp.setAdvertiseRefsHook(AdvertiseRefsHookChain.newChain(advHooks));
|
||||||
rp.setPostReceiveHook(lazyPostReceive.get());
|
rp.setPostReceiveHook(lazyPostReceive.get());
|
||||||
@@ -2275,7 +2279,8 @@ public class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newPatchSet.getGroups() == null) {
|
if (newPatchSet.getGroups() == null) {
|
||||||
newPatchSet.setGroups(GroupCollector.getCurrentGroups(db, change));
|
PatchSet prevPs = psUtil.current(db, update.getChangeNotes());
|
||||||
|
newPatchSet.setGroups(prevPs != null ? prevPs.getGroups() : null);
|
||||||
}
|
}
|
||||||
db.patchSets().insert(Collections.singleton(newPatchSet));
|
db.patchSets().insert(Collections.singleton(newPatchSet));
|
||||||
|
|
||||||
@@ -2705,13 +2710,14 @@ public class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Change.Key closeChange(final ReceiveCommand cmd, final PatchSet.Id psi,
|
private Change.Key closeChange(ReceiveCommand cmd, PatchSet.Id psi,
|
||||||
final RevCommit commit) throws OrmException, IOException {
|
RevCommit commit) throws OrmException, IOException {
|
||||||
final String refName = cmd.getRefName();
|
String refName = cmd.getRefName();
|
||||||
final Change.Id cid = psi.getParentKey();
|
Change.Id cid = psi.getParentKey();
|
||||||
|
|
||||||
final Change change = db.changes().get(cid);
|
Change change = db.changes().get(cid);
|
||||||
final PatchSet ps = db.patchSets().get(psi);
|
ChangeControl ctl = projectControl.controlFor(change);
|
||||||
|
PatchSet ps = psUtil.get(db, ctl.getNotes(), psi);
|
||||||
if (change == null || ps == null) {
|
if (change == null || ps == null) {
|
||||||
log.warn(project.getName() + " " + psi + " is missing");
|
log.warn(project.getName() + " " + psi + " is missing");
|
||||||
return null;
|
return null;
|
||||||
@@ -2728,7 +2734,7 @@ public class ReceiveCommits {
|
|||||||
|
|
||||||
ReplaceRequest result = new ReplaceRequest(cid, commit, cmd, false);
|
ReplaceRequest result = new ReplaceRequest(cid, commit, cmd, false);
|
||||||
result.change = change;
|
result.change = change;
|
||||||
result.changeCtl = projectControl.controlFor(change);
|
result.changeCtl = ctl;
|
||||||
result.newPatchSet = ps;
|
result.newPatchSet = ps;
|
||||||
result.info = patchSetInfoFactory.get(rp.getRevWalk(), commit, psi);
|
result.info = patchSetInfoFactory.get(rp.getRevWalk(), commit, psi);
|
||||||
result.mergedIntoRef = refName;
|
result.mergedIntoRef = refName;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import com.google.common.collect.Sets;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gerrit.server.util.MagicBranch;
|
import com.google.gerrit.server.util.MagicBranch;
|
||||||
@@ -47,14 +46,12 @@ public class ReceiveCommitsAdvertiseRefsHook implements AdvertiseRefsHook {
|
|||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(ReceiveCommitsAdvertiseRefsHook.class);
|
.getLogger(ReceiveCommitsAdvertiseRefsHook.class);
|
||||||
|
|
||||||
private final ReviewDb db;
|
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
private final Project.NameKey projectName;
|
private final Project.NameKey projectName;
|
||||||
|
|
||||||
public ReceiveCommitsAdvertiseRefsHook(ReviewDb db,
|
public ReceiveCommitsAdvertiseRefsHook(
|
||||||
Provider<InternalChangeQuery> queryProvider,
|
Provider<InternalChangeQuery> queryProvider,
|
||||||
Project.NameKey projectName) {
|
Project.NameKey projectName) {
|
||||||
this.db = db;
|
|
||||||
this.queryProvider = queryProvider;
|
this.queryProvider = queryProvider;
|
||||||
this.projectName = projectName;
|
this.projectName = projectName;
|
||||||
}
|
}
|
||||||
@@ -92,22 +89,15 @@ public class ReceiveCommitsAdvertiseRefsHook implements AdvertiseRefsHook {
|
|||||||
|
|
||||||
private Set<ObjectId> advertiseOpenChanges() {
|
private Set<ObjectId> advertiseOpenChanges() {
|
||||||
// Advertise some recent open changes, in case a commit is based on one.
|
// Advertise some recent open changes, in case a commit is based on one.
|
||||||
final int limit = 32;
|
int limit = 32;
|
||||||
try {
|
try {
|
||||||
Set<PatchSet.Id> toGet = Sets.newHashSetWithExpectedSize(limit);
|
Set<ObjectId> r = Sets.newHashSetWithExpectedSize(limit);
|
||||||
for (ChangeData cd : queryProvider.get()
|
for (ChangeData cd : queryProvider.get()
|
||||||
.enforceVisibility(true)
|
.enforceVisibility(true)
|
||||||
.setLimit(limit)
|
.setLimit(limit)
|
||||||
.byProjectOpen(projectName)) {
|
.byProjectOpen(projectName)) {
|
||||||
PatchSet.Id id = cd.change().currentPatchSetId();
|
PatchSet ps = cd.currentPatchSet();
|
||||||
if (id != null) {
|
if (ps != null) {
|
||||||
toGet.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<ObjectId> r = Sets.newHashSetWithExpectedSize(toGet.size());
|
|
||||||
for (PatchSet ps : db.patchSets().get(toGet)) {
|
|
||||||
if (ps.getRevision() != null && ps.getRevision().get() != null) {
|
|
||||||
r.add(ObjectId.fromString(ps.getRevision().get()));
|
r.add(ObjectId.fromString(ps.getRevision().get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.google.gerrit.server.git.BatchUpdate;
|
|||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
|
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
|
||||||
import com.google.gerrit.server.git.CodeReviewCommit;
|
import com.google.gerrit.server.git.CodeReviewCommit;
|
||||||
import com.google.gerrit.server.git.GroupCollector;
|
|
||||||
import com.google.gerrit.server.git.IntegrationException;
|
import com.google.gerrit.server.git.IntegrationException;
|
||||||
import com.google.gerrit.server.git.MergeIdenticalTreeException;
|
import com.google.gerrit.server.git.MergeIdenticalTreeException;
|
||||||
import com.google.gerrit.server.git.MergeTip;
|
import com.google.gerrit.server.git.MergeTip;
|
||||||
@@ -167,13 +166,14 @@ public class CherryPick extends SubmitStrategy {
|
|||||||
// Merge conflict; don't update change.
|
// Merge conflict; don't update change.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
PatchSet prevPs = args.psUtil.current(ctx.getDb(), ctx.getNotes());
|
||||||
PatchSet ps = new PatchSet(psId);
|
PatchSet ps = new PatchSet(psId);
|
||||||
ps.setCreatedOn(ctx.getWhen());
|
ps.setCreatedOn(ctx.getWhen());
|
||||||
ps.setUploader(args.caller.getAccountId());
|
ps.setUploader(args.caller.getAccountId());
|
||||||
ps.setRevision(new RevId(newCommit.getId().getName()));
|
ps.setRevision(new RevId(newCommit.getId().getName()));
|
||||||
|
|
||||||
Change c = toMerge.change();
|
Change c = toMerge.change();
|
||||||
ps.setGroups(GroupCollector.getCurrentGroups(args.db, c));
|
ps.setGroups(prevPs != null ? prevPs.getGroups() : null);
|
||||||
args.db.patchSets().insert(Collections.singleton(ps));
|
args.db.patchSets().insert(Collections.singleton(ps));
|
||||||
c.setCurrentPatchSet(patchSetInfo);
|
c.setCurrentPatchSet(patchSetInfo);
|
||||||
ctx.saveChange();
|
ctx.saveChange();
|
||||||
|
|||||||
@@ -144,11 +144,11 @@ public class RebaseIfNecessary extends SubmitStrategy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stale read of patch set is ok; see comments in RebaseChangeOp.
|
||||||
|
PatchSet origPs = args.psUtil.get(
|
||||||
|
ctx.getDb(), toMerge.getControl().getNotes(), toMerge.getPatchsetId());
|
||||||
rebaseOp = args.rebaseFactory.create(
|
rebaseOp = args.rebaseFactory.create(
|
||||||
toMerge.getControl(),
|
toMerge.getControl(), origPs, mergeTip.getCurrentTip().name())
|
||||||
// Racy read of patch set is ok; see comments in RebaseChangeOp.
|
|
||||||
args.db.patchSets().get(toMerge.getPatchsetId()),
|
|
||||||
mergeTip.getCurrentTip().name())
|
|
||||||
.setRunHooks(false)
|
.setRunHooks(false)
|
||||||
// Bypass approval copier since we're going to copy all approvals
|
// Bypass approval copier since we're going to copy all approvals
|
||||||
// later anyway.
|
// later anyway.
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.change.RebaseChangeOp;
|
import com.google.gerrit.server.change.RebaseChangeOp;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.CodeReviewCommit;
|
import com.google.gerrit.server.git.CodeReviewCommit;
|
||||||
@@ -84,6 +85,7 @@ public abstract class SubmitStrategy {
|
|||||||
final BatchUpdate.Factory batchUpdateFactory;
|
final BatchUpdate.Factory batchUpdateFactory;
|
||||||
final ChangeControl.GenericFactory changeControlFactory;
|
final ChangeControl.GenericFactory changeControlFactory;
|
||||||
final PatchSetInfoFactory patchSetInfoFactory;
|
final PatchSetInfoFactory patchSetInfoFactory;
|
||||||
|
final PatchSetUtil psUtil;
|
||||||
final ProjectCache projectCache;
|
final ProjectCache projectCache;
|
||||||
final PersonIdent serverIdent;
|
final PersonIdent serverIdent;
|
||||||
final RebaseChangeOp.Factory rebaseFactory;
|
final RebaseChangeOp.Factory rebaseFactory;
|
||||||
@@ -109,6 +111,7 @@ public abstract class SubmitStrategy {
|
|||||||
ChangeControl.GenericFactory changeControlFactory,
|
ChangeControl.GenericFactory changeControlFactory,
|
||||||
MergeUtil.Factory mergeUtilFactory,
|
MergeUtil.Factory mergeUtilFactory,
|
||||||
PatchSetInfoFactory patchSetInfoFactory,
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
@GerritPersonIdent PersonIdent serverIdent,
|
@GerritPersonIdent PersonIdent serverIdent,
|
||||||
ProjectCache projectCache,
|
ProjectCache projectCache,
|
||||||
RebaseChangeOp.Factory rebaseFactory,
|
RebaseChangeOp.Factory rebaseFactory,
|
||||||
@@ -125,6 +128,7 @@ public abstract class SubmitStrategy {
|
|||||||
this.batchUpdateFactory = batchUpdateFactory;
|
this.batchUpdateFactory = batchUpdateFactory;
|
||||||
this.changeControlFactory = changeControlFactory;
|
this.changeControlFactory = changeControlFactory;
|
||||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
this.rebaseFactory = rebaseFactory;
|
this.rebaseFactory = rebaseFactory;
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
|
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
try {
|
try {
|
||||||
patchSet = args.db.get().patchSets().get(change.currentPatchSetId());
|
patchSet = changeData.currentPatchSet();
|
||||||
} catch (OrmException err) {
|
} catch (OrmException err) {
|
||||||
patchSet = null;
|
patchSet = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.patch;
|
package com.google.gerrit.server.patch;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.data.CommentDetail;
|
import com.google.gerrit.common.data.CommentDetail;
|
||||||
@@ -31,6 +33,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
@@ -73,6 +76,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
LoggerFactory.getLogger(PatchScriptFactory.class);
|
LoggerFactory.getLogger(PatchScriptFactory.class);
|
||||||
|
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Provider<PatchScriptBuilder> builderFactory;
|
private final Provider<PatchScriptBuilder> builderFactory;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
private final ReviewDb db;
|
private final ReviewDb db;
|
||||||
@@ -100,10 +104,12 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
private CommentDetail comments;
|
private CommentDetail comments;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PatchScriptFactory(final GitRepositoryManager grm,
|
PatchScriptFactory(GitRepositoryManager grm,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
Provider<PatchScriptBuilder> builderFactory,
|
Provider<PatchScriptBuilder> builderFactory,
|
||||||
final PatchListCache patchListCache, final ReviewDb db,
|
PatchListCache patchListCache,
|
||||||
final AccountInfoCacheFactory.Factory aicFactory,
|
ReviewDb db,
|
||||||
|
AccountInfoCacheFactory.Factory aicFactory,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
ChangeEditUtil editReader,
|
ChangeEditUtil editReader,
|
||||||
@Assisted ChangeControl control,
|
@Assisted ChangeControl control,
|
||||||
@@ -112,6 +118,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
@Assisted("patchSetB") final PatchSet.Id patchSetB,
|
@Assisted("patchSetB") final PatchSet.Id patchSetB,
|
||||||
@Assisted DiffPreferencesInfo diffPrefs) {
|
@Assisted DiffPreferencesInfo diffPrefs) {
|
||||||
this.repoManager = grm;
|
this.repoManager = grm;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -126,6 +133,10 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
this.diffPrefs = diffPrefs;
|
this.diffPrefs = diffPrefs;
|
||||||
|
|
||||||
changeId = patchSetB.getParentKey();
|
changeId = patchSetB.getParentKey();
|
||||||
|
checkArgument(
|
||||||
|
patchSetA == null || patchSetA.getParentKey().equals(changeId),
|
||||||
|
"cannot compare PatchSets from different changes: %s and %s",
|
||||||
|
patchSetA, patchSetB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadHistory(boolean load) {
|
public void setLoadHistory(boolean load) {
|
||||||
@@ -146,11 +157,15 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
change = control.getChange();
|
change = control.getChange();
|
||||||
project = change.getProject();
|
project = change.getProject();
|
||||||
|
|
||||||
aId = psa != null ? toObjectId(db, psa) : null;
|
PatchSet psEntityA = psa != null
|
||||||
bId = toObjectId(db, psb);
|
? psUtil.get(db, control.getNotes(), psa) : null;
|
||||||
|
PatchSet psEntityB = psUtil.get(db, control.getNotes(), psb);
|
||||||
|
|
||||||
if ((psa != null && !control.isPatchVisible(db.patchSets().get(psa), db)) ||
|
aId = psEntityA != null ? toObjectId(psEntityA) : null;
|
||||||
(psb != null && !control.isPatchVisible(db.patchSets().get(psb), db))) {
|
bId = toObjectId(psEntityB);
|
||||||
|
|
||||||
|
if ((psEntityA != null && !control.isPatchVisible(psEntityA, db)) ||
|
||||||
|
(psEntityB != null && !control.isPatchVisible(psEntityB, db))) {
|
||||||
throw new NoSuchChangeException(changeId);
|
throw new NoSuchChangeException(changeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +175,9 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
final PatchScriptBuilder b = newBuilder(list, git);
|
final PatchScriptBuilder b = newBuilder(list, git);
|
||||||
final PatchListEntry content = list.get(fileName);
|
final PatchListEntry content = list.get(fileName);
|
||||||
|
|
||||||
loadCommentsAndHistory(content.getChangeType(), //
|
loadCommentsAndHistory(control.getNotes(),
|
||||||
content.getOldName(), //
|
content.getChangeType(),
|
||||||
|
content.getOldName(),
|
||||||
content.getNewName());
|
content.getNewName());
|
||||||
|
|
||||||
return b.toPatchScript(content, comments, history);
|
return b.toPatchScript(content, comments, history);
|
||||||
@@ -200,26 +216,20 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectId toObjectId(final ReviewDb db, final PatchSet.Id psId)
|
private ObjectId toObjectId(PatchSet ps) throws NoSuchChangeException,
|
||||||
throws OrmException, NoSuchChangeException, AuthException,
|
AuthException, NoSuchChangeException, IOException {
|
||||||
NoSuchChangeException, IOException {
|
|
||||||
if (!changeId.equals(psId.getParentKey())) {
|
|
||||||
throw new NoSuchChangeException(changeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (psId.get() == 0) {
|
|
||||||
return getEditRev();
|
|
||||||
}
|
|
||||||
PatchSet ps = db.patchSets().get(psId);
|
|
||||||
if (ps == null || ps.getRevision() == null
|
if (ps == null || ps.getRevision() == null
|
||||||
|| ps.getRevision().get() == null) {
|
|| ps.getRevision().get() == null) {
|
||||||
throw new NoSuchChangeException(changeId);
|
throw new NoSuchChangeException(changeId);
|
||||||
}
|
}
|
||||||
|
if (ps.getId().get() == 0) {
|
||||||
|
return getEditRev();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return ObjectId.fromString(ps.getRevision().get());
|
return ObjectId.fromString(ps.getRevision().get());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.error("Patch set " + psId + " has invalid revision");
|
log.error("Patch set " + ps.getId() + " has invalid revision");
|
||||||
throw new NoSuchChangeException(changeId, e);
|
throw new NoSuchChangeException(changeId, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,9 +252,9 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadCommentsAndHistory(final ChangeType changeType,
|
private void loadCommentsAndHistory(ChangeNotes notes, ChangeType changeType,
|
||||||
final String oldName, final String newName) throws OrmException {
|
String oldName, String newName) throws OrmException {
|
||||||
final Map<Patch.Key, Patch> byKey = new HashMap<>();
|
Map<Patch.Key, Patch> byKey = new HashMap<>();
|
||||||
|
|
||||||
if (loadHistory) {
|
if (loadHistory) {
|
||||||
// This seems like a cheap trick. It doesn't properly account for a
|
// This seems like a cheap trick. It doesn't properly account for a
|
||||||
@@ -253,7 +263,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
// proper rename detection between the patch sets.
|
// proper rename detection between the patch sets.
|
||||||
//
|
//
|
||||||
history = new ArrayList<>();
|
history = new ArrayList<>();
|
||||||
for (final PatchSet ps : db.patchSets().byChange(changeId)) {
|
for (PatchSet ps : psUtil.byChange(db, notes)) {
|
||||||
if (!control.isPatchVisible(ps, db)) {
|
if (!control.isPatchVisible(ps, db)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -275,12 +285,12 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Patch p = new Patch(new Patch.Key(ps.getId(), name));
|
Patch p = new Patch(new Patch.Key(ps.getId(), name));
|
||||||
history.add(p);
|
history.add(p);
|
||||||
byKey.put(p.getKey(), p);
|
byKey.put(p.getKey(), p);
|
||||||
}
|
}
|
||||||
if (edit != null && edit.isPresent()) {
|
if (edit != null && edit.isPresent()) {
|
||||||
final Patch p = new Patch(new Patch.Key(
|
Patch p = new Patch(new Patch.Key(
|
||||||
new PatchSet.Id(psb.getParentKey(), 0), fileName));
|
new PatchSet.Id(psb.getParentKey(), 0), fileName));
|
||||||
history.add(p);
|
history.add(p);
|
||||||
byKey.put(p.getKey(), p);
|
byKey.put(p.getKey(), p);
|
||||||
@@ -288,7 +298,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (loadComments && edit == null) {
|
if (loadComments && edit == null) {
|
||||||
final AccountInfoCacheFactory aic = aicFactory.create();
|
AccountInfoCacheFactory aic = aicFactory.create();
|
||||||
comments = new CommentDetail(psa, psb);
|
comments = new CommentDetail(psa, psb);
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case ADDED:
|
case ADDED:
|
||||||
@@ -312,9 +322,9 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CurrentUser user = control.getUser();
|
CurrentUser user = control.getUser();
|
||||||
if (user.isIdentifiedUser()) {
|
if (user.isIdentifiedUser()) {
|
||||||
final Account.Id me = user.getAccountId();
|
Account.Id me = user.getAccountId();
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case ADDED:
|
case ADDED:
|
||||||
case MODIFIED:
|
case MODIFIED:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import com.google.gerrit.server.ChangeMessagesUtil;
|
|||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.change.MergeabilityCache;
|
import com.google.gerrit.server.change.MergeabilityCache;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.MergeUtil;
|
import com.google.gerrit.server.git.MergeUtil;
|
||||||
@@ -137,6 +138,7 @@ public class ChangeData {
|
|||||||
for (ChangeData cd : changes) {
|
for (ChangeData cd : changes) {
|
||||||
cd.patchSets();
|
cd.patchSets();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ResultSet<PatchSet>> results = new ArrayList<>(BATCH_SIZE);
|
List<ResultSet<PatchSet>> results = new ArrayList<>(BATCH_SIZE);
|
||||||
@@ -167,6 +169,7 @@ public class ChangeData {
|
|||||||
for (ChangeData cd : changes) {
|
for (ChangeData cd : changes) {
|
||||||
cd.currentPatchSet();
|
cd.currentPatchSet();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<PatchSet.Id, ChangeData> missing = Maps.newHashMap();
|
Map<PatchSet.Id, ChangeData> missing = Maps.newHashMap();
|
||||||
@@ -192,6 +195,7 @@ public class ChangeData {
|
|||||||
for (ChangeData cd : changes) {
|
for (ChangeData cd : changes) {
|
||||||
cd.currentApprovals();
|
cd.currentApprovals();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ResultSet<PatchSetApproval>> results = new ArrayList<>(BATCH_SIZE);
|
List<ResultSet<PatchSetApproval>> results = new ArrayList<>(BATCH_SIZE);
|
||||||
@@ -281,7 +285,7 @@ public class ChangeData {
|
|||||||
*/
|
*/
|
||||||
public static ChangeData createForTest(Change.Id id, int currentPatchSetId) {
|
public static ChangeData createForTest(Change.Id id, int currentPatchSetId) {
|
||||||
ChangeData cd = new ChangeData(null, null, null, null, null, null, null,
|
ChangeData cd = new ChangeData(null, null, null, null, null, null, null,
|
||||||
null, null, null, null, null, null, id);
|
null, null, null, null, null, null, null, id);
|
||||||
cd.currentPatchSet = new PatchSet(new PatchSet.Id(id, currentPatchSetId));
|
cd.currentPatchSet = new PatchSet(new PatchSet.Id(id, currentPatchSetId));
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
@@ -296,6 +300,7 @@ public class ChangeData {
|
|||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
private final PatchLineCommentsUtil plcUtil;
|
private final PatchLineCommentsUtil plcUtil;
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
private final NotesMigration notesMigration;
|
private final NotesMigration notesMigration;
|
||||||
private final MergeabilityCache mergeabilityCache;
|
private final MergeabilityCache mergeabilityCache;
|
||||||
@@ -306,7 +311,7 @@ public class ChangeData {
|
|||||||
private String commitMessage;
|
private String commitMessage;
|
||||||
private List<FooterLine> commitFooters;
|
private List<FooterLine> commitFooters;
|
||||||
private PatchSet currentPatchSet;
|
private PatchSet currentPatchSet;
|
||||||
private Collection<PatchSet> patchSets;
|
private List<PatchSet> patchSets;
|
||||||
private ListMultimap<PatchSet.Id, PatchSetApproval> allApprovals;
|
private ListMultimap<PatchSet.Id, PatchSetApproval> allApprovals;
|
||||||
private List<PatchSetApproval> currentApprovals;
|
private List<PatchSetApproval> currentApprovals;
|
||||||
private Map<Integer, List<String>> files = new HashMap<>();
|
private Map<Integer, List<String>> files = new HashMap<>();
|
||||||
@@ -335,6 +340,7 @@ public class ChangeData {
|
|||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
NotesMigration notesMigration,
|
NotesMigration notesMigration,
|
||||||
MergeabilityCache mergeabilityCache,
|
MergeabilityCache mergeabilityCache,
|
||||||
@@ -350,6 +356,7 @@ public class ChangeData {
|
|||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.notesMigration = notesMigration;
|
this.notesMigration = notesMigration;
|
||||||
this.mergeabilityCache = mergeabilityCache;
|
this.mergeabilityCache = mergeabilityCache;
|
||||||
@@ -367,6 +374,7 @@ public class ChangeData {
|
|||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
NotesMigration notesMigration,
|
NotesMigration notesMigration,
|
||||||
MergeabilityCache mergeabilityCache,
|
MergeabilityCache mergeabilityCache,
|
||||||
@@ -382,6 +390,7 @@ public class ChangeData {
|
|||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.notesMigration = notesMigration;
|
this.notesMigration = notesMigration;
|
||||||
this.mergeabilityCache = mergeabilityCache;
|
this.mergeabilityCache = mergeabilityCache;
|
||||||
@@ -400,6 +409,7 @@ public class ChangeData {
|
|||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
PatchSetUtil psUtil,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
NotesMigration notesMigration,
|
NotesMigration notesMigration,
|
||||||
MergeabilityCache mergeabilityCache,
|
MergeabilityCache mergeabilityCache,
|
||||||
@@ -415,6 +425,7 @@ public class ChangeData {
|
|||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
this.cmUtil = cmUtil;
|
this.cmUtil = cmUtil;
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.notesMigration = notesMigration;
|
this.notesMigration = notesMigration;
|
||||||
this.mergeabilityCache = mergeabilityCache;
|
this.mergeabilityCache = mergeabilityCache;
|
||||||
@@ -684,15 +695,14 @@ public class ChangeData {
|
|||||||
* @return patches for the change.
|
* @return patches for the change.
|
||||||
* @throws OrmException an error occurred reading the database.
|
* @throws OrmException an error occurred reading the database.
|
||||||
*/
|
*/
|
||||||
public Collection<PatchSet> patchSets()
|
public List<PatchSet> patchSets() throws OrmException {
|
||||||
throws OrmException {
|
|
||||||
if (patchSets == null) {
|
if (patchSets == null) {
|
||||||
patchSets = db.patchSets().byChange(legacyId).toList();
|
patchSets = psUtil.byChange(db, notes());
|
||||||
}
|
}
|
||||||
return patchSets;
|
return patchSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPatchSets(Collection<PatchSet> patchSets) {
|
public void setPatchSets(List<PatchSet> patchSets) {
|
||||||
this.currentPatchSet = null;
|
this.currentPatchSet = null;
|
||||||
this.patchSets = patchSets;
|
this.patchSets = patchSets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ public class CommandUtils {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw error("\"" + patchIdentity + "\" is not a valid patch set");
|
throw error("\"" + patchIdentity + "\" is not a valid patch set");
|
||||||
}
|
}
|
||||||
|
// TODO(dborowitz): Use PatchSetUtils; probably requires a non-static
|
||||||
|
// implementation.
|
||||||
PatchSet patchSet = db.patchSets().get(patchSetId);
|
PatchSet patchSet = db.patchSets().get(patchSetId);
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
throw error("\"" + patchIdentity + "\" no such patch set");
|
throw error("\"" + patchIdentity + "\" no such patch set");
|
||||||
|
|||||||
Reference in New Issue
Block a user