Patchwork [1,of,4,V2] changegroup: refactor emitrevision to use a `deltamode` argument

login
register
mail settings
Submitter Boris Feld
Date Oct. 18, 2018, 10:56 a.m.
Message ID <cc7eeac5f0d94e27c527.1539860172@localhost.localdomain>
Download mbox | patch
Permalink /patch/36121/
State Accepted
Headers show

Comments

Boris Feld - Oct. 18, 2018, 10:56 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1539115321 -7200
#      Tue Oct 09 22:02:01 2018 +0200
# Node ID cc7eeac5f0d94e27c527524040f2cd1814c8102b
# Parent  2c0aa02ecd5a05ae76b6345962ee3a0ef773bd8a
# EXP-Topic slim-bundle
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r cc7eeac5f0d9
changegroup: refactor emitrevision to use a `deltamode` argument

This new argument gathers the semantic of `sendfulltext` and `deltaprevious`
in a single value. We are about to introduce a new type of constraints.
Avoiding yet another argument sounds like a plus.

Patch

diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -37,6 +37,10 @@  REVISION_FLAG_EXTSTORED = 1 << 13
 REVISION_FLAGS_KNOWN = (
     REVISION_FLAG_CENSORED | REVISION_FLAG_ELLIPSIS | REVISION_FLAG_EXTSTORED)
 
+CG_DELTAMODE_STD = b'default'
+CG_DELTAMODE_PREV = b'previous'
+CG_DELTAMODE_FULL = b'fulltext'
+
 class ipeerconnection(interfaceutil.Interface):
     """Represents a "connection" to a repository.
 
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2229,6 +2229,12 @@  class revlog(object):
         if nodesorder is None and not self._generaldelta:
             nodesorder = 'storage'
 
+        deltamode = repository.CG_DELTAMODE_STD
+        if deltaprevious:
+            deltamode = repository.CG_DELTAMODE_PREV
+        elif not self._storedeltachains:
+            deltamode = repository.CG_DELTAMODE_FULL
+
         return storageutil.emitrevisions(
             self, nodes, nodesorder, revlogrevisiondelta,
             deltaparentfn=self.deltaparent,
@@ -2236,10 +2242,9 @@  class revlog(object):
             rawsizefn=self.rawsize,
             revdifffn=self.revdiff,
             flagsfn=self.flags,
-            sendfulltext=not self._storedeltachains,
+            deltamode=deltamode,
             revisiondata=revisiondata,
-            assumehaveparentrevisions=assumehaveparentrevisions,
-            deltaprevious=deltaprevious)
+            assumehaveparentrevisions=assumehaveparentrevisions)
 
     DELTAREUSEALWAYS = 'always'
     DELTAREUSESAMEREVS = 'samerevs'
diff --git a/mercurial/utils/storageutil.py b/mercurial/utils/storageutil.py
--- a/mercurial/utils/storageutil.py
+++ b/mercurial/utils/storageutil.py
@@ -21,6 +21,7 @@  from .. import (
     error,
     mdiff,
     pycompat,
+    repository,
 )
 
 _nullhash = hashlib.sha1(nullid)
@@ -268,9 +269,8 @@  def resolvestripinfo(minlinkrev, tiprev,
 
 def emitrevisions(store, nodes, nodesorder, resultcls, deltaparentfn=None,
                   candeltafn=None, rawsizefn=None, revdifffn=None, flagsfn=None,
-                  sendfulltext=False,
-                  revisiondata=False, assumehaveparentrevisions=False,
-                  deltaprevious=False):
+                  deltamode=repository.CG_DELTAMODE_STD,
+                  revisiondata=False, assumehaveparentrevisions=False):
     """Generic implementation of ifiledata.emitrevisions().
 
     Emitting revision data is subtly complex. This function attempts to
@@ -321,14 +321,17 @@  def emitrevisions(store, nodes, nodesord
        Callable receiving a revision number and returns the integer flags
        value for it. If not defined, flags value will be 0.
 
-    ``sendfulltext``
+    ``deltamode``
+       constaint on delta to be sent:
+       * CG_DELTAMODE_STD  - normal mode, try to reuse storage deltas,
+       * CG_DELTAMODE_PREV - only delta against "prev",
+       * CG_DELTAMODE_FULL - only issue full snapshot.
+
        Whether to send fulltext revisions instead of deltas, if allowed.
 
     ``nodesorder``
     ``revisiondata``
     ``assumehaveparentrevisions``
-    ``deltaprevious``
-       See ``ifiledata.emitrevisions()`` interface documentation.
     """
 
     fnode = store.node
@@ -344,7 +347,7 @@  def emitrevisions(store, nodes, nodesord
 
     prevrev = None
 
-    if deltaprevious or assumehaveparentrevisions:
+    if deltamode == repository.CG_DELTAMODE_PREV or assumehaveparentrevisions:
         prevrev = store.parentrevs(revs[0])[0]
 
     # Set of revs available to delta against.
@@ -363,11 +366,11 @@  def emitrevisions(store, nodes, nodesord
             deltaparentrev = nullrev
 
         # Forced delta against previous mode.
-        if deltaprevious:
+        if deltamode == repository.CG_DELTAMODE_PREV:
             baserev = prevrev
 
         # We're instructed to send fulltext. Honor that.
-        elif sendfulltext:
+        elif deltamode == repository.CG_DELTAMODE_FULL:
             baserev = nullrev
 
         # There is a delta in storage. We try to use that because it
@@ -426,7 +429,8 @@  def emitrevisions(store, nodes, nodesord
                         baserevisionsize = len(store.revision(baserev,
                                                               raw=True))
 
-            elif baserev == nullrev and not deltaprevious:
+            elif (baserev == nullrev
+                    and deltamode != repository.CG_DELTAMODE_PREV):
                 revision = store.revision(node, raw=True)
                 available.add(rev)
             else: