PatchSet: Always use non-null Lists for groups
Although groups may be "missing" due to patch sets being created prior to the schema migration that added that field, the fact that these are represented in the database as null is an implementation detail. In practice we do not distinguish between empty groups and null groups, so potentially returning both of them from the API is confusing. Note that we definitely don't distinguish between these in the secondary index. Require that groups always be a non-null, and check for an empty group list to determine whether groups are "missing". This also means it's natural to use a List<String> for groups, which are naturally an ordered list. The one place where this doesn't hold is when coming out of GroupCollector, which for internal reasons needs to use a Set for deduplication. Have the few callers of that class copy the result to a list. Change-Id: I0b276e16b3ac02fd882ff1cb23d5dfd1fc7bcd20
This commit is contained in:
committed by
Edwin Kempin
parent
b3d7f7328e
commit
a714938965
@@ -100,7 +100,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
private Change.Status status;
|
||||
private String topic;
|
||||
private String message;
|
||||
private Iterable<String> groups;
|
||||
private List<String> groups = Collections.emptyList();
|
||||
private CommitValidators.Policy validatePolicy =
|
||||
CommitValidators.Policy.GERRIT;
|
||||
private NotifyHandling notify = NotifyHandling.ALL;
|
||||
@@ -238,7 +238,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChangeInserter setGroups(Iterable<String> groups) {
|
||||
public ChangeInserter setGroups(List<String> groups) {
|
||||
checkNotNull(groups, "groups may not be empty");
|
||||
checkState(patchSet == null,
|
||||
"setGroups(Iterable<String>) only valid before creating change");
|
||||
this.groups = groups;
|
||||
@@ -319,8 +320,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
update.setTopic(change.getTopic());
|
||||
|
||||
boolean draft = status == Change.Status.DRAFT;
|
||||
Iterable<String> newGroups = groups;
|
||||
if (newGroups == null) {
|
||||
List<String> newGroups = groups;
|
||||
if (newGroups.isEmpty()) {
|
||||
newGroups = GroupCollector.getDefaultGroups(commit);
|
||||
}
|
||||
patchSet = psUtil.insert(ctx.getDb(), ctx.getRevWalk(), update, psId,
|
||||
|
||||
Reference in New Issue
Block a user