Change: Add helper methods to check change state

To check a change's state the caller currently has to call getState()
and then do a comparison on the enum value.

To make this easier, introduce new methods on Change:

- isNew
- isMerged
- isAbandoned
- isClosed

Note that we don't add "isOpen" since there are no longer multiple
states that could be considered "open". Previously there were "new"
and "draft", but the draft workflow was removed.

Update callers to use the new methods.

Change-Id: Ic047f74b114e2277e66c878dace73ea8e0babab6
This commit is contained in:
David Pursehouse 2019-02-14 13:15:41 +09:00
parent f23f78c99f
commit 4c58e1031f
48 changed files with 114 additions and 117 deletions

View File

@ -112,7 +112,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
String insertIndex; String insertIndex;
try { try {
if (cd.change().getStatus().isOpen()) { if (cd.change().isNew()) {
insertIndex = OPEN_CHANGES; insertIndex = OPEN_CHANGES;
deleteIndex = CLOSED_CHANGES; deleteIndex = CLOSED_CHANGES;
} else { } else {

View File

@ -207,7 +207,7 @@ public class LuceneChangeIndex implements ChangeIndex {
// sub-index, so just pick one. // sub-index, so just pick one.
Document doc = openIndex.toDocument(cd); Document doc = openIndex.toDocument(cd);
try { try {
if (cd.change().getStatus().isOpen()) { if (cd.change().isNew()) {
Futures.allAsList(closedIndex.delete(id), openIndex.replace(id, doc)).get(); Futures.allAsList(closedIndex.delete(id), openIndex.replace(id, doc)).get();
} else { } else {
Futures.allAsList(openIndex.delete(id), closedIndex.replace(id, doc)).get(); Futures.allAsList(openIndex.delete(id), closedIndex.replace(id, doc)).get();

View File

@ -671,6 +671,22 @@ public final class Change {
status = newStatus.getCode(); status = newStatus.getCode();
} }
public boolean isNew() {
return getStatus().equals(Status.NEW);
}
public boolean isMerged() {
return getStatus().equals(Status.MERGED);
}
public boolean isAbandoned() {
return getStatus().equals(Status.ABANDONED);
}
public boolean isClosed() {
return isAbandoned() || isMerged();
}
public String getTopic() { public String getTopic() {
return topic; return topic;
} }

View File

@ -145,7 +145,7 @@ public class PatchSetUtil {
/** Is the current patch set locked against state changes? */ /** Is the current patch set locked against state changes? */
public boolean isPatchSetLocked(ChangeNotes notes) throws OrmException, IOException { public boolean isPatchSetLocked(ChangeNotes notes) throws OrmException, IOException {
Change change = notes.getChange(); Change change = notes.getChange();
if (change.getStatus() == Change.Status.MERGED) { if (change.isMerged()) {
return false; return false;
} }

View File

@ -83,7 +83,7 @@ public class AbandonOp implements BatchUpdateOp {
change = ctx.getChange(); change = ctx.getChange();
PatchSet.Id psId = change.currentPatchSetId(); PatchSet.Id psId = change.currentPatchSetId();
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
patchSet = psUtil.get(ctx.getNotes(), psId); patchSet = psUtil.get(ctx.getNotes(), psId);

View File

@ -29,7 +29,6 @@ import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription; import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.extensions.webui.UiActions; import com.google.gerrit.server.extensions.webui.UiActions;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
@ -180,8 +179,7 @@ public class ActionJson {
// The followup action is a client-side only operation that does not // The followup action is a client-side only operation that does not
// have a server side handler. It must be manually registered into the // have a server side handler. It must be manually registered into the
// resulting action map. // resulting action map.
Status status = notes.getChange().getStatus(); if (!notes.getChange().isAbandoned()) {
if (status.isOpen() || status.equals(Status.MERGED)) {
UiAction.Description descr = new UiAction.Description(); UiAction.Description descr = new UiAction.Description();
PrivateInternals_UiActionDescription.setId(descr, "followup"); PrivateInternals_UiActionDescription.setId(descr, "followup");
PrivateInternals_UiActionDescription.setMethod(descr, "POST"); PrivateInternals_UiActionDescription.setMethod(descr, "POST");

View File

@ -510,7 +510,7 @@ public class ChangeJson {
out.assignee = in.getAssignee() != null ? accountLoader.get(in.getAssignee()) : null; out.assignee = in.getAssignee() != null ? accountLoader.get(in.getAssignee()) : null;
out.hashtags = cd.hashtags(); out.hashtags = cd.hashtags();
out.changeId = in.getKey().get(); out.changeId = in.getKey().get();
if (in.getStatus().isOpen()) { if (in.isNew()) {
SubmitTypeRecord str = cd.submitTypeRecord(); SubmitTypeRecord str = cd.submitTypeRecord();
if (str.isOk()) { if (str.isOk()) {
out.submitType = str.type; out.submitType = str.type;
@ -547,7 +547,7 @@ public class ChangeJson {
} }
} }
if (in.getStatus().isOpen() && has(REVIEWED) && user.isIdentifiedUser()) { if (in.isNew() && has(REVIEWED) && user.isIdentifiedUser()) {
out.reviewed = cd.isReviewedBy(user.getAccountId()) ? true : null; out.reviewed = cd.isReviewedBy(user.getAccountId()) ? true : null;
} }
@ -560,7 +560,7 @@ public class ChangeJson {
if (user.isIdentifiedUser() if (user.isIdentifiedUser()
&& (!limitToPsId.isPresent() || limitToPsId.get().equals(in.currentPatchSetId()))) { && (!limitToPsId.isPresent() || limitToPsId.get().equals(in.currentPatchSetId()))) {
out.permittedLabels = out.permittedLabels =
cd.change().getStatus() != Change.Status.ABANDONED !cd.change().isAbandoned()
? labelsJson.permittedLabels(user.getAccountId(), cd) ? labelsJson.permittedLabels(user.getAccountId(), cd)
: ImmutableMap.of(); : ImmutableMap.of();
} }

View File

@ -368,12 +368,12 @@ public class ConsistencyChecker {
private void checkMergedBitMatchesStatus(PatchSet.Id psId, RevCommit commit, boolean merged) { private void checkMergedBitMatchesStatus(PatchSet.Id psId, RevCommit commit, boolean merged) {
String refName = change().getDest().get(); String refName = change().getDest().get();
if (merged && change().getStatus() != Change.Status.MERGED) { if (merged && !change().isMerged()) {
ProblemInfo p = wrongChangeStatus(psId, commit); ProblemInfo p = wrongChangeStatus(psId, commit);
if (fix != null) { if (fix != null) {
fixMerged(p); fixMerged(p);
} }
} else if (!merged && change().getStatus() == Change.Status.MERGED) { } else if (!merged && change().isMerged()) {
problem( problem(
String.format( String.format(
"Patch set %d (%s) is not merged into" "Patch set %d (%s) is not merged into"

View File

@ -41,7 +41,6 @@ import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.LabelInfo; import com.google.gerrit.extensions.common.LabelInfo;
import com.google.gerrit.extensions.common.VotingRangeInfo; import com.google.gerrit.extensions.common.VotingRangeInfo;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSetApproval; import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.server.ApprovalsUtil; import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.account.AccountLoader; import com.google.gerrit.server.account.AccountLoader;
@ -107,7 +106,7 @@ public class LabelsJson {
LabelTypes labelTypes = cd.getLabelTypes(); LabelTypes labelTypes = cd.getLabelTypes();
Map<String, LabelWithStatus> withStatus = Map<String, LabelWithStatus> withStatus =
cd.change().getStatus() == Change.Status.MERGED cd.change().isMerged()
? labelsForSubmittedChange(accountLoader, cd, labelTypes, standard, detailed) ? labelsForSubmittedChange(accountLoader, cd, labelTypes, standard, detailed)
: labelsForUnsubmittedChange(accountLoader, cd, labelTypes, standard, detailed); : labelsForUnsubmittedChange(accountLoader, cd, labelTypes, standard, detailed);
return ImmutableMap.copyOf(Maps.transformValues(withStatus, LabelWithStatus::label)); return ImmutableMap.copyOf(Maps.transformValues(withStatus, LabelWithStatus::label));
@ -116,7 +115,7 @@ public class LabelsJson {
/** Returns all labels that the provided user has permission to vote on. */ /** Returns all labels that the provided user has permission to vote on. */
Map<String, Collection<String>> permittedLabels(Account.Id filterApprovalsBy, ChangeData cd) Map<String, Collection<String>> permittedLabels(Account.Id filterApprovalsBy, ChangeData cd)
throws OrmException, PermissionBackendException { throws OrmException, PermissionBackendException {
boolean isMerged = cd.change().getStatus() == Change.Status.MERGED; boolean isMerged = cd.change().isMerged();
LabelTypes labelTypes = cd.getLabelTypes(); LabelTypes labelTypes = cd.getLabelTypes();
Map<String, LabelType> toCheck = new HashMap<>(); Map<String, LabelType> toCheck = new HashMap<>();
for (SubmitRecord rec : submitRecords(cd)) { for (SubmitRecord rec : submitRecords(cd)) {
@ -434,9 +433,10 @@ public class LabelsJson {
private void setAllApprovals( private void setAllApprovals(
AccountLoader accountLoader, ChangeData cd, Map<String, LabelWithStatus> labels) AccountLoader accountLoader, ChangeData cd, Map<String, LabelWithStatus> labels)
throws OrmException, PermissionBackendException { throws OrmException, PermissionBackendException {
Change.Status status = cd.change().getStatus();
checkState( checkState(
status != Change.Status.MERGED, "should not call setAllApprovals on %s change", status); !cd.change().isMerged(),
"should not call setAllApprovals on %s change",
cd.change().getStatus());
// Include a user in the output for this label if either: // Include a user in the output for this label if either:
// - They are an explicit reviewer. // - They are an explicit reviewer.

View File

@ -194,7 +194,7 @@ public class PatchSetInserter implements BatchUpdateOp {
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
update.setSubjectForCommit("Create patch set " + psId.get()); update.setSubjectForCommit("Create patch set " + psId.get());
if (!change.getStatus().isOpen() && !allowClosed) { if (!change.isNew() && !allowClosed) {
throw new ResourceConflictException( throw new ResourceConflictException(
String.format( String.format(
"Cannot create new patch set of change %s because it is %s", "Cannot create new patch set of change %s because it is %s",

View File

@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkState;
import com.google.gerrit.extensions.restapi.MergeConflictException; import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.RevId; import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.ChangeUtil;
@ -194,8 +193,8 @@ public class RebaseChangeOp implements BatchUpdateOp {
+ " was rebased"); + " was rebased");
} }
if (base != null && base.notes().getChange().getStatus() != Change.Status.MERGED) { if (base != null && !base.notes().getChange().isMerged()) {
if (base.notes().getChange().getStatus() != Change.Status.MERGED) { if (!base.notes().getChange().isMerged()) {
// Add to end of relation chain for open base change. // Add to end of relation chain for open base change.
patchSetInserter.setGroups(base.patchSet().getGroups()); patchSetInserter.setGroups(base.patchSet().getGroups());
} else { } else {

View File

@ -22,7 +22,6 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException; import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
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.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
@ -164,12 +163,12 @@ public class RebaseUtil {
continue; continue;
} }
Change depChange = cd.change(); Change depChange = cd.change();
if (depChange.getStatus() == Status.ABANDONED) { if (depChange.isAbandoned()) {
throw new ResourceConflictException( throw new ResourceConflictException(
"Cannot rebase a change with an abandoned parent: " + depChange.getKey()); "Cannot rebase a change with an abandoned parent: " + depChange.getKey());
} }
if (depChange.getStatus().isOpen()) { if (depChange.isNew()) {
if (depPatchSet.getId().equals(depChange.currentPatchSetId())) { if (depPatchSet.getId().equals(depChange.currentPatchSetId())) {
throw new ResourceConflictException( throw new ResourceConflictException(
"Change is already based on the latest patch set of the dependent change."); "Change is already based on the latest patch set of the dependent change.");

View File

@ -397,7 +397,7 @@ public class ChangeEditModifier {
} }
Change c = notes.getChange(); Change c = notes.getChange();
if (!c.getStatus().isOpen()) { if (!c.isNew()) {
throw new ResourceConflictException( throw new ResourceConflictException(
String.format( String.format(
"change %s is %s", c.getChangeId(), c.getStatus().toString().toLowerCase())); "change %s is %s", c.getChangeId(), c.getStatus().toString().toLowerCase()));

View File

@ -190,7 +190,7 @@ public class EventFactory {
*/ */
public void extend(ChangeAttribute a, Change change) { public void extend(ChangeAttribute a, Change change) {
a.lastUpdated = change.getLastUpdatedOn().getTime() / 1000L; a.lastUpdated = change.getLastUpdatedOn().getTime() / 1000L;
a.open = change.getStatus().isOpen(); a.open = change.isNew();
} }
/** /**

View File

@ -125,8 +125,7 @@ public class MergedByPushOp implements BatchUpdateOp {
info = getPatchSetInfo(ctx); info = getPatchSetInfo(ctx);
ChangeUpdate update = ctx.getUpdate(psId); ChangeUpdate update = ctx.getUpdate(psId);
Change.Status status = change.getStatus(); if (change.isMerged()) {
if (status == Change.Status.MERGED) {
return true; return true;
} }
change.setCurrentPatchSet(info); change.setCurrentPatchSet(info);

View File

@ -1975,7 +1975,7 @@ class ReceiveCommits {
*/ */
private boolean requestReplace( private boolean requestReplace(
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) { ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
if (change.getStatus().isClosed()) { if (change.isClosed()) {
reject( reject(
cmd, cmd,
changeFormatter.changeClosed( changeFormatter.changeClosed(
@ -2712,7 +2712,7 @@ class ReceiveCommits {
return false; return false;
} }
if (change.getStatus().isClosed()) { if (change.isClosed()) {
reject(inputCommand, "change " + ontoChange + " closed"); reject(inputCommand, "change " + ontoChange + " closed");
return false; return false;
} else if (revisions.containsKey(newCommit)) { } else if (revisions.containsKey(newCommit)) {

View File

@ -246,7 +246,7 @@ public class ReplaceOp implements BatchUpdateOp {
ConfigInvalidException { ConfigInvalidException {
notes = ctx.getNotes(); notes = ctx.getNotes();
Change change = notes.getChange(); Change change = notes.getChange();
if (change == null || change.getStatus().isClosed()) { if (change == null || change.isClosed()) {
rejectMessage = CHANGE_IS_CLOSED; rejectMessage = CHANGE_IS_CLOSED;
return false; return false;
} }

View File

@ -165,7 +165,7 @@ class ChangeControl {
/** Can this user edit the topic name? */ /** Can this user edit the topic name? */
private boolean canEditTopicName() { private boolean canEditTopicName() {
if (getChange().getStatus().isOpen()) { if (getChange().isNew()) {
return isOwner() // owner (aka creator) of the change can edit topic return isOwner() // owner (aka creator) of the change can edit topic
|| refControl.isOwner() // branch owner can edit topic || refControl.isOwner() // branch owner can edit topic
|| getProjectControl().isOwner() // project owner can edit topic || getProjectControl().isOwner() // project owner can edit topic
@ -178,7 +178,7 @@ class ChangeControl {
/** Can this user edit the description? */ /** Can this user edit the description? */
private boolean canEditDescription() { private boolean canEditDescription() {
if (getChange().getStatus().isOpen()) { if (getChange().isNew()) {
return isOwner() // owner (aka creator) of the change can edit desc return isOwner() // owner (aka creator) of the change can edit desc
|| refControl.isOwner() // branch owner can edit desc || refControl.isOwner() // branch owner can edit desc
|| getProjectControl().isOwner() // project owner can edit desc || getProjectControl().isOwner() // project owner can edit desc

View File

@ -92,7 +92,7 @@ public class RemoveReviewerControl {
Account.Id reviewer, Account.Id reviewer,
int value) int value)
throws PermissionBackendException { throws PermissionBackendException {
if (change.getStatus().equals(Change.Status.MERGED)) { if (change.isMerged()) {
return false; return false;
} }

View File

@ -102,7 +102,7 @@ public class SubmitRuleEvaluator {
return ruleError("Error looking up change " + cd.getId(), e); return ruleError("Error looking up change " + cd.getId(), e);
} }
if (!opts.allowClosed() && change.getStatus().isClosed()) { if (!opts.allowClosed() && change.isClosed()) {
SubmitRecord rec = new SubmitRecord(); SubmitRecord rec = new SubmitRecord();
rec.status = SubmitRecord.Status.CLOSED; rec.status = SubmitRecord.Status.CLOSED;
return Collections.singletonList(rec); return Collections.singletonList(rec);

View File

@ -173,7 +173,7 @@ public class ChangeData {
throws OrmException { throws OrmException {
List<ChangeData> pending = new ArrayList<>(); List<ChangeData> pending = new ArrayList<>();
for (ChangeData cd : changes) { for (ChangeData cd : changes) {
if (cd.reviewedBy == null && cd.change().getStatus().isOpen()) { if (cd.reviewedBy == null && cd.change().isNew()) {
pending.add(cd); pending.add(cd);
} }
} }
@ -886,9 +886,9 @@ public class ChangeData {
if (c == null) { if (c == null) {
return null; return null;
} }
if (c.getStatus() == Change.Status.MERGED) { if (c.isMerged()) {
mergeable = true; mergeable = true;
} else if (c.getStatus() == Change.Status.ABANDONED) { } else if (c.isAbandoned()) {
return null; return null;
} else if (c.isWorkInProgress()) { } else if (c.isWorkInProgress()) {
return null; return null;

View File

@ -188,7 +188,7 @@ public class InternalChangeQuery extends InternalQuery<ChangeData, InternalChang
changeIds, changeIds,
cn -> { cn -> {
Change c = cn.getChange(); Change c = cn.getChange();
return c.getDest().equals(branch) && c.getStatus() != Change.Status.MERGED; return c.getDest().equals(branch) && !c.isMerged();
}); });
return Lists.transform(notes, n -> changeDataFactory.create(n)); return Lists.transform(notes, n -> changeDataFactory.create(n));
} }

View File

@ -137,7 +137,7 @@ public class Abandon extends RetryingRestModifyView<ChangeResource, AbandonInput
.setVisible(false); .setVisible(false);
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
return description; return description;
} }

View File

@ -31,7 +31,6 @@ import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
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.server.ApprovalsUtil; import com.google.gerrit.server.ApprovalsUtil;
@ -307,15 +306,15 @@ public class CherryPickChange {
} }
Change change = changeDatas.get(0).change(); Change change = changeDatas.get(0).change();
Change.Status status = change.getStatus(); if (!change.isAbandoned()) {
if (status == Status.NEW || status == Status.MERGED) {
// The base commit is a valid change revision. // The base commit is a valid change revision.
return baseCommit; return baseCommit;
} }
throw new ResourceConflictException( throw new ResourceConflictException(
String.format( String.format(
"Change %s with commit %s is %s", change.getChangeId(), base, status.asChangeStatus())); "Change %s with commit %s is %s",
change.getChangeId(), base, change.getStatus().asChangeStatus()));
} }
private Change.Id insertPatchSet( private Change.Id insertPatchSet(

View File

@ -50,7 +50,7 @@ public class DeleteChange extends RetryingRestModifyView<ChangeResource, Input,
protected Response<?> applyImpl( protected Response<?> applyImpl(
BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input) BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
throws RestApiException, UpdateException, PermissionBackendException { throws RestApiException, UpdateException, PermissionBackendException {
if (!isChangeDeletable(rsrc.getChange().getStatus())) { if (!isChangeDeletable(rsrc)) {
throw new MethodNotAllowedException("delete not permitted"); throw new MethodNotAllowedException("delete not permitted");
} }
rsrc.permissions().check(ChangePermission.DELETE); rsrc.permissions().check(ChangePermission.DELETE);
@ -66,16 +66,16 @@ public class DeleteChange extends RetryingRestModifyView<ChangeResource, Input,
@Override @Override
public UiAction.Description getDescription(ChangeResource rsrc) { public UiAction.Description getDescription(ChangeResource rsrc) {
Change.Status status = rsrc.getChange().getStatus();
PermissionBackend.ForChange perm = rsrc.permissions(); PermissionBackend.ForChange perm = rsrc.permissions();
return new UiAction.Description() return new UiAction.Description()
.setLabel("Delete") .setLabel("Delete")
.setTitle("Delete change " + rsrc.getId()) .setTitle("Delete change " + rsrc.getId())
.setVisible(and(isChangeDeletable(status), perm.testCond(ChangePermission.DELETE))); .setVisible(and(isChangeDeletable(rsrc), perm.testCond(ChangePermission.DELETE)));
} }
private static boolean isChangeDeletable(Change.Status status) { private static boolean isChangeDeletable(ChangeResource rsrc) {
if (status == Change.Status.MERGED) { Change change = rsrc.getChange();
if (change.isMerged()) {
// Merged changes should never be deleted. // Merged changes should never be deleted.
return false; return false;
} }

View File

@ -83,8 +83,7 @@ public class DeleteChangeOp implements BatchUpdateOp {
private void ensureDeletable(ChangeContext ctx, Change.Id id, Collection<PatchSet> patchSets) private void ensureDeletable(ChangeContext ctx, Change.Id id, Collection<PatchSet> patchSets)
throws ResourceConflictException, MethodNotAllowedException, IOException { throws ResourceConflictException, MethodNotAllowedException, IOException {
Change.Status status = ctx.getChange().getStatus(); if (ctx.getChange().isMerged()) {
if (status == Change.Status.MERGED) {
throw new MethodNotAllowedException("Deleting merged change " + id + " is not allowed"); throw new MethodNotAllowedException("Deleting merged change " + id + " is not allowed");
} }
for (PatchSet patchSet : patchSets) { for (PatchSet patchSet : patchSets) {

View File

@ -96,7 +96,7 @@ public class Mergeable implements RestReadView<RevisionResource> {
PatchSet ps = resource.getPatchSet(); PatchSet ps = resource.getPatchSet();
MergeableInfo result = new MergeableInfo(); MergeableInfo result = new MergeableInfo();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ps.getId().equals(change.currentPatchSetId())) { } else if (!ps.getId().equals(change.currentPatchSetId())) {
// Only the current revision is mergeable. Others always fail. // Only the current revision is mergeable. Others always fail.

View File

@ -33,7 +33,6 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.LabelId; import com.google.gerrit.reviewdb.client.LabelId;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
@ -133,7 +132,7 @@ public class Move extends RetryingRestModifyView<ChangeResource, MoveInput, Chan
} }
input.destinationBranch = RefNames.fullName(input.destinationBranch); input.destinationBranch = RefNames.fullName(input.destinationBranch);
if (change.getStatus().isClosed()) { if (!change.isNew()) {
throw new ResourceConflictException("Change is " + ChangeUtil.status(change)); throw new ResourceConflictException("Change is " + ChangeUtil.status(change));
} }
@ -181,7 +180,7 @@ public class Move extends RetryingRestModifyView<ChangeResource, MoveInput, Chan
public boolean updateChange(ChangeContext ctx) public boolean updateChange(ChangeContext ctx)
throws OrmException, ResourceConflictException, IOException { throws OrmException, ResourceConflictException, IOException {
change = ctx.getChange(); change = ctx.getChange();
if (change.getStatus() != Status.NEW) { if (!change.isNew()) {
throw new ResourceConflictException("Change is " + ChangeUtil.status(change)); throw new ResourceConflictException("Change is " + ChangeUtil.status(change));
} }
@ -293,7 +292,7 @@ public class Move extends RetryingRestModifyView<ChangeResource, MoveInput, Chan
.setVisible(false); .setVisible(false);
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
return description; return description;
} }

View File

@ -98,7 +98,7 @@ public class PostPrivate
private BooleanCondition canSetPrivate(ChangeResource rsrc) { private BooleanCondition canSetPrivate(ChangeResource rsrc) {
PermissionBackend.WithUser user = permissionBackend.user(rsrc.getUser()); PermissionBackend.WithUser user = permissionBackend.user(rsrc.getUser());
return or( return or(
rsrc.isUserOwner() && rsrc.getChange().getStatus() != Change.Status.MERGED, rsrc.isUserOwner() && !rsrc.getChange().isMerged(),
user.testCond(GlobalPermission.ADMINISTRATE_SERVER)); user.testCond(GlobalPermission.ADMINISTRATE_SERVER));
} }
} }

View File

@ -1122,7 +1122,7 @@ public class PostReview
// If no labels were modified and change is closed, abort early. // If no labels were modified and change is closed, abort early.
// This avoids trying to record a modified label caused by a user // This avoids trying to record a modified label caused by a user
// losing access to a label after the change was submitted. // losing access to a label after the change was submitted.
if (inLabels.isEmpty() && ctx.getChange().getStatus().isClosed()) { if (inLabels.isEmpty() && ctx.getChange().isClosed()) {
return false; return false;
} }
@ -1201,11 +1201,11 @@ public class PostReview
List<PatchSetApproval> ups, List<PatchSetApproval> ups,
List<PatchSetApproval> del) List<PatchSetApproval> del)
throws ResourceConflictException { throws ResourceConflictException {
if (ctx.getChange().getStatus().isOpen()) { if (ctx.getChange().isNew()) {
return; // Not closed, nothing to validate. return; // Not closed, nothing to validate.
} else if (del.isEmpty() && ups.isEmpty()) { } else if (del.isEmpty() && ups.isEmpty()) {
return; // No new votes. return; // No new votes.
} else if (ctx.getChange().getStatus() != Change.Status.MERGED) { } else if (!ctx.getChange().isMerged()) {
throw new ResourceConflictException("change is closed"); throw new ResourceConflictException("change is closed");
} }

View File

@ -99,7 +99,7 @@ public class PreviewSubmit implements RestReadView<RevisionResource> {
} }
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
throw new PreconditionFailedException("change is " + ChangeUtil.status(change)); throw new PreconditionFailedException("change is " + ChangeUtil.status(change));
} }
if (!rsrc.getUser().isIdentifiedUser()) { if (!rsrc.getUser().isIdentifiedUser()) {

View File

@ -27,7 +27,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
@ -115,7 +114,7 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
RevWalk rw = new RevWalk(reader); RevWalk rw = new RevWalk(reader);
BatchUpdate bu = BatchUpdate bu =
updateFactory.create(change.getProject(), rsrc.getUser(), TimeUtil.nowTs())) { updateFactory.create(change.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!hasOneParent(rw, rsrc.getPatchSet())) { } else if (!hasOneParent(rw, rsrc.getPatchSet())) {
throw new ResourceConflictException( throw new ResourceConflictException(
@ -175,7 +174,7 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
} else if (!baseChange.getDest().equals(change.getDest())) { } else if (!baseChange.getDest().equals(change.getDest())) {
throw new ResourceConflictException( throw new ResourceConflictException(
"base change is targeting wrong branch: " + baseChange.getDest()); "base change is targeting wrong branch: " + baseChange.getDest());
} else if (baseChange.getStatus() == Status.ABANDONED) { } else if (baseChange.isAbandoned()) {
throw new ResourceConflictException("base change is abandoned: " + baseChange.getKey()); throw new ResourceConflictException("base change is abandoned: " + baseChange.getKey());
} else if (isMergedInto(rw, rsrc.getPatchSet(), base.patchSet())) { } else if (isMergedInto(rw, rsrc.getPatchSet(), base.patchSet())) {
throw new ResourceConflictException( throw new ResourceConflictException(
@ -207,7 +206,7 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
.setVisible(false); .setVisible(false);
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (!(change.getStatus().isOpen() && rsrc.isCurrent())) { if (!(change.isNew() && rsrc.isCurrent())) {
return description; return description;
} }

View File

@ -113,7 +113,7 @@ public class Restore extends RetryingRestModifyView<ChangeResource, RestoreInput
@Override @Override
public boolean updateChange(ChangeContext ctx) throws OrmException, ResourceConflictException { public boolean updateChange(ChangeContext ctx) throws OrmException, ResourceConflictException {
change = ctx.getChange(); change = ctx.getChange();
if (change == null || change.getStatus() != Status.ABANDONED) { if (change == null || !change.isAbandoned()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
PatchSet.Id psId = change.currentPatchSetId(); PatchSet.Id psId = change.currentPatchSetId();
@ -162,7 +162,7 @@ public class Restore extends RetryingRestModifyView<ChangeResource, RestoreInput
.setVisible(false); .setVisible(false);
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (change.getStatus() != Status.ABANDONED) { if (!change.isAbandoned()) {
return description; return description;
} }

View File

@ -145,7 +145,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
throws IOException, OrmException, RestApiException, UpdateException, NoSuchChangeException, throws IOException, OrmException, RestApiException, UpdateException, NoSuchChangeException,
PermissionBackendException, NoSuchProjectException, ConfigInvalidException { PermissionBackendException, NoSuchProjectException, ConfigInvalidException {
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (change.getStatus() != Change.Status.MERGED) { if (!change.isMerged()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
@ -265,7 +265,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
.setTitle("Revert the change") .setTitle("Revert the change")
.setVisible( .setVisible(
and( and(
change.getStatus() == Change.Status.MERGED && projectStatePermitsWrite, change.isMerged() && projectStatePermitsWrite,
permissionBackend permissionBackend
.user(rsrc.getUser()) .user(rsrc.getUser())
.ref(change.getDest()) .ref(change.getDest())

View File

@ -24,7 +24,6 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
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.change.ChangeResource; import com.google.gerrit.server.change.ChangeResource;
@ -70,7 +69,7 @@ public class SetReadyForReview extends RetryingRestModifyView<ChangeResource, In
WorkInProgressOp.checkPermissions(permissionBackend, user.get(), rsrc.getChange()); WorkInProgressOp.checkPermissions(permissionBackend, user.get(), rsrc.getChange());
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (change.getStatus() != Status.NEW) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
@ -94,7 +93,7 @@ public class SetReadyForReview extends RetryingRestModifyView<ChangeResource, In
.setTitle("Set Ready For Review") .setTitle("Set Ready For Review")
.setVisible( .setVisible(
and( and(
rsrc.getChange().getStatus() == Status.NEW && rsrc.getChange().isWorkInProgress(), rsrc.getChange().isNew() && rsrc.getChange().isWorkInProgress(),
or( or(
rsrc.isUserOwner(), rsrc.isUserOwner(),
or( or(

View File

@ -24,7 +24,6 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
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.change.ChangeResource; import com.google.gerrit.server.change.ChangeResource;
@ -70,7 +69,7 @@ public class SetWorkInProgress extends RetryingRestModifyView<ChangeResource, In
WorkInProgressOp.checkPermissions(permissionBackend, user.get(), rsrc.getChange()); WorkInProgressOp.checkPermissions(permissionBackend, user.get(), rsrc.getChange());
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (change.getStatus() != Status.NEW) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
@ -94,7 +93,7 @@ public class SetWorkInProgress extends RetryingRestModifyView<ChangeResource, In
.setTitle("Set Work In Progress") .setTitle("Set Work In Progress")
.setVisible( .setVisible(
and( and(
rsrc.getChange().getStatus() == Status.NEW && !rsrc.getChange().isWorkInProgress(), rsrc.getChange().isNew() && !rsrc.getChange().isWorkInProgress(),
or( or(
rsrc.isUserOwner(), rsrc.isUserOwner(),
or( or(

View File

@ -195,7 +195,7 @@ public class Submit
throws OrmException, RestApiException, IOException, UpdateException, ConfigInvalidException, throws OrmException, RestApiException, IOException, UpdateException, ConfigInvalidException,
PermissionBackendException { PermissionBackendException {
Change change = rsrc.getChange(); Change change = rsrc.getChange();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change)); throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ProjectUtil.branchExists(repoManager, change.getDest())) { } else if (!ProjectUtil.branchExists(repoManager, change.getDest())) {
throw new ResourceConflictException( throw new ResourceConflictException(
@ -216,16 +216,13 @@ public class Submit
} }
} }
switch (change.getStatus()) { if (change.isMerged()) {
case MERGED: return change;
return change;
case NEW:
throw new RestApiException(
"change unexpectedly had status " + change.getStatus() + " after submit attempt");
case ABANDONED:
default:
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
if (change.isNew()) {
throw new RestApiException("change unexpectedly had status NEW after submit attempt");
}
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} }
/** /**
@ -300,7 +297,7 @@ public class Submit
@Override @Override
public UiAction.Description getDescription(RevisionResource resource) { public UiAction.Description getDescription(RevisionResource resource) {
Change change = resource.getChange(); Change change = resource.getChange();
if (!change.getStatus().isOpen() if (!change.isNew()
|| change.isWorkInProgress() || change.isWorkInProgress()
|| !resource.isCurrent() || !resource.isCurrent()
|| !resource.permissions().testOrFalse(ChangePermission.SUBMIT)) { || !resource.permissions().testOrFalse(ChangePermission.SUBMIT)) {

View File

@ -21,7 +21,6 @@ import static java.util.stream.Collectors.toList;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo; import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherOption; import com.google.gerrit.extensions.api.changes.SubmittedTogetherOption;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption; import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.BadRequestException;
@ -124,11 +123,11 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
List<ChangeData> cds; List<ChangeData> cds;
int hidden; int hidden;
if (c.getStatus().isOpen()) { if (c.isNew()) {
ChangeSet cs = mergeSuperSet.get().completeChangeSet(c, resource.getUser()); ChangeSet cs = mergeSuperSet.get().completeChangeSet(c, resource.getUser());
cds = ensureRequiredDataIsLoaded(cs.changes().asList()); cds = ensureRequiredDataIsLoaded(cs.changes().asList());
hidden = cs.nonVisibleChanges().size(); hidden = cs.nonVisibleChanges().size();
} else if (c.getStatus().asChangeStatus() == ChangeStatus.MERGED) { } else if (c.isMerged()) {
cds = queryProvider.get().bySubmissionId(c.getSubmissionId()); cds = queryProvider.get().bySubmissionId(c.getSubmissionId());
hidden = 0; hidden = 0;
} else { } else {

View File

@ -159,7 +159,7 @@ public class PrologRuleEvaluator {
return ruleError("Error looking up change " + cd.getId(), e); return ruleError("Error looking up change " + cd.getId(), e);
} }
if (!opts.allowClosed() && change.getStatus().isClosed()) { if (!opts.allowClosed() && change.isClosed()) {
SubmitRecord rec = new SubmitRecord(); SubmitRecord rec = new SubmitRecord();
rec.status = SubmitRecord.Status.CLOSED; rec.status = SubmitRecord.Status.CLOSED;
return Collections.singletonList(rec); return Collections.singletonList(rec);

View File

@ -383,9 +383,8 @@ public class MergeOp implements AutoCloseable {
!cs.furtherHiddenChanges(), "checkSubmitRulesAndState called for topic with hidden change"); !cs.furtherHiddenChanges(), "checkSubmitRulesAndState called for topic with hidden change");
for (ChangeData cd : cs.changes()) { for (ChangeData cd : cs.changes()) {
try { try {
Change.Status status = cd.change().getStatus(); if (!cd.change().isNew()) {
if (status != Change.Status.NEW) { if (!(cd.change().isMerged() && allowMerged)) {
if (!(status == Change.Status.MERGED && allowMerged)) {
commitStatus.problem( commitStatus.problem(
cd.getId(), cd.getId(),
"Change " + cd.getId() + " is " + cd.change().getStatus().toString().toLowerCase()); "Change " + cd.getId() + " is " + cd.change().getStatus().toString().toLowerCase());
@ -906,7 +905,7 @@ public class MergeOp implements AutoCloseable {
@Override @Override
public boolean updateChange(ChangeContext ctx) { public boolean updateChange(ChangeContext ctx) {
Change change = ctx.getChange(); Change change = ctx.getChange();
if (!change.getStatus().isOpen()) { if (!change.isNew()) {
return false; return false;
} }

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.submit;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
@ -126,8 +125,7 @@ public class RebaseSorter {
// check if the commit associated change is merged in the same branch // check if the commit associated change is merged in the same branch
List<ChangeData> changes = queryProvider.get().byCommit(commit); List<ChangeData> changes = queryProvider.get().byCommit(commit);
for (ChangeData change : changes) { for (ChangeData change : changes) {
if (change.change().getStatus() == Status.MERGED if (change.change().isMerged() && change.change().getDest().equals(dest)) {
&& change.change().getDest().equals(dest)) {
logger.atFine().log( logger.atFine().log(
"Dependency %s associated with merged change %s.", commit.getName(), change.getId()); "Dependency %s associated with merged change %s.", commit.getName(), change.getId());
return true; return true;

View File

@ -215,7 +215,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
"%s#updateChange for change %s", getClass().getSimpleName(), toMerge.change().getId()); "%s#updateChange for change %s", getClass().getSimpleName(), toMerge.change().getId());
toMerge.setNotes(ctx.getNotes()); // Update change and notes from ctx. toMerge.setNotes(ctx.getNotes()); // Update change and notes from ctx.
if (ctx.getChange().getStatus() == Change.Status.MERGED) { if (ctx.getChange().isMerged()) {
// Either another thread won a race, or we are retrying a whole topic submission after one // Either another thread won a race, or we are retrying a whole topic submission after one
// repo failed with lock failure. // repo failed with lock failure.
if (alreadyMergedCommit == null) { if (alreadyMergedCommit == null) {

View File

@ -1783,7 +1783,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
// Added a new patch set and auto-closed the change. // Added a new patch set and auto-closed the change.
cd = byChangeId(id); cd = byChangeId(id);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd.change().isMerged()).isTrue();
assertThat(getPatchSetRevisions(cd)) assertThat(getPatchSetRevisions(cd))
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableMap.of(1, ps1Rev, 2, testRepo.getRepository().resolve("HEAD").name())); ImmutableMap.of(1, ps1Rev, 2, testRepo.getRepository().resolve("HEAD").name()));
@ -1801,7 +1801,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
// Change not updated. // Change not updated.
cd = byChangeId(id); cd = byChangeId(id);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.NEW); assertThat(cd.change().isNew()).isTrue();
assertThat(getPatchSetRevisions(cd)).containsExactlyEntriesIn(ImmutableMap.of(1, ps1Rev)); assertThat(getPatchSetRevisions(cd)).containsExactlyEntriesIn(ImmutableMap.of(1, ps1Rev));
} }
@ -1851,7 +1851,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
testRepo.reset(ps2Commit); testRepo.reset(ps2Commit);
ChangeData cd = byCommit(ps1Commit); ChangeData cd = byCommit(ps1Commit);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.NEW); assertThat(cd.change().isNew()).isTrue();
assertThat(getPatchSetRevisions(cd)) assertThat(getPatchSetRevisions(cd))
.containsExactlyEntriesIn(ImmutableMap.of(1, ps1Commit.name())); .containsExactlyEntriesIn(ImmutableMap.of(1, ps1Commit.name()));
return c.getId(); return c.getId();

View File

@ -160,7 +160,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
RevCommit c = r.getCommit(); RevCommit c = r.getCommit();
PatchSet.Id psId = cd.currentPatchSet().getId(); PatchSet.Id psId = cd.currentPatchSet().getId();
assertThat(psId.get()).isEqualTo(1); assertThat(psId.get()).isEqualTo(1);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd.change().isMerged()).isTrue();
assertSubmitApproval(psId); assertSubmitApproval(psId);
assertThat(cd.patchSets()).hasSize(1); assertThat(cd.patchSets()).hasSize(1);
@ -184,7 +184,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
assertCommit(project, master); assertCommit(project, master);
ChangeData cd = ChangeData cd =
Iterables.getOnlyElement(queryProvider.get().byKey(new Change.Key(r.getChangeId()))); Iterables.getOnlyElement(queryProvider.get().byKey(new Change.Key(r.getChangeId())));
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd.change().isMerged()).isTrue();
RemoteRefUpdate.Status status = pushCommitTo(commit, "refs/for/other"); RemoteRefUpdate.Status status = pushCommitTo(commit, "refs/for/other");
assertThat(status).isEqualTo(RemoteRefUpdate.Status.OK); assertThat(status).isEqualTo(RemoteRefUpdate.Status.OK);
@ -194,7 +194,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
for (ChangeData c : queryProvider.get().byKey(new Change.Key(r.getChangeId()))) { for (ChangeData c : queryProvider.get().byKey(new Change.Key(r.getChangeId()))) {
if (c.change().getDest().get().equals(other)) { if (c.change().getDest().get().equals(other)) {
assertThat(c.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(c.change().isMerged()).isTrue();
} }
} }
} }
@ -230,7 +230,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
ChangeData cd = r.getChange(); ChangeData cd = r.getChange();
RevCommit c2 = r.getCommit(); RevCommit c2 = r.getCommit();
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd.change().isMerged()).isTrue();
PatchSet.Id psId2 = cd.change().currentPatchSetId(); PatchSet.Id psId2 = cd.change().currentPatchSetId();
assertThat(psId2.get()).isEqualTo(2); assertThat(psId2.get()).isEqualTo(2);
assertCommit(project, "refs/heads/master"); assertCommit(project, "refs/heads/master");
@ -262,7 +262,7 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
cd = changeDataFactory.create(project, psId1.getParentKey()); cd = changeDataFactory.create(project, psId1.getParentKey());
Change c = cd.change(); Change c = cd.change();
assertThat(c.getStatus()).isEqualTo(Change.Status.MERGED); assertThat(c.isMerged()).isTrue();
assertThat(c.currentPatchSetId()).isEqualTo(psId1); assertThat(c.currentPatchSetId()).isEqualTo(psId1);
assertThat(cd.patchSets().stream().map(PatchSet::getId).collect(toList())) assertThat(cd.patchSets().stream().map(PatchSet::getId).collect(toList()))
.containsExactly(psId1, psId2); .containsExactly(psId1, psId2);
@ -301,14 +301,14 @@ public class SubmitOnPushIT extends AbstractDaemonTest {
assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master"); assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
ChangeData cd2 = r2.getChange(); ChangeData cd2 = r2.getChange();
assertThat(cd2.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd2.change().isMerged()).isTrue();
PatchSet.Id psId2_2 = cd2.change().currentPatchSetId(); PatchSet.Id psId2_2 = cd2.change().currentPatchSetId();
assertThat(psId2_2.get()).isEqualTo(2); assertThat(psId2_2.get()).isEqualTo(2);
assertThat(cd2.patchSet(psId2_1).getRevision().get()).isEqualTo(c2_1.name()); assertThat(cd2.patchSet(psId2_1).getRevision().get()).isEqualTo(c2_1.name());
assertThat(cd2.patchSet(psId2_2).getRevision().get()).isEqualTo(c2_2.name()); assertThat(cd2.patchSet(psId2_2).getRevision().get()).isEqualTo(c2_2.name());
ChangeData cd1 = r1.getChange(); ChangeData cd1 = r1.getChange();
assertThat(cd1.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd1.change().isMerged()).isTrue();
PatchSet.Id psId1_2 = cd1.change().currentPatchSetId(); PatchSet.Id psId1_2 = cd1.change().currentPatchSetId();
assertThat(psId1_2.get()).isEqualTo(2); assertThat(psId1_2.get()).isEqualTo(2);
assertThat(cd1.patchSet(psId1_1).getRevision().get()).isEqualTo(c1_1.name()); assertThat(cd1.patchSet(psId1_1).getRevision().get()).isEqualTo(c1_1.name());

View File

@ -50,7 +50,6 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException; import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.Comment; import com.google.gerrit.reviewdb.client.Comment;
import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.Patch;
@ -336,7 +335,7 @@ public class ImpersonationIT extends AbstractDaemonTest {
gApi.changes().id(changeId).current().submit(in); gApi.changes().id(changeId).current().submit(in);
ChangeData cd = r.getChange(); ChangeData cd = r.getChange();
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(cd.change().isMerged()).isTrue();
PatchSetApproval submitter = PatchSetApproval submitter =
approvalsUtil.getSubmitter(cd.notes(), cd.change().currentPatchSetId()); approvalsUtil.getSubmitter(cd.notes(), cd.change().currentPatchSetId());
assertThat(submitter.getAccountId()).isEqualTo(admin2.id); assertThat(submitter.getAccountId()).isEqualTo(admin2.id);

View File

@ -379,7 +379,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
"Marked change as merged")); "Marked change as merged"));
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().isMerged()).isTrue();
assertNoProblems(notes, null); assertNoProblems(notes, null);
} }
@ -422,7 +422,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
"Marked change as merged")); "Marked change as merged"));
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().isMerged()).isTrue();
assertNoProblems(notes, null); assertNoProblems(notes, null);
} }
@ -572,7 +572,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
PatchSet.Id psId3 = new PatchSet.Id(notes.getChangeId(), 3); PatchSet.Id psId3 = new PatchSet.Id(notes.getChangeId(), 3);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().isMerged()).isTrue();
assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps2.getId(), psId3); assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps2.getId(), psId3);
assertThat(psUtil.get(notes, psId3).getRevision().get()).isEqualTo(rev1); assertThat(psUtil.get(notes, psId3).getRevision().get()).isEqualTo(rev1);
} }
@ -620,7 +620,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
PatchSet.Id psId4 = new PatchSet.Id(notes.getChangeId(), 4); PatchSet.Id psId4 = new PatchSet.Id(notes.getChangeId(), 4);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId4); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId4);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().isMerged()).isTrue();
assertThat(psUtil.byChangeAsMap(notes).keySet()) assertThat(psUtil.byChangeAsMap(notes).keySet())
.containsExactly(ps1.getId(), ps3.getId(), psId4); .containsExactly(ps1.getId(), ps3.getId(), psId4);
assertThat(psUtil.get(notes, psId4).getRevision().get()).isEqualTo(rev2); assertThat(psUtil.get(notes, psId4).getRevision().get()).isEqualTo(rev2);
@ -657,7 +657,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
notes = reload(notes); notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2); assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(notes.getChange().getStatus()).isEqualTo(Change.Status.MERGED); assertThat(notes.getChange().isMerged()).isTrue();
assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps1.getId(), psId2); assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps1.getId(), psId2);
assertThat(psUtil.get(notes, psId2).getRevision().get()).isEqualTo(rev2); assertThat(psUtil.get(notes, psId2).getRevision().get()).isEqualTo(rev2);
} }

View File

@ -253,7 +253,7 @@ public class ChangeProtoConverterTest {
assertThat(change.currentPatchSetId()).isNull(); assertThat(change.currentPatchSetId()).isNull();
// Default values for unset protobuf fields which can't be unset in the entity object. // Default values for unset protobuf fields which can't be unset in the entity object.
assertThat(change.getRowVersion()).isEqualTo(0); assertThat(change.getRowVersion()).isEqualTo(0);
assertThat(change.getStatus()).isEqualTo(Change.Status.NEW); assertThat(change.isNew()).isTrue();
assertThat(change.isPrivate()).isFalse(); assertThat(change.isPrivate()).isFalse();
assertThat(change.isWorkInProgress()).isFalse(); assertThat(change.isWorkInProgress()).isFalse();
assertThat(change.hasReviewStarted()).isFalse(); assertThat(change.hasReviewStarted()).isFalse();

@ -1 +1 @@
Subproject commit a9456bfdb862dfa7197583decac3c22149ae8109 Subproject commit d7ba4997b5c0038c85f6393b73a9ca16ca4fb927