bundle: get rid of chunkiter
authorMatt Mackall <mpm@selenic.com>
Sun, 19 Sep 2010 12:51:54 -0500
changeset 12335 e21fe9c5fb25
parent 12334 50946802593d
child 12336 9d234f7d8a77
bundle: get rid of chunkiter
contrib/shrink-revlog.py
mercurial/bundlerepo.py
mercurial/changegroup.py
mercurial/localrepo.py
mercurial/revlog.py
--- a/contrib/shrink-revlog.py	Sun Sep 19 12:38:44 2010 -0500
+++ b/contrib/shrink-revlog.py	Sun Sep 19 12:51:54 2010 -0500
@@ -117,7 +117,7 @@
 
     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)
 
--- a/mercurial/bundlerepo.py	Sun Sep 19 12:38:44 2010 -0500
+++ b/mercurial/bundlerepo.py	Sun Sep 19 12:51:54 2010 -0500
@@ -33,7 +33,10 @@
         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 @@
                 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:]
--- a/mercurial/changegroup.py	Sun Sep 19 12:38:44 2010 -0500
+++ b/mercurial/changegroup.py	Sun Sep 19 12:51:54 2010 -0500
@@ -24,17 +24,6 @@
                           % (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 @@
         # 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 @@
                              % (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
--- a/mercurial/localrepo.py	Sun Sep 19 12:38:44 2010 -0500
+++ b/mercurial/localrepo.py	Sun Sep 19 12:51:54 2010 -0500
@@ -1676,7 +1676,7 @@
             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 @@
             # 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 @@
                 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
--- a/mercurial/revlog.py	Sun Sep 19 12:38:44 2010 -0500
+++ b/mercurial/revlog.py	Sun Sep 19 12:51:54 2010 -0500
@@ -1269,7 +1269,7 @@
 
         yield changegroup.closechunk()
 
-    def addgroup(self, revs, linkmapper, transaction):
+    def addgroup(self, bundle, linkmapper, transaction):
         """
         add a delta group
 
@@ -1301,7 +1301,10 @@
         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