# HG changeset patch # User Pierre-Yves David # Date 1400782442 25200 # Node ID 7ff01befc7ecf6f27e6dd2320f08f4a5f7e910fb # Parent 5e08f3b655107a8fa2014ab9f23c84087d019066 bundle2: track life cycle of parts We introduce a ``_generated`` attribute on parts. Coming changesets will make it easier to update a part's contents after its creation. We need a way to track if the part is still open to modification or if it is currently being generated and should not be touched anymore. As a bonus, we can now detect and crash if someone manages to write bogus code to get a part generated twice. diff -r 5e08f3b65510 -r 7ff01befc7ec mercurial/bundle2.py --- a/mercurial/bundle2.py Fri May 23 15:59:19 2014 -0700 +++ b/mercurial/bundle2.py Thu May 22 11:14:02 2014 -0700 @@ -552,8 +552,17 @@ self.data = data self.mandatoryparams = mandatoryparams self.advisoryparams = advisoryparams + # status of the part's generation: + # - None: not started, + # - False: currently generated, + # - True: generation done. + self._generated = None + # methods used to generates the bundle2 stream def getchunks(self): + if self._generated is not None: + raise RuntimeError('part can only be consumed once') + self._generated = False #### header ## parttype header = [_pack(_fparttypesize, len(self.type)), @@ -591,6 +600,7 @@ yield chunk # end of payload yield _pack(_fpayloadsize, 0) + self._generated = True def _payloadchunks(self): """yield chunks of a the part payload