# HG changeset patch # User Pierre-Yves David # Date 1400788329 25200 # Node ID 054fa5176fa7d8c8ef457a8333bc09e1cc10c2d0 # Parent e55888447958098e82a477f320522a122131b8d3 bundle2: forbid duplicate parameter keys No rules were specified about parameter key uniqueness. We document that keys should be unique and document it. This opens the way to a more friendly (read dictionary like) way to access value of parameters in the code. diff -r e55888447958 -r 054fa5176fa7 mercurial/bundle2.py --- a/mercurial/bundle2.py Fri May 23 16:46:30 2014 -0700 +++ b/mercurial/bundle2.py Thu May 22 12:52:09 2014 -0700 @@ -113,6 +113,8 @@ Mandatory parameters comes first, then the advisory ones. + Each parameter's key MUST be unique within the part. + :payload: payload is a series of ``. @@ -570,6 +572,12 @@ self._data = data self._mandatoryparams = list(mandatoryparams) self._advisoryparams = list(advisoryparams) + # checking for duplicated entries + self._seenparams = set() + for pname, __ in self._mandatoryparams + self._advisoryparams: + if pname in self._seenparams: + raise RuntimeError('duplicated params: %s' % pname) + self._seenparams.add(pname) # status of the part's generation: # - None: not started, # - False: currently generated, @@ -598,6 +606,9 @@ def addparam(self, name, value='', mandatory=True): if self._generated is not None: raise ReadOnlyPartError('part is being generated') + if name in self._seenparams: + raise ValueError('duplicated params: %s' % name) + self._seenparams.add(name) params = self._advisoryparams if mandatory: params = self._mandatoryparams