Enforce label uniqueness in ProjectConfig and ProjectState

Within a single project, it is an error to specify two different
labels that differ only in case. (Multiple [label "Foo"] sections with
the same case are automatically collapsed by JGit.)

Between projects, it is valid to override a label "Foo" in a parent
project with a label "foo" in a child.

Change-Id: Ica6b990feefb272d1675c0f006162afbe51335b5
This commit is contained in:
Dave Borowitz
2013-02-25 14:19:11 -08:00
parent 0e0a41a281
commit 6045c9d956
2 changed files with 12 additions and 2 deletions

View File

@@ -532,8 +532,17 @@ public class ProjectConfig extends VersionedMetaData {
}
private void loadLabelSections(Config rc) throws IOException {
Map<String, String> lowerNames = Maps.newHashMapWithExpectedSize(2);
labelSections = Maps.newLinkedHashMap();
for (String name : rc.getSubsections(LABEL)) {
String lower = name.toLowerCase();
if (lowerNames.containsKey(lower)) {
error(new ValidationError(PROJECT_CONFIG, String.format(
"Label \"%s\" conflicts with \"%s\"",
name, lowerNames.get(lower))));
}
lowerNames.put(lower, name);
List<LabelValue> values = Lists.newArrayList();
for (String value : rc.getStringList(LABEL, name, KEY_VALUE)) {
try {

View File

@@ -347,9 +347,10 @@ public class ProjectState {
Collections.reverse(projects);
for (ProjectState s : projects) {
for (LabelType type : s.getConfig().getLabelSections().values()) {
LabelType old = types.get(type.getName());
String lower = type.getName().toLowerCase();
LabelType old = types.get(lower);
if (old == null || !old.canOverride()) {
types.put(type.getName(), type);
types.put(lower, type);
}
}
}