changegroup: consolidate tree manifests sending into cg1packer
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 03 Aug 2018 09:44:30 -0700
changeset 38899 7a154778fb46
parent 38898 67f37e8a5490
child 38900 6e999a2d8fe7
changegroup: consolidate tree manifests sending into cg1packer Previously, we overrode a method to control how manifests were serialized. This method was redefined on cg3packer to send tree manifests. This commit moves the tree manifests sending variation to cg1packer and teaches the cgpacker constructor to control which version to use. After these changes, cg3packer was empty. So it has been removed. Differential Revision: https://phab.mercurial-scm.org/D4081
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Thu Aug 02 18:04:51 2018 -0700
+++ b/mercurial/changegroup.py	Fri Aug 03 09:44:30 2018 -0700
@@ -521,7 +521,7 @@
 
 class cg1packer(object):
     def __init__(self, repo, filematcher, version, builddeltaheader,
-                 manifestsend,
+                 manifestsend, sendtreemanifests,
                  bundlecaps=None):
         """Given a source repo, construct a bundler.
 
@@ -533,6 +533,8 @@
 
         manifestsend is a chunk to send after manifests have been fully emitted.
 
+        sendtreemanifests indicates whether tree manifests should be emitted.
+
         bundlecaps is optional and can be used to specify the set of
         capabilities which can be used to build the bundle. While bundlecaps is
         unused in core Mercurial, extensions rely on this feature to communicate
@@ -544,6 +546,7 @@
         self.version = version
         self._builddeltaheader = builddeltaheader
         self._manifestsend = manifestsend
+        self._sendtreemanifests = sendtreemanifests
 
         # Set of capabilities we can use to build the bundle.
         if bundlecaps is None:
@@ -665,6 +668,23 @@
                                 lookuplinknode, units=_('manifests')):
             yield chunk
 
+    def _packtreemanifests(self, dir, mfnodes, lookuplinknode):
+        """Version of _packmanifests that operates on directory manifests.
+
+        Encodes the directory name in the output so multiple manifests
+        can be sent.
+        """
+        assert self.version == b'03'
+
+        if dir:
+            yield self.fileheader(dir)
+
+        # TODO violates storage abstractions by assuming revlogs.
+        dirlog = self._repo.manifestlog._revlog.dirlog(dir)
+        for chunk in self.group(mfnodes, dirlog, lookuplinknode,
+                                units=_('manifests')):
+            yield chunk
+
     def generate(self, commonrevs, clnodes, fastpathlinkrev, source):
         '''yield a sequence of changegroup chunks (strings)'''
         repo = self._repo
@@ -845,13 +865,14 @@
                 return clnode
             return lookupmflinknode
 
+        fn = (self._packtreemanifests if self._sendtreemanifests
+              else self._packmanifests)
         size = 0
         while tmfnodes:
             dir, nodes = tmfnodes.popitem()
             prunednodes = self.prune(dirlog(dir), nodes, commonrevs)
             if not dir or prunednodes:
-                for x in self._packmanifests(dir, prunednodes,
-                                             makelookupmflinknode(dir, nodes)):
+                for x in fn(dir, prunednodes, makelookupmflinknode(dir, nodes)):
                     size += len(x)
                     yield x
         self._verbosenote(_('%8.i (manifests)\n') % size)
@@ -1100,9 +1121,10 @@
 
 class cg2packer(cg1packer):
     def __init__(self, repo, filematcher, version, builddeltaheader,
-                 manifestsend, bundlecaps=None):
+                 manifestsend, sendtreemanifests, bundlecaps=None):
         super(cg2packer, self).__init__(repo, filematcher, version,
                                         builddeltaheader, manifestsend,
+                                        sendtreemanifests,
                                         bundlecaps=bundlecaps)
 
         if self._reorder is None:
@@ -1150,22 +1172,12 @@
             base = nullrev
         return base
 
-class cg3packer(cg2packer):
-    def _packmanifests(self, dir, mfnodes, lookuplinknode):
-        if dir:
-            yield self.fileheader(dir)
-
-        dirlog = self._repo.manifestlog._revlog.dirlog(dir)
-        for chunk in self.group(mfnodes, dirlog, lookuplinknode,
-                                units=_('manifests')):
-            yield chunk
-
 def _makecg1packer(repo, filematcher, bundlecaps):
     builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack(
         d.node, d.p1node, d.p2node, d.linknode)
 
     return cg1packer(repo, filematcher, b'01', builddeltaheader,
-                     manifestsend=b'',
+                     manifestsend=b'', sendtreemanifests=False,
                      bundlecaps=bundlecaps)
 
 def _makecg2packer(repo, filematcher, bundlecaps):
@@ -1173,15 +1185,15 @@
         d.node, d.p1node, d.p2node, d.basenode, d.linknode)
 
     return cg2packer(repo, filematcher, b'02', builddeltaheader,
-                     manifestsend=b'',
+                     manifestsend=b'', sendtreemanifests=False,
                      bundlecaps=bundlecaps)
 
 def _makecg3packer(repo, filematcher, bundlecaps):
     builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack(
         d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags)
 
-    return cg3packer(repo, filematcher, b'03', builddeltaheader,
-                     manifestsend=closechunk(),
+    return cg2packer(repo, filematcher, b'03', builddeltaheader,
+                     manifestsend=closechunk(), sendtreemanifests=True,
                      bundlecaps=bundlecaps)
 
 _packermap = {'01': (_makecg1packer, cg1unpacker),