changeset 38900:6e999a2d8fe7

changegroup: control reordering via constructor argument cg2packer.__init__ exists just to override self._reorder. Let's parameterize this behavior via an argument to the parent's __init__. The logic for self._reorder is kinda wonky. None is used as a special value and the value should be None in some situations. It is probably worth rewriting this logic to make behavior more explicit. This will likely happen as part of future work to control the delta generation process that I have planned. Differential Revision: https://phab.mercurial-scm.org/D4082
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 03 Aug 2018 10:01:58 -0700
parents 7a154778fb46
children 23ae0c07a3e1
files mercurial/changegroup.py
diffstat 1 files changed, 20 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Fri Aug 03 09:44:30 2018 -0700
+++ b/mercurial/changegroup.py	Fri Aug 03 10:01:58 2018 -0700
@@ -520,14 +520,18 @@
     deltachunks = attr.ib()
 
 class cg1packer(object):
-    def __init__(self, repo, filematcher, version, builddeltaheader,
-                 manifestsend, sendtreemanifests,
+    def __init__(self, repo, filematcher, version, allowreorder,
+                 builddeltaheader, manifestsend, sendtreemanifests,
                  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.
 
+        allowreorder controls whether reordering of revisions is allowed.
+        This value is used when ``bundle.reorder`` is ``auto`` or isn't
+        set.
+
         builddeltaheader is a callable that constructs the header for a group
         delta.
 
@@ -552,14 +556,16 @@
         if bundlecaps is None:
             bundlecaps = set()
         self._bundlecaps = bundlecaps
+
         # experimental config: bundle.reorder
         reorder = repo.ui.config('bundle', 'reorder')
         if reorder == 'auto':
-            reorder = None
+            self._reorder = allowreorder
         else:
-            reorder = stringutil.parsebool(reorder)
+            self._reorder = stringutil.parsebool(reorder)
+
         self._repo = repo
-        self._reorder = reorder
+
         if self._repo.ui.verbose and not self._repo.ui.debugflag:
             self._verbosenote = self._repo.ui.note
         else:
@@ -1120,19 +1126,6 @@
         )
 
 class cg2packer(cg1packer):
-    def __init__(self, repo, filematcher, version, builddeltaheader,
-                 manifestsend, sendtreemanifests, bundlecaps=None):
-        super(cg2packer, self).__init__(repo, filematcher, version,
-                                        builddeltaheader, manifestsend,
-                                        sendtreemanifests,
-                                        bundlecaps=bundlecaps)
-
-        if self._reorder is None:
-            # Since generaldelta is directly supported by cg2, reordering
-            # generally doesn't help, so we disable it by default (treating
-            # bundle.reorder=auto just like bundle.reorder=False).
-            self._reorder = False
-
     def deltaparent(self, store, rev, p1, p2, prev):
         # Narrow ellipses mode.
         if util.safehasattr(self, 'full_nodes'):
@@ -1176,7 +1169,8 @@
     builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack(
         d.node, d.p1node, d.p2node, d.linknode)
 
-    return cg1packer(repo, filematcher, b'01', builddeltaheader,
+    return cg1packer(repo, filematcher, b'01', allowreorder=None,
+                     builddeltaheader=builddeltaheader,
                      manifestsend=b'', sendtreemanifests=False,
                      bundlecaps=bundlecaps)
 
@@ -1184,7 +1178,11 @@
     builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack(
         d.node, d.p1node, d.p2node, d.basenode, d.linknode)
 
-    return cg2packer(repo, filematcher, b'02', builddeltaheader,
+    # Since generaldelta is directly supported by cg2, reordering
+    # generally doesn't help, so we disable it by default (treating
+    # bundle.reorder=auto just like bundle.reorder=False).
+    return cg2packer(repo, filematcher, b'02', allowreorder=False,
+                     builddeltaheader=builddeltaheader,
                      manifestsend=b'', sendtreemanifests=False,
                      bundlecaps=bundlecaps)
 
@@ -1192,7 +1190,8 @@
     builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack(
         d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags)
 
-    return cg2packer(repo, filematcher, b'03', builddeltaheader,
+    return cg2packer(repo, filematcher, b'03', allowreorder=False,
+                     builddeltaheader=builddeltaheader,
                      manifestsend=closechunk(), sendtreemanifests=True,
                      bundlecaps=bundlecaps)