Patchwork D4079: changegroup: pass function to build delta header into constructor

login
register
mail settings
Submitter phabricator
Date Aug. 6, 2018, 6:57 a.m.
Message ID <dc367c4e24ee5a361b488983df195b07@localhost.localdomain>
Download mbox | patch
Permalink /patch/33299/
State Not Applicable
Headers show

Comments

phabricator - Aug. 6, 2018, 6:57 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGbd64b8b8f0dd: changegroup: pass function to build delta header into constructor (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4079?vs=9841&id=9955

REVISION DETAIL
  https://phab.mercurial-scm.org/D4079

AFFECTED FILES
  mercurial/changegroup.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -520,14 +520,16 @@ 
     deltachunks = attr.ib()
 
 class cg1packer(object):
-    deltaheader = _CHANGEGROUPV1_DELTA_HEADER
-
-    def __init__(self, repo, filematcher, version, bundlecaps=None):
+    def __init__(self, repo, filematcher, version, builddeltaheader,
+                 bundlecaps=None):
         """Given a source repo, construct a bundler.
 
         filematcher is a matcher that matches on files to include in the
         changegroup. Used to facilitate sparse changegroups.
 
+        builddeltaheader is a callable that constructs the header for a group
+        delta.
+
         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
@@ -537,6 +539,7 @@ 
         self._filematcher = filematcher
 
         self.version = version
+        self._builddeltaheader = builddeltaheader
 
         # Set of capabilities we can use to build the bundle.
         if bundlecaps is None:
@@ -933,9 +936,7 @@ 
         if not delta:
             return
 
-        meta = self.builddeltaheader(delta.node, delta.p1node, delta.p2node,
-                                     delta.basenode, delta.linknode,
-                                     delta.flags)
+        meta = self._builddeltaheader(delta)
         l = len(meta) + sum(len(x) for x in delta.deltachunks)
 
         yield chunkheader(l)
@@ -1096,16 +1097,11 @@ 
             deltachunks=(diffheader, data),
         )
 
-    def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
-        # do nothing with basenode, it is implicitly the previous one in HG10
-        # do nothing with flags, it is implicitly 0 for cg1 and cg2
-        return self.deltaheader.pack(node, p1n, p2n, linknode)
-
 class cg2packer(cg1packer):
-    deltaheader = _CHANGEGROUPV2_DELTA_HEADER
-
-    def __init__(self, repo, filematcher, version, bundlecaps=None):
+    def __init__(self, repo, filematcher, version, builddeltaheader,
+                 bundlecaps=None):
         super(cg2packer, self).__init__(repo, filematcher, version,
+                                        builddeltaheader,
                                         bundlecaps=bundlecaps)
 
         if self._reorder is None:
@@ -1153,13 +1149,7 @@ 
             base = nullrev
         return base
 
-    def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
-        # Do nothing with flags, it is implicitly 0 in cg1 and cg2
-        return self.deltaheader.pack(node, p1n, p2n, basenode, linknode)
-
 class cg3packer(cg2packer):
-    deltaheader = _CHANGEGROUPV3_DELTA_HEADER
-
     def _packmanifests(self, dir, mfnodes, lookuplinknode):
         if dir:
             yield self.fileheader(dir)
@@ -1172,17 +1162,26 @@ 
     def _manifestsdone(self):
         return self.close()
 
-    def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
-        return self.deltaheader.pack(node, p1n, p2n, basenode, linknode, flags)
+def _makecg1packer(repo, filematcher, bundlecaps):
+    builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack(
+        d.node, d.p1node, d.p2node, d.linknode)
 
-def _makecg1packer(repo, filematcher, bundlecaps):
-    return cg1packer(repo, filematcher, b'01', bundlecaps=bundlecaps)
+    return cg1packer(repo, filematcher, b'01', builddeltaheader,
+                     bundlecaps=bundlecaps)
 
 def _makecg2packer(repo, filematcher, bundlecaps):
-    return cg2packer(repo, filematcher, b'02', bundlecaps=bundlecaps)
+    builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack(
+        d.node, d.p1node, d.p2node, d.basenode, d.linknode)
+
+    return cg2packer(repo, filematcher, b'02', builddeltaheader,
+                     bundlecaps=bundlecaps)
 
 def _makecg3packer(repo, filematcher, bundlecaps):
-    return cg3packer(repo, filematcher, b'03', bundlecaps=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,
+                     bundlecaps=bundlecaps)
 
 _packermap = {'01': (_makecg1packer, cg1unpacker),
              # cg2 adds support for exchanging generaldelta