changegroup: define functions for creating changegroup packers
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 02 Aug 2018 17:29:53 -0700
changeset 38894 19344024a8e1
parent 38893 23d582caae30
child 38895 d7ac49c2353c
changegroup: define functions for creating changegroup packers Currently, we have 3 classes for changegroup generation. Each class handles a specific changegroup format. And each subsequent version's class inherits from the previous one. The interface for the classes is not very well defined and a lot of version-specific behavior is behind overloaded functions. This approach adds complexity and makes changegroup generation difficult to reason about. Upcoming commits will be consolidating these 3 classes so differences between changegroup versions and changegroup generation are controlled by parameters to a single constructor / type rather than by overriding class attributes via inheritance. We begin this process by building dedicated functions for creating each changegroup packer instance. Currently they just call the constructor on the appropriate class. This will soon change. Differential Revision: https://phab.mercurial-scm.org/D4076
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Fri Aug 03 10:05:26 2018 -0700
+++ b/mercurial/changegroup.py	Thu Aug 02 17:29:53 2018 -0700
@@ -1176,11 +1176,20 @@
         return struct.pack(
             self.deltaheader, node, p1n, p2n, basenode, linknode, flags)
 
-_packermap = {'01': (cg1packer, cg1unpacker),
+def _makecg1packer(repo, filematcher, bundlecaps):
+    return cg1packer(repo, filematcher, bundlecaps=bundlecaps)
+
+def _makecg2packer(repo, filematcher, bundlecaps):
+    return cg2packer(repo, filematcher, bundlecaps=bundlecaps)
+
+def _makecg3packer(repo, filematcher, bundlecaps):
+    return cg3packer(repo, filematcher, bundlecaps=bundlecaps)
+
+_packermap = {'01': (_makecg1packer, cg1unpacker),
              # cg2 adds support for exchanging generaldelta
-             '02': (cg2packer, cg2unpacker),
+             '02': (_makecg2packer, cg2unpacker),
              # cg3 adds support for exchanging revlog flags and treemanifests
-             '03': (cg3packer, cg3unpacker),
+             '03': (_makecg3packer, cg3unpacker),
 }
 
 def allsupportedversions(repo):
@@ -1249,8 +1258,8 @@
     filematcher = matchmod.intersectmatchers(repo.narrowmatch(),
                                              filematcher)
 
-    return _packermap[version][0](repo, filematcher=filematcher,
-                                  bundlecaps=bundlecaps)
+    fn = _packermap[version][0]
+    return fn(repo, filematcher, bundlecaps)
 
 def getunbundler(version, fh, alg, extras=None):
     return _packermap[version][1](fh, alg, extras=extras)