mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
bundle2: the ability to set `data
` attribute of the part is now official
We make it safe to set the data attribute after part creation. It is an allowed operation as long as the part has not started to be generated.
This commit is contained in:
parent
2ece793be7
commit
3c42f04f04
@ -554,13 +554,17 @@ class bundlepart(object):
|
||||
|
||||
The part `type` is used to route the part to the application level
|
||||
handler.
|
||||
|
||||
The part payload is contained in ``part.data``. It could be raw bytes or a
|
||||
generator of byte chunks. The data attribute cannot be modified after the
|
||||
generation has begun.
|
||||
"""
|
||||
|
||||
def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
|
||||
data=''):
|
||||
self.id = None
|
||||
self.type = parttype
|
||||
self.data = data
|
||||
self._data = data
|
||||
self.mandatoryparams = mandatoryparams
|
||||
self.advisoryparams = advisoryparams
|
||||
# status of the part's generation:
|
||||
@ -569,6 +573,15 @@ class bundlepart(object):
|
||||
# - True: generation done.
|
||||
self._generated = None
|
||||
|
||||
# methods used to defines the part content
|
||||
def __setdata(self, data):
|
||||
if self._generated is not None:
|
||||
raise ReadOnlyPartError('part is being generated')
|
||||
self._data = data
|
||||
def __getdata(self):
|
||||
return self._data
|
||||
data = property(__getdata, __setdata)
|
||||
|
||||
# methods used to generates the bundle2 stream
|
||||
def getchunks(self):
|
||||
if self._generated is not None:
|
||||
|
@ -84,8 +84,9 @@ Create an extension to test bundle2 API
|
||||
> bundler.newpart('b2x:replycaps', data=capsstring)
|
||||
>
|
||||
> if opts['pushrace']:
|
||||
> dummynode = '01234567890123456789'
|
||||
> bundler.newpart('b2x:check:heads', data=dummynode)
|
||||
> # also serve to test the assignement of data outside of init
|
||||
> part = bundler.newpart('b2x:check:heads')
|
||||
> part.data = '01234567890123456789'
|
||||
>
|
||||
> revs = opts['rev']
|
||||
> if 'rev' in opts:
|
||||
|
Loading…
Reference in New Issue
Block a user