Patchwork [2,of,9] bundle-ng: move group into the bundler

login
register
mail settings
Submitter Sune Foldager
Date Feb. 14, 2013, 11:07 p.m.
Message ID <66e25980c10d10b00b65.1360883240@firefly.edlund.dk>
Download mbox | patch
Permalink /patch/999/
State Superseded, archived
Commit 4cfdec944edf53dbbe5379587f8d19ebada83a7e
Headers show

Comments

Sune Foldager - Feb. 14, 2013, 11:07 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1360432114 -3600
# Node ID 66e25980c10d10b00b658608472b251b2d3ee4fe
# Parent  d78029a5c1f72e2eb75321409ad969462b7d372f
bundle-ng: move group into the bundler
Pierre-Yves David - March 12, 2013, 4:33 p.m.
On Fri, Feb 15, 2013 at 12:07:20AM +0100, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager <cryo@cyanite.org>
> # Date 1360432114 -3600
> # Node ID 66e25980c10d10b00b658608472b251b2d3ee4fe
> # Parent  d78029a5c1f72e2eb75321409ad969462b7d372f
> bundle-ng: move group into the bundler

nitch: When I do such movement, I usually add a testimony that no semantical
changes were made.

> 
> diff -r d78029a5c1f7 -r 66e25980c10d contrib/shrink-revlog.py
> --- a/contrib/shrink-revlog.py	Sat Feb 09 18:52:22 2013 +0100
> +++ b/contrib/shrink-revlog.py	Sat Feb 09 18:48:34 2013 +0100
> @@ -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:
> diff -r d78029a5c1f7 -r 66e25980c10d mercurial/changegroup.py
> --- a/mercurial/changegroup.py	Sat Feb 09 18:52:22 2013 +0100
> +++ b/mercurial/changegroup.py	Sat Feb 09 18:48:34 2013 +0100
> @@ -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)
> diff -r d78029a5c1f7 -r 66e25980c10d mercurial/localrepo.py
> --- a/mercurial/localrepo.py	Sat Feb 09 18:52:22 2013 +0100
> +++ b/mercurial/localrepo.py	Sat Feb 09 18:48:34 2013 +0100
> @@ -2084,7 +2084,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)
>  
> @@ -2093,7 +2093,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)
>  
> @@ -2113,7 +2113,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.
> @@ -2193,12 +2193,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)
>  
> @@ -2213,7 +2213,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)
> diff -r d78029a5c1f7 -r 66e25980c10d mercurial/revlog.py
> --- a/mercurial/revlog.py	Sat Feb 09 18:52:22 2013 +0100
> +++ b/mercurial/revlog.py	Sat Feb 09 18:48:34 2013 +0100
> @@ -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
> @@ -1148,44 +1148,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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r d78029a5c1f7 -r 66e25980c10d contrib/shrink-revlog.py
--- a/contrib/shrink-revlog.py	Sat Feb 09 18:52:22 2013 +0100
+++ b/contrib/shrink-revlog.py	Sat Feb 09 18:48:34 2013 +0100
@@ -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:
diff -r d78029a5c1f7 -r 66e25980c10d mercurial/changegroup.py
--- a/mercurial/changegroup.py	Sat Feb 09 18:52:22 2013 +0100
+++ b/mercurial/changegroup.py	Sat Feb 09 18:48:34 2013 +0100
@@ -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)
diff -r d78029a5c1f7 -r 66e25980c10d mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sat Feb 09 18:52:22 2013 +0100
+++ b/mercurial/localrepo.py	Sat Feb 09 18:48:34 2013 +0100
@@ -2084,7 +2084,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)
 
@@ -2093,7 +2093,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)
 
@@ -2113,7 +2113,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.
@@ -2193,12 +2193,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)
 
@@ -2213,7 +2213,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)
diff -r d78029a5c1f7 -r 66e25980c10d mercurial/revlog.py
--- a/mercurial/revlog.py	Sat Feb 09 18:52:22 2013 +0100
+++ b/mercurial/revlog.py	Sat Feb 09 18:48:34 2013 +0100
@@ -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
@@ -1148,44 +1148,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