Mercurial > hg-stable
comparison mercurial/bundle2.py @ 34325:4fbbdd9b04f1
phases: use a Struct object for binary encoding and decoding
We will move the binary encoding and decoding code to 'phases.py' in order to
make it easier to reuse. First, let's cleanup it a bit.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Tue, 19 Sep 2017 22:08:09 +0200 |
parents | 2bdd55abd56c |
children | 5779d096a696 |
comparison
equal
deleted
inserted
replaced
34324:e45ec589f962 | 34325:4fbbdd9b04f1 |
---|---|
177 _fparttypesize = '>B' | 177 _fparttypesize = '>B' |
178 _fpartid = '>I' | 178 _fpartid = '>I' |
179 _fpayloadsize = '>i' | 179 _fpayloadsize = '>i' |
180 _fpartparamcount = '>BB' | 180 _fpartparamcount = '>BB' |
181 | 181 |
182 _fphasesentry = '>i20s' | 182 _fphasesentry = struct.Struct('>i20s') |
183 | 183 |
184 preferedchunksize = 4096 | 184 preferedchunksize = 4096 |
185 | 185 |
186 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]') | 186 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]') |
187 | 187 |
1481 if opts.get('phases', False): | 1481 if opts.get('phases', False): |
1482 headsbyphase = phases.subsetphaseheads(repo, outgoing.missing) | 1482 headsbyphase = phases.subsetphaseheads(repo, outgoing.missing) |
1483 phasedata = [] | 1483 phasedata = [] |
1484 for phase in phases.allphases: | 1484 for phase in phases.allphases: |
1485 for head in headsbyphase[phase]: | 1485 for head in headsbyphase[phase]: |
1486 phasedata.append(_pack(_fphasesentry, phase, head)) | 1486 phasedata.append(_fphasesentry.pack(phase, head)) |
1487 bundler.newpart('phase-heads', data=''.join(phasedata)) | 1487 bundler.newpart('phase-heads', data=''.join(phasedata)) |
1488 | 1488 |
1489 def addparttagsfnodescache(repo, bundler, outgoing): | 1489 def addparttagsfnodescache(repo, bundler, outgoing): |
1490 # we include the tags fnode cache for the bundle changeset | 1490 # we include the tags fnode cache for the bundle changeset |
1491 # (as an optional parts) | 1491 # (as an optional parts) |
1841 kwargs[key] = inpart.params[key] | 1841 kwargs[key] = inpart.params[key] |
1842 raise error.PushkeyFailed(partid=str(inpart.id), **kwargs) | 1842 raise error.PushkeyFailed(partid=str(inpart.id), **kwargs) |
1843 | 1843 |
1844 def _readphaseheads(inpart): | 1844 def _readphaseheads(inpart): |
1845 headsbyphase = [[] for i in phases.allphases] | 1845 headsbyphase = [[] for i in phases.allphases] |
1846 entrysize = struct.calcsize(_fphasesentry) | 1846 entrysize = _fphasesentry.size |
1847 while True: | 1847 while True: |
1848 entry = inpart.read(entrysize) | 1848 entry = inpart.read(entrysize) |
1849 if len(entry) < entrysize: | 1849 if len(entry) < entrysize: |
1850 if entry: | 1850 if entry: |
1851 raise error.Abort(_('bad phase-heads bundle part')) | 1851 raise error.Abort(_('bad phase-heads bundle part')) |
1852 break | 1852 break |
1853 phase, node = struct.unpack(_fphasesentry, entry) | 1853 phase, node = _fphasesentry.unpack(entry) |
1854 headsbyphase[phase].append(node) | 1854 headsbyphase[phase].append(node) |
1855 return headsbyphase | 1855 return headsbyphase |
1856 | 1856 |
1857 @parthandler('phase-heads') | 1857 @parthandler('phase-heads') |
1858 def handlephases(op, inpart): | 1858 def handlephases(op, inpart): |