Skip to content

Commit f6b9d14

Browse files
committed
[update_checkout] Improved validation failure diagnostic.
Previously, if an alias were defined for multiple schemes, the produced diagnostic would only say that there was a collision, but did not specify where that collision was. Here, the diagnostic is improved to read RuntimeError: Configuration file defines the alias ALIAS in both the SCHEME_NAME_1 scheme and the SCHEME_NAME_2 scheme?!
1 parent 05c5171 commit f6b9d14

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import re
1818
import sys
1919
import traceback
20-
from functools import reduce
2120
from multiprocessing import Lock, Pool, cpu_count, freeze_support
2221

2322
from build_swift.build_swift.constants import SWIFT_SOURCE_ROOT
@@ -408,19 +407,16 @@ def validate_config(config):
408407
'too.'.format(scheme_name))
409408

410409
# Then make sure the alias names used by our branches are unique.
411-
#
412-
# We do this by constructing a list consisting of len(names),
413-
# set(names). Then we reduce over that list summing the counts and taking
414-
# the union of the sets. We have uniqueness if the length of the union
415-
# equals the length of the sum of the counts.
416-
data = [(len(v['aliases']), set(v['aliases']))
417-
for v in config['branch-schemes'].values()]
418-
result = reduce(lambda acc, x: (acc[0] + x[0], acc[1] | x[1]), data,
419-
(0, set([])))
420-
if result[0] == len(result[1]):
421-
return
422-
raise RuntimeError('Configuration file has schemes with duplicate '
423-
'aliases?!')
410+
seen = dict()
411+
for (scheme_name, scheme) in config['branch-schemes'].items():
412+
aliases = scheme['aliases']
413+
for alias in aliases:
414+
if alias in seen:
415+
raise RuntimeError('Configuration file defines the alias {0} '
416+
'in both the {1} scheme and the {2} scheme?!'
417+
.format(alias, seen[alias], scheme_name))
418+
else:
419+
seen[alias] = scheme_name
424420

425421

426422
def full_target_name(repository, target):

0 commit comments

Comments
 (0)