Rework SUBM label in LabelId

Use a static method instead of a public LabelId field. LabelId is
mutable, so naming it like a constant is misleading at best. At worst,
a caller could call SUBMIT.set(newValue) and change the value seen by
all callers in the process. (Fortunately no callers were doing this as
far as I could tell.)

While we're in there, rename methods to refer to this as a "legacy"
submit label, as we want to eventually get rid of it in NoteDb.

Change-Id: Id7fbddfaac1d625839c66c73231d4e4ba2550c50
This commit is contained in:
Dave Borowitz
2016-03-08 10:01:49 -08:00
parent 6df8475ac5
commit 79ecc14466
14 changed files with 20 additions and 16 deletions

View File

@@ -321,7 +321,7 @@ public class ApprovalsUtil {
}
PatchSetApproval submitter = null;
for (PatchSetApproval a : approvals) {
if (a.getPatchSetId().equals(c) && a.getValue() > 0 && a.isSubmit()) {
if (a.getPatchSetId().equals(c) && a.getValue() > 0 && a.isLegacySubmit()) {
if (submitter == null
|| a.getGranted().compareTo(submitter.getGranted()) > 0) {
submitter = a;

View File

@@ -611,7 +611,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
for (PatchSetApproval a : approvalsUtil.byPatchSetUser(
ctx.getDb(), ctx.getControl(), psId, user.getAccountId())) {
if (a.isSubmit()) {
if (a.isLegacySubmit()) {
continue;
}

View File

@@ -127,7 +127,7 @@ public class LabelNormalizer {
checkArgument(changeId.equals(ctl.getId()),
"Approval %s does not match change %s",
psa.getKey(), ctl.getChange().getKey());
if (psa.isSubmit()) {
if (psa.isLegacySubmit()) {
unchanged.add(psa);
continue;
}

View File

@@ -253,7 +253,7 @@ public class MergeUtil {
continue;
}
if (a.isSubmit()) {
if (a.isLegacySubmit()) {
// Submit is treated specially, below (becomes committer)
//
if (submitAudit == null

View File

@@ -2565,7 +2565,7 @@ public class ReceiveCommits {
new PatchSetApproval.Key(
change.currentPatchSetId(),
ctx.getUser().getAccountId(),
LabelId.SUBMIT),
LabelId.legacySubmit()),
(short) 1, ctx.getWhen());
update.putApproval(submitter.getLabel(), submitter.getValue());
ctx.getDb().patchSetApprovals().upsert(

View File

@@ -301,7 +301,7 @@ public class ReplaceOp extends BatchUpdate.Op {
for (PatchSetApproval a : approvalsUtil.byPatchSetUser(ctx.getDb(),
ctx.getControl(), priorPatchSetId,
ctx.getUser().getAccountId())) {
if (a.isSubmit()) {
if (a.isLegacySubmit()) {
continue;
}

View File

@@ -337,7 +337,7 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
new PatchSetApproval.Key(
psId,
ctx.getUser().getAccountId(),
LabelId.SUBMIT),
LabelId.legacySubmit()),
(short) 1, ctx.getWhen());
byKey.put(submitter.getKey(), submitter);
submitter.setValue((short) 1);
@@ -373,7 +373,7 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
// TODO(dborowitz): Don't use a label in notedb; just check when status
// change happened.
for (PatchSetApproval psa : normalized.unchanged()) {
if (includeUnchanged || psa.isSubmit()) {
if (includeUnchanged || psa.isLegacySubmit()) {
logDebug("Adding submit label " + psa);
update.putApprovalFor(
psa.getAccountId(), psa.getLabel(), psa.getValue());

View File

@@ -359,7 +359,7 @@ public class ChangeField {
Set<String> allApprovals = Sets.newHashSet();
Set<String> distinctApprovals = Sets.newHashSet();
for (PatchSetApproval a : input.currentApprovals()) {
if (a.getValue() != 0 && !a.isSubmit()) {
if (a.getValue() != 0 && !a.isLegacySubmit()) {
allApprovals.add(formatLabel(a.getLabel(), a.getValue(),
a.getAccountId()));
distinctApprovals.add(formatLabel(a.getLabel(), a.getValue()));

View File

@@ -857,7 +857,7 @@ public class ChangeData {
public Optional<PatchSetApproval> getSubmitApproval()
throws OrmException {
for (PatchSetApproval psa : currentApprovals()) {
if (psa.isSubmit()) {
if (psa.isLegacySubmit()) {
return Optional.fromNullable(psa);
}
}