# HG changeset patch # User Matt Mackall # Date 2010-09-19 17:38:44 # Node ID 50946802593dba9528494dc13690218048640265 # Parent 44c7dfc2f6a30ff4c5303db6129f52dab8a8f679 bundle: refactor progress callback This lets us eliminate the chunk iterator so we can have the bundle class parse headers. diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -142,6 +142,7 @@ class unbundle10(object): def __init__(self, fh, alg): self._stream = decompressor(fh, alg) self._type = alg + self.callback = None def compressed(self): return self._type != 'UN' def read(self, l): @@ -150,10 +151,32 @@ class unbundle10(object): return self._stream.seek(pos) def tell(self): return self._stream.tell() - def chunks(self, progress=None): - return chunkiter(self, progress) + + def chunklength(self): + d = self.read(4) + if not d: + return 0 + l = max(0, struct.unpack(">l", d)[0] - 4) + if l and self.callback: + self.callback() + return l + def chunk(self): - return getchunk(self) + """return the next chunk from changegroup 'source' as a string""" + l = self.chunklength() + d = self.read(l) + if len(d) < l: + raise util.Abort(_("premature EOF reading chunk" + " (got %d bytes, expected %d)") + % (len(d), l)) + return d + + def chunks(self): + while 1: + c = self.chunk() + if not c: + break + yield c class headerlessfixup(object): def __init__(self, fh, h): diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1674,7 +1674,9 @@ class localrepository(repo.repository): total=self.total) self.count += 1 pr = prog() - if (cl.addgroup(source.chunks(pr), csmap, trp) is None + source.callback = pr + + if (cl.addgroup(source.chunks(), csmap, trp) is None and not emptyok): raise util.Abort(_("received changelog group is empty")) clend = len(cl) @@ -1693,7 +1695,7 @@ class localrepository(repo.repository): # if the result of the merge of 1 and 2 is the same in 3 and 4, # no new manifest will be created and the manifest group will # be empty during the pull - self.manifest.addgroup(source.chunks(pr), revmap, trp) + self.manifest.addgroup(source.chunks(), revmap, trp) self.ui.progress(_('manifests'), None) needfiles = {} @@ -1711,6 +1713,8 @@ class localrepository(repo.repository): pr.step = 'files' pr.count = 1 pr.total = efiles + source.callback = None + while 1: f = source.chunk() if not f: