Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 21607:054fa5176fa7
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 22 May 2014 12:52:09 -0700 |
parents | e55888447958 |
children | 3cb96ca90c17 |
comparison
equal
deleted
inserted
replaced
21606:e55888447958 | 21607:054fa5176fa7 |
---|---|
110 A blob of bytes from which each parameter key and value can be | 110 A blob of bytes from which each parameter key and value can be |
111 retrieved using the list of size couples stored in the previous | 111 retrieved using the list of size couples stored in the previous |
112 field. | 112 field. |
113 | 113 |
114 Mandatory parameters comes first, then the advisory ones. | 114 Mandatory parameters comes first, then the advisory ones. |
115 | |
116 Each parameter's key MUST be unique within the part. | |
115 | 117 |
116 :payload: | 118 :payload: |
117 | 119 |
118 payload is a series of `<chunksize><chunkdata>`. | 120 payload is a series of `<chunksize><chunkdata>`. |
119 | 121 |
568 self.id = None | 570 self.id = None |
569 self.type = parttype | 571 self.type = parttype |
570 self._data = data | 572 self._data = data |
571 self._mandatoryparams = list(mandatoryparams) | 573 self._mandatoryparams = list(mandatoryparams) |
572 self._advisoryparams = list(advisoryparams) | 574 self._advisoryparams = list(advisoryparams) |
575 # checking for duplicated entries | |
576 self._seenparams = set() | |
577 for pname, __ in self._mandatoryparams + self._advisoryparams: | |
578 if pname in self._seenparams: | |
579 raise RuntimeError('duplicated params: %s' % pname) | |
580 self._seenparams.add(pname) | |
573 # status of the part's generation: | 581 # status of the part's generation: |
574 # - None: not started, | 582 # - None: not started, |
575 # - False: currently generated, | 583 # - False: currently generated, |
576 # - True: generation done. | 584 # - True: generation done. |
577 self._generated = None | 585 self._generated = None |
596 return tuple(self._advisoryparams) | 604 return tuple(self._advisoryparams) |
597 | 605 |
598 def addparam(self, name, value='', mandatory=True): | 606 def addparam(self, name, value='', mandatory=True): |
599 if self._generated is not None: | 607 if self._generated is not None: |
600 raise ReadOnlyPartError('part is being generated') | 608 raise ReadOnlyPartError('part is being generated') |
609 if name in self._seenparams: | |
610 raise ValueError('duplicated params: %s' % name) | |
611 self._seenparams.add(name) | |
601 params = self._advisoryparams | 612 params = self._advisoryparams |
602 if mandatory: | 613 if mandatory: |
603 params = self._mandatoryparams | 614 params = self._mandatoryparams |
604 params.append((name, value)) | 615 params.append((name, value)) |
605 | 616 |