Fixed regression caused by the defaultValue feature

[1] added support for selecting default values for labels.
Unfortunately it also broke the ability to remove labels
as described in [2], more precisely by: "To remove a label in a child
project, add an empty label with the same name as in the parent."

This fix make it possible to push empty labels in project.config
to refs/meta/config again. Without it, the following error is returned
by gerrit: 'project.config: Invalid defaultValue "0" for label ...'

[1] https://gerrit-review.googlesource.com/#/c/55750/
[2] https://gerrit-review.googlesource.com/Documentation/config-labels.html#label_custom

Change-Id: Icd727f64cb7a904957a2acc5143fe801653cfabe
This commit is contained in:
Zalan Blenessy 2015-05-20 11:27:26 +02:00
parent 1ff91c0d82
commit 6e6c5cd072

View File

@ -684,13 +684,15 @@ public class ProjectConfig extends VersionedMetaData {
label.setFunctionName(null);
}
short dv = (short) rc.getInt(LABEL, name, KEY_DEFAULT_VALUE, 0);
if (isInRange(dv, values)) {
label.setDefaultValue(dv);
} else {
error(new ValidationError(PROJECT_CONFIG, String.format(
"Invalid %s \"%s\" for label \"%s\"",
KEY_DEFAULT_VALUE, dv, name)));
if (!values.isEmpty()) {
short dv = (short) rc.getInt(LABEL, name, KEY_DEFAULT_VALUE, 0);
if (isInRange(dv, values)) {
label.setDefaultValue(dv);
} else {
error(new ValidationError(PROJECT_CONFIG, String.format(
"Invalid %s \"%s\" for label \"%s\"",
KEY_DEFAULT_VALUE, dv, name)));
}
}
label.setCopyMinScore(
rc.getBoolean(LABEL, name, KEY_COPY_MIN_SCORE, false));