# HG changeset patch # User Matt Mackall # Date 2010-09-19 18:12:45 # Node ID 9d234f7d8a7784e1c866dc89b27eb7f6f2170a60 # Parent e21fe9c5fb252c2f9d41ff8151a41e9ce85383cf bundle: move chunk parsing into unbundle class diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -163,6 +163,15 @@ class unbundle10(object): % (len(d), l)) return d + def parsechunk(self): + l = self.chunklength() + if not l: + return {} + h = self.read(80) + node, p1, p2, cs = struct.unpack("20s20s20s20s", h) + data = self.read(l - 80) + return dict(node=node, p1=p1, p2=p2, cs=cs, data=data) + class headerlessfixup(object): def __init__(self, fh, h): self._h = h diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1302,18 +1302,21 @@ class revlog(object): # loop through our set of deltas chain = None while 1: - chunk = bundle.chunk() - if not chunk: + chunkdata = bundle.parsechunk() + if not chunkdata: break - node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) + node = chunkdata['node'] + p1 = chunkdata['p1'] + p2 = chunkdata['p2'] + cs = chunkdata['cs'] + delta = chunkdata['data'] + link = linkmapper(cs) if (node in self.nodemap and (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)): # this can happen if two branches make the same change chain = node continue - delta = buffer(chunk, 80) - del chunk for p in (p1, p2): if not p in self.nodemap: