[PATCH 01 of 10 v2] bundle-ng: move bundler creation up in the stack

Benoit Boissinot benoit.boissinot at ens-lyon.org
Fri May 10 16:59:49 CDT 2013


# HG changeset patch
# User Benoit Boissinot <benoit.boissinot at ens-lyon.org>
# Date 1368211061 -7200
#      Fri May 10 20:37:41 2013 +0200
# Node ID 106958c40111127bf7e9c71b43b61c51f06898ca
# Parent  12459bfa4b591f173059305e93bc3bab7b4ba704
bundle-ng: move bundler creation up in the stack

Create a simple start() method to pass the lookup function until bundler
becomes smarter and gets a repo object.

Since we now create the bundler for the whole lifetime, we need to pass it
down to revlog methods.

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,8 @@
     unlookup = lambda x: int(x, 10)
 
     try:
-        bundler = changegroup.bundle10(lookup)
+        bundler = changegroup.bundle10()
+        bundler.start(lookup)
         group = util.chunkbuffer(r1.group(order, bundler))
         group = changegroup.unbundle10(group, "UN")
         r2.addgroup(group, unlookup, tr)
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -225,7 +225,9 @@
 
 class bundle10(object):
     deltaheader = _BUNDLE10_DELTA_HEADER
-    def __init__(self, lookup):
+    def __init__(self):
+        pass
+    def start(self, lookup):
         self._lookup = lookup
     def close(self):
         return closechunk()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1840,7 +1840,9 @@
                     if revs is None and not outgoing.excluded:
                         # push everything,
                         # use the fast path, no race possible on push
-                        cg = self._changegroup(outgoing.missing, 'push')
+                        bundler = changegroup.bundle10()
+                        cg = self._changegroup(outgoing.missing, bundler,
+                                               'push')
                     else:
                         cg = self.getlocalbundle('push', outgoing)
 
@@ -1986,7 +1988,8 @@
         csets, bases, heads = cl.nodesbetween(bases, heads)
         # We assume that all ancestors of bases are known
         common = cl.ancestors([cl.rev(n) for n in bases])
-        return self._changegroupsubset(common, csets, heads, source)
+        bundler = changegroup.bundle10()
+        return self._changegroupsubset(common, csets, heads, bundler, source)
 
     def getlocalbundle(self, source, outgoing):
         """Like getbundle, but taking a discovery.outgoing as an argument.
@@ -1995,9 +1998,11 @@
         precomputed sets in outgoing."""
         if not outgoing.missing:
             return None
+        bundler = changegroup.bundle10()
         return self._changegroupsubset(outgoing.common,
                                        outgoing.missing,
                                        outgoing.missingheads,
+                                       bundler,
                                        source)
 
     def getbundle(self, source, heads=None, common=None):
@@ -2021,7 +2026,7 @@
                                    discovery.outgoing(cl, common, heads))
 
     @unfilteredmethod
-    def _changegroupsubset(self, commonrevs, csets, heads, source):
+    def _changegroupsubset(self, commonrevs, csets, heads, bundler, source):
 
         cl = self.changelog
         mf = self.manifest
@@ -2034,7 +2039,7 @@
         # can we go through the fast path ?
         heads.sort()
         if heads == sorted(self.heads()):
-            return self._changegroup(csets, source)
+            return self._changegroup(csets, bundler, source)
 
         # slow path
         self.hook('preoutgoing', throw=True, source=source)
@@ -2076,7 +2081,7 @@
                          unit=_files, total=count[1])
                 return fstate[1][x]
 
-        bundler = changegroup.bundle10(lookup)
+        bundler.start(lookup)
         reorder = self.ui.config('bundle', 'reorder', 'auto')
         if reorder == 'auto':
             reorder = None
@@ -2133,7 +2138,7 @@
         return self.changegroupsubset(basenodes, self.heads(), source)
 
     @unfilteredmethod
-    def _changegroup(self, nodes, source):
+    def _changegroup(self, nodes, bundler, source):
         """Compute the changegroup of all nodes that we have that a recipient
         doesn't.  Return a chunkbuffer object whose read() method will return
         successive changegroup chunks.
@@ -2184,7 +2189,7 @@
                     total=count[1], unit=_files)
                 return cl.node(revlog.linkrev(revlog.rev(x)))
 
-        bundler = changegroup.bundle10(lookup)
+        bundler.start(lookup)
         reorder = self.ui.config('bundle', 'reorder', 'auto')
         if reorder == 'auto':
             reorder = None


More information about the Mercurial-devel mailing list