Always pass non-null ChangeData into Prolog environment
Injecting arbitrary objects via StoredValues is possible but cumbersome. The ChangeData passed in is useful because it can lazily compute its own fields without passing in additional objects. The only problem was it might have been null; fix it so that is not the case. This requires in turn allowing ChangeControl to produce non-null ChangeDatas in its method, which is enough to tip the scales in favor of having a ChangeControl.AssistedFactory. Change-Id: I6bac3cfac52b31ddaf36e1504ed229a0b188b6f4
This commit is contained in:
@@ -4,9 +4,7 @@ package gerrit;
|
||||
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.rules.StoredValues;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -40,20 +38,11 @@ class PRED__load_commit_labels_1 extends Predicate.P1 {
|
||||
|
||||
Term listHead = Prolog.Nil;
|
||||
try {
|
||||
ReviewDb db = StoredValues.REVIEW_DB.get(engine);
|
||||
PatchSet patchSet = StoredValues.PATCH_SET.get(engine);
|
||||
ChangeData cd = StoredValues.CHANGE_DATA.getOrNull(engine);
|
||||
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
|
||||
LabelTypes types =
|
||||
StoredValues.CHANGE_CONTROL.get(engine).getLabelTypes();
|
||||
|
||||
Iterable<PatchSetApproval> approvals;
|
||||
if (cd != null) {
|
||||
approvals = cd.currentApprovals();
|
||||
} else {
|
||||
approvals = db.patchSetApprovals().byPatchSet(patchSet.getId());
|
||||
}
|
||||
|
||||
for (PatchSetApproval a : approvals) {
|
||||
for (PatchSetApproval a : cd.currentApprovals()) {
|
||||
if (a.getValue() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user