bundle-ng: move bundler creation up in the stack
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Fri, 10 May 2013 20:37:41 +0200
changeset 19199 d6d0f1ed8ebb
parent 19196 0fbcabe523bc
child 19200 4cfdec944edf
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.
contrib/shrink-revlog.py
mercurial/changegroup.py
mercurial/localrepo.py
--- a/contrib/shrink-revlog.py	Tue May 14 18:52:52 2013 -0500
+++ b/contrib/shrink-revlog.py	Fri May 10 20:37:41 2013 +0200
@@ -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)
--- a/mercurial/changegroup.py	Tue May 14 18:52:52 2013 -0500
+++ b/mercurial/changegroup.py	Fri May 10 20:37:41 2013 +0200
@@ -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()
--- a/mercurial/localrepo.py	Tue May 14 18:52:52 2013 -0500
+++ b/mercurial/localrepo.py	Fri May 10 20:37:41 2013 +0200
@@ -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