changeset 19200:4cfdec944edf

bundle-ng: move group into the bundler No additional semantic changes made.
author Sune Foldager <cryo@cyanite.org>
date Fri, 10 May 2013 21:03:01 +0200
parents d6d0f1ed8ebb
children 309c439cdbaa
files contrib/shrink-revlog.py mercurial/changegroup.py mercurial/localrepo.py mercurial/revlog.py
diffstat 4 files changed, 50 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/shrink-revlog.py	Fri May 10 20:37:41 2013 +0200
+++ b/contrib/shrink-revlog.py	Fri May 10 21:03:01 2013 +0200
@@ -119,7 +119,7 @@
     try:
         bundler = changegroup.bundle10()
         bundler.start(lookup)
-        group = util.chunkbuffer(r1.group(order, bundler))
+        group = util.chunkbuffer(bundler.group(order, r1))
         group = changegroup.unbundle10(group, "UN")
         r2.addgroup(group, unlookup, tr)
     finally:
--- a/mercurial/changegroup.py	Fri May 10 20:37:41 2013 +0200
+++ b/mercurial/changegroup.py	Fri May 10 21:03:01 2013 +0200
@@ -7,7 +7,7 @@
 
 from i18n import _
 from node import nullrev
-import mdiff, util
+import mdiff, util, dagutil
 import struct, os, bz2, zlib, tempfile
 
 _BUNDLE10_DELTA_HEADER = "20s20s20s20s"
@@ -231,8 +231,49 @@
         self._lookup = lookup
     def close(self):
         return closechunk()
+
     def fileheader(self, fname):
         return chunkheader(len(fname)) + fname
+
+    def group(self, nodelist, revlog, reorder=None):
+        """Calculate a delta group, yielding a sequence of changegroup chunks
+        (strings).
+
+        Given a list of changeset revs, return a set of deltas and
+        metadata corresponding to nodes. The first delta is
+        first parent(nodelist[0]) -> nodelist[0], the receiver is
+        guaranteed to have this parent as it has all history before
+        these changesets. In the case firstparent is nullrev the
+        changegroup starts with a full revision.
+        """
+
+        # if we don't have any revisions touched by these changesets, bail
+        if len(nodelist) == 0:
+            yield self.close()
+            return
+
+        # for generaldelta revlogs, we linearize the revs; this will both be
+        # much quicker and generate a much smaller bundle
+        if (revlog._generaldelta and reorder is not False) or reorder:
+            dag = dagutil.revlogdag(revlog)
+            revs = set(revlog.rev(n) for n in nodelist)
+            revs = dag.linearize(revs)
+        else:
+            revs = sorted([revlog.rev(n) for n in nodelist])
+
+        # add the parent of the first rev
+        p = revlog.parentrevs(revs[0])[0]
+        revs.insert(0, p)
+
+        # build deltas
+        for r in xrange(len(revs) - 1):
+            prev, curr = revs[r], revs[r + 1]
+            for c in self.revchunk(revlog, curr, prev):
+                yield c
+
+        yield self.close()
+
+
     def revchunk(self, revlog, rev, prev):
         node = revlog.node(rev)
         p1, p2 = revlog.parentrevs(rev)
--- a/mercurial/localrepo.py	Fri May 10 20:37:41 2013 +0200
+++ b/mercurial/localrepo.py	Fri May 10 21:03:01 2013 +0200
@@ -2092,7 +2092,7 @@
             # Create a changenode group generator that will call our functions
             # back to lookup the owning changenode and collect information.
             count[:] = [0, len(csets)]
-            for chunk in cl.group(csets, bundler, reorder=reorder):
+            for chunk in bundler.group(csets, cl, reorder=reorder):
                 yield chunk
             progress(_bundling, None)
 
@@ -2101,7 +2101,7 @@
             for f in changedfiles:
                 fnodes[f] = {}
             count[:] = [0, len(mfs)]
-            for chunk in mf.group(prune(mf, mfs), bundler, reorder=reorder):
+            for chunk in bundler.group(prune(mf, mfs), mf, reorder=reorder):
                 yield chunk
             progress(_bundling, None)
 
@@ -2121,7 +2121,7 @@
                 if nodelist:
                     count[0] += 1
                     yield bundler.fileheader(fname)
-                    for chunk in filerevlog.group(nodelist, bundler, reorder):
+                    for chunk in bundler.group(nodelist, filerevlog, reorder):
                         yield chunk
 
             # Signal that no more groups are left.
@@ -2201,12 +2201,12 @@
             # construct a list of all changed files
 
             count[:] = [0, len(nodes)]
-            for chunk in cl.group(nodes, bundler, reorder=reorder):
+            for chunk in bundler.group(nodes, cl, reorder=reorder):
                 yield chunk
             progress(_bundling, None)
 
             count[:] = [0, len(mfs)]
-            for chunk in mf.group(gennodelst(mf), bundler, reorder=reorder):
+            for chunk in bundler.group(gennodelst(mf), mf, reorder=reorder):
                 yield chunk
             progress(_bundling, None)
 
@@ -2221,7 +2221,7 @@
                 if nodelist:
                     count[0] += 1
                     yield bundler.fileheader(fname)
-                    for chunk in filerevlog.group(nodelist, bundler, reorder):
+                    for chunk in bundler.group(nodelist, filerevlog, reorder):
                         yield chunk
             yield bundler.close()
             progress(_bundling, None)
--- a/mercurial/revlog.py	Fri May 10 20:37:41 2013 +0200
+++ b/mercurial/revlog.py	Fri May 10 21:03:01 2013 +0200
@@ -14,7 +14,7 @@
 # import stuff from node for others to import from revlog
 from node import bin, hex, nullid, nullrev
 from i18n import _
-import ancestor, mdiff, parsers, error, util, dagutil
+import ancestor, mdiff, parsers, error, util
 import struct, zlib, errno
 
 _pack = struct.pack
@@ -1143,44 +1143,6 @@
         self._basecache = (curr, chainbase)
         return node
 
-    def group(self, nodelist, bundler, reorder=None):
-        """Calculate a delta group, yielding a sequence of changegroup chunks
-        (strings).
-
-        Given a list of changeset revs, return a set of deltas and
-        metadata corresponding to nodes. The first delta is
-        first parent(nodelist[0]) -> nodelist[0], the receiver is
-        guaranteed to have this parent as it has all history before
-        these changesets. In the case firstparent is nullrev the
-        changegroup starts with a full revision.
-        """
-
-        # if we don't have any revisions touched by these changesets, bail
-        if len(nodelist) == 0:
-            yield bundler.close()
-            return
-
-        # for generaldelta revlogs, we linearize the revs; this will both be
-        # much quicker and generate a much smaller bundle
-        if (self._generaldelta and reorder is not False) or reorder:
-            dag = dagutil.revlogdag(self)
-            revs = set(self.rev(n) for n in nodelist)
-            revs = dag.linearize(revs)
-        else:
-            revs = sorted([self.rev(n) for n in nodelist])
-
-        # add the parent of the first rev
-        p = self.parentrevs(revs[0])[0]
-        revs.insert(0, p)
-
-        # build deltas
-        for r in xrange(len(revs) - 1):
-            prev, curr = revs[r], revs[r + 1]
-            for c in bundler.revchunk(self, curr, prev):
-                yield c
-
-        yield bundler.close()
-
     def addgroup(self, bundle, linkmapper, transaction):
         """
         add a delta group