Do not expect ApprovalType of Category SUBM

Pushing a new, rebased Patch Set for a Change failed with a
NullPointer if the first Patch Set could not be merged due
to a patch conflict.

The reason was that there is no ApprovalType of Category SUBM
anymore, but it is still stored in the database.

Change-Id: I058ba99b835813245283c04fdb08199c94957645
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
This commit is contained in:
Stefan Lay
2011-05-18 15:09:00 -07:00
committed by Shawn O. Pearce
parent 6a765190df
commit 71bebadf9f
5 changed files with 29 additions and 17 deletions

View File

@@ -187,11 +187,13 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
for (final PatchSetApproval ca : db.patchSetApprovals()
.byPatchSetUser(ps_id, aid)) {
final ApprovalCategory.Id category = ca.getCategoryId();
if (ApprovalCategory.SUBMIT.equals(category)) {
continue;
}
if (change.getStatus().isOpen()) {
fs.normalize(approvalTypes.byId(category), ca);
}
if (ca.getValue() == 0
|| ApprovalCategory.SUBMIT.equals(category)) {
if (ca.getValue() == 0) {
continue;
}
psas.put(category, ca);
@@ -231,11 +233,13 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
for (PatchSetApproval ca : db.patchSetApprovals().byPatchSet(ps_id)) {
final ApprovalCategory.Id category = ca.getCategoryId();
if (ApprovalCategory.SUBMIT.equals(category)) {
continue;
}
if (change.getStatus().isOpen()) {
fs.normalize(approvalTypes.byId(category), ca);
}
if (ca.getValue() == 0
|| ApprovalCategory.SUBMIT.equals(category)) {
if (ca.getValue() == 0) {
continue;
}
boolean keep = true;

View File

@@ -433,8 +433,10 @@ public class ChangeHookRunner {
Entry<ApprovalCategory.Id, ApprovalCategoryValue.Id> approval) {
ApprovalAttribute a = new ApprovalAttribute();
a.type = approval.getKey().get();
final ApprovalType at = approvalTypes.byId(approval.getKey());
a.description = at.getCategory().getName();
ApprovalType at = approvalTypes.byId(approval.getKey());
if (at != null) {
a.description = at.getCategory().getName();
}
a.value = Short.toString(approval.getValue().get());
return a;
}

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.git;
import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.common.data.ApprovalTypes;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.PatchSetApproval;
@@ -212,10 +213,10 @@ public class CreateCodeReviewNotes {
if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
submit = a;
} else {
ApprovalCategory type = approvalTypes.byId(a.getCategoryId()).getCategory();
ApprovalType type = approvalTypes.byId(a.getCategoryId());
if (type != null) {
formatter.appendApproval(
type,
type.getCategory(),
a.getValue(),
accountCache.get(a.getAccountId()).getAccount());
}

View File

@@ -1358,15 +1358,18 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
oldCC.add(a.getAccountId());
}
final ApprovalType type =
// ApprovalCategory.SUBMIT is still in db but not relevant in git-store
if (!ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
final ApprovalType type =
approvalTypes.byId(a.getCategoryId());
if (a.getPatchSetId().equals(priorPatchSet)
&& type.getCategory().isCopyMinScore() && type.isMaxNegative(a)) {
// If there was a negative vote on the prior patch set, carry it
// into this patch set.
//
db.patchSetApprovals().insert(
Collections.singleton(new PatchSetApproval(ps.getId(), a)));
if (a.getPatchSetId().equals(priorPatchSet)
&& type.getCategory().isCopyMinScore() && type.isMaxNegative(a)) {
// If there was a negative vote on the prior patch set, carry it
// into this patch set.
//
db.patchSetApprovals().insert(
Collections.singleton(new PatchSetApproval(ps.getId(), a)));
}
}
if (!haveAuthor && authorId != null && a.getAccountId().equals(authorId)) {

View File

@@ -171,7 +171,9 @@ public class PublishComments implements Callable<VoidResult> {
final short o = a.getValue();
a.setValue(want.get());
a.cache(change);
functionState.normalize(types.byId(a.getCategoryId()), a);
if (!ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
functionState.normalize(types.byId(a.getCategoryId()), a);
}
if (o != a.getValue()) {
// Value changed, ensure we update the database.
//