Mercurial > hg-stable
changeset 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 | e45ec589f962 |
children | 5779d096a696 |
files | mercurial/bundle2.py |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/bundle2.py Wed Sep 20 05:47:33 2017 +0200 +++ b/mercurial/bundle2.py Tue Sep 19 22:08:09 2017 +0200 @@ -179,7 +179,7 @@ _fpayloadsize = '>i' _fpartparamcount = '>BB' -_fphasesentry = '>i20s' +_fphasesentry = struct.Struct('>i20s') preferedchunksize = 4096 @@ -1483,7 +1483,7 @@ phasedata = [] for phase in phases.allphases: for head in headsbyphase[phase]: - phasedata.append(_pack(_fphasesentry, phase, head)) + phasedata.append(_fphasesentry.pack(phase, head)) bundler.newpart('phase-heads', data=''.join(phasedata)) def addparttagsfnodescache(repo, bundler, outgoing): @@ -1843,14 +1843,14 @@ def _readphaseheads(inpart): headsbyphase = [[] for i in phases.allphases] - entrysize = struct.calcsize(_fphasesentry) + entrysize = _fphasesentry.size while True: entry = inpart.read(entrysize) if len(entry) < entrysize: if entry: raise error.Abort(_('bad phase-heads bundle part')) break - phase, node = struct.unpack(_fphasesentry, entry) + phase, node = _fphasesentry.unpack(entry) headsbyphase[phase].append(node) return headsbyphase