# HG changeset patch # User Matt Mackall # Date 2010-09-19 17:51:54 # Node ID e21fe9c5fb252c2f9d41ff8151a41e9ce85383cf # Parent 50946802593dba9528494dc13690218048640265 bundle: get rid of chunkiter diff --git a/contrib/shrink-revlog.py b/contrib/shrink-revlog.py --- a/contrib/shrink-revlog.py +++ b/contrib/shrink-revlog.py @@ -117,7 +117,7 @@ def writerevs(ui, r1, r2, order, tr): try: group = util.chunkbuffer(r1.group(order, lookup, progress)) - r2.addgroup(group.chunks(), unlookup, tr) + r2.addgroup(group, unlookup, tr) finally: ui.progress(_('writing'), None) diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -33,7 +33,10 @@ class bundlerevlog(revlog.revlog): self.bundle = bundle self.basemap = {} def chunkpositer(): - for chunk in bundle.chunks(): + while 1: + chunk = bundle.chunk() + if not chunk: + break pos = bundle.tell() yield chunk, pos - len(chunk) n = len(self) @@ -230,8 +233,10 @@ class bundlerepository(localrepo.localre if not chunk: break self.bundlefilespos[chunk] = self.bundle.tell() - for c in self.bundle.chunks(): - pass + while 1: + c = self.bundle.chunk() + if not c: + break if f[0] == '/': f = f[1:] diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -24,17 +24,6 @@ def getchunk(source): % (len(d), l - 4)) return d -def chunkiter(source, progress=None): - """iterate through the chunks in source, yielding a sequence of chunks - (strings)""" - while 1: - c = getchunk(source) - if not c: - break - elif progress is not None: - progress() - yield c - def chunkheader(length): """return a changegroup chunk header (string)""" return struct.pack(">l", length + 4) @@ -94,15 +83,18 @@ def writebundle(cg, filename, bundletype # parse the changegroup data, otherwise we will block # in case of sshrepo because we don't know the end of the stream - # an empty chunkiter is the end of the changegroup - # a changegroup has at least 2 chunkiters (changelog and manifest). - # after that, an empty chunkiter is the end of the changegroup + # an empty chunkgroup is the end of the changegroup + # a changegroup has at least 2 chunkgroups (changelog and manifest). + # after that, an empty chunkgroup is the end of the changegroup empty = False count = 0 while not empty or count <= 2: empty = True count += 1 - for chunk in chunkiter(cg): + while 1: + chunk = getchunk(cg) + if not chunk: + break empty = False fh.write(z.compress(chunkheader(len(chunk)))) pos = 0 @@ -171,13 +163,6 @@ class unbundle10(object): % (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): self._h = h diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1676,7 +1676,7 @@ class localrepository(repo.repository): pr = prog() source.callback = pr - if (cl.addgroup(source.chunks(), csmap, trp) is None + if (cl.addgroup(source, csmap, trp) is None and not emptyok): raise util.Abort(_("received changelog group is empty")) clend = len(cl) @@ -1695,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(), revmap, trp) + self.manifest.addgroup(source, revmap, trp) self.ui.progress(_('manifests'), None) needfiles = {} @@ -1723,7 +1723,7 @@ class localrepository(repo.repository): pr() fl = self.file(f) o = len(fl) - if fl.addgroup(source.chunks(), revmap, trp) is None: + if fl.addgroup(source, revmap, trp) is None: raise util.Abort(_("received file revlog group is empty")) revisions += len(fl) - o files += 1 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1269,7 +1269,7 @@ class revlog(object): yield changegroup.closechunk() - def addgroup(self, revs, linkmapper, transaction): + def addgroup(self, bundle, linkmapper, transaction): """ add a delta group @@ -1301,7 +1301,10 @@ class revlog(object): try: # loop through our set of deltas chain = None - for chunk in revs: + while 1: + chunk = bundle.chunk() + if not chunk: + break node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) link = linkmapper(cs) if (node in self.nodemap and