# HG changeset patch # User Pierre-Yves David # Date 2014-05-22 18:14:02 # 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 --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -552,8 +552,17 @@ class bundlepart(object): 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 @@ class bundlepart(object): yield chunk # end of payload yield _pack(_fpayloadsize, 0) + self._generated = True def _payloadchunks(self): """yield chunks of a the part payload