Merge "Omit change JSON fields when data is missing"

This commit is contained in:
Shawn Pearce
2013-03-09 01:23:50 +00:00
committed by Gerrit Code Review

View File

@@ -248,7 +248,7 @@ public class ChangeJson {
out.reviewed = in.getStatus().isOpen() && isChangeReviewed(cd) ? true : null; out.reviewed = in.getStatus().isOpen() && isChangeReviewed(cd) ? true : null;
out.labels = labelsFor(cd, options.contains(LABELS), out.labels = labelsFor(cd, options.contains(LABELS),
options.contains(DETAILED_LABELS)); options.contains(DETAILED_LABELS));
if (options.contains(DETAILED_LABELS)) { if (out.labels != null && options.contains(DETAILED_LABELS)) {
out.permitted_labels = permittedLabels(cd); out.permitted_labels = permittedLabels(cd);
out.removable_reviewers = removableReviewers(cd, out.labels.values()); out.removable_reviewers = removableReviewers(cd, out.labels.values());
} }
@@ -257,10 +257,12 @@ public class ChangeJson {
if (options.contains(ALL_REVISIONS) || options.contains(CURRENT_REVISION) if (options.contains(ALL_REVISIONS) || options.contains(CURRENT_REVISION)
|| cd.getLimitedPatchSets() != null) { || cd.getLimitedPatchSets() != null) {
out.revisions = revisions(cd); out.revisions = revisions(cd);
for (String commit : out.revisions.keySet()) { if (out.revisions != null) {
if (out.revisions.get(commit).isCurrent) { for (String commit : out.revisions.keySet()) {
out.current_revision = commit; if (out.revisions.get(commit).isCurrent) {
break; out.current_revision = commit;
break;
}
} }
} }
} }
@@ -315,12 +317,12 @@ public class ChangeJson {
ChangeControl ctl = control(cd); ChangeControl ctl = control(cd);
if (ctl == null) { if (ctl == null) {
return Collections.emptyMap(); return null;
} }
PatchSet ps = cd.currentPatchSet(db); PatchSet ps = cd.currentPatchSet(db);
if (ps == null) { if (ps == null) {
return Collections.emptyMap(); return null;
} }
if (cd.getChange().getStatus().isOpen()) { if (cd.getChange().getStatus().isOpen()) {
@@ -553,7 +555,7 @@ public class ChangeJson {
throws OrmException { throws OrmException {
ChangeControl ctl = control(cd); ChangeControl ctl = control(cd);
if (ctl == null) { if (ctl == null) {
return Collections.emptyMap(); return null;
} }
ListMultimap<String, String> permitted = LinkedListMultimap.create(); ListMultimap<String, String> permitted = LinkedListMultimap.create();
@@ -592,7 +594,7 @@ public class ChangeJson {
Collection<LabelInfo> labels) throws OrmException { Collection<LabelInfo> labels) throws OrmException {
ChangeControl ctl = control(cd); ChangeControl ctl = control(cd);
if (ctl == null) { if (ctl == null) {
return ImmutableList.of(); return null;
} }
Set<Account.Id> fixed = Sets.newHashSetWithExpectedSize(labels.size()); Set<Account.Id> fixed = Sets.newHashSetWithExpectedSize(labels.size());
@@ -656,7 +658,7 @@ public class ChangeJson {
private Map<String, RevisionInfo> revisions(ChangeData cd) throws OrmException { private Map<String, RevisionInfo> revisions(ChangeData cd) throws OrmException {
ChangeControl ctl = control(cd); ChangeControl ctl = control(cd);
if (ctl == null) { if (ctl == null) {
return Collections.emptyMap(); return null;
} }
Collection<PatchSet> src; Collection<PatchSet> src;