[PATCH 7 of 8 "] compression: introduce an official `zstd-revlog` requirement

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sun Mar 31 11:36:23 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1553707623 -3600
#      Wed Mar 27 18:27:03 2019 +0100
# Node ID 2cfe9983fa92313d58f0420ec62f2341a810343e
# Parent  108e26fa0a97fe5342a1ce246cc4e4c185803454
# EXP-Topic zstd-revlog
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 2cfe9983fa92
compression: introduce an official `zstd-revlog` requirement

This requirement supersede `exp-compression-zstd`. However, we keep support for
the old requirement.

Strictly speaking, we do not need to add a new requirement, there are no logic
change making "new" repo incompatible with mercurial client using a version
that support `exp-compression-zstd`.

The choice to introduce a new requirement is motivated by the following:

* The previous requirement was explicitly "experimental". Using it by default
  could confuse users.

* adding support for a hypothetical third compression engine will requires new
  code, and will comes with its own requirement tool.

* We won't use it as the default for a while since I do not think we support
  zstd on all platform. I can imagine we'll gain another (unrelated but on my
  default) requirement by the time we turn this zstd by default.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -645,6 +645,8 @@ def gathersupportedrequirements(ui):
         engine = util.compengines[name]
         if engine.revlogheader():
             supported.add(b'exp-compression-%s' % name)
+            if engine.name() == 'zstd':
+                supported.add(b'zstd-revlog')
 
     return supported
 
@@ -794,7 +796,13 @@ def resolverevlogstorevfsoptions(ui, req
         options[b'maxchainlen'] = maxchainlen
 
     for r in requirements:
-        if r.startswith(b'exp-compression-'):
+        # we allow multiple compression engine requirement to co-exist because
+        # strickly speaking, revlog seems to support mixed compression style.
+        #
+        # The compression used for new entries will be "the last one"
+        if r == 'zstd-revlog':
+            options[b'compengine'] = 'zstd'
+        elif r.startswith(b'exp-compression-'):
             options[b'compengine'] = r[len(b'exp-compression-'):]
 
     options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level')
@@ -2929,7 +2937,9 @@ def newreporequirements(ui, createopts):
                                  'compression engines'))
 
     # zlib is the historical default and doesn't need an explicit requirement.
-    if compengine != 'zlib':
+    elif compengine == 'zstd':
+        requirements.add('zstd-revlog')
+    elif compengine != 'zlib':
         requirements.add('exp-compression-%s' % compengine)
 
     if scmutil.gdinitconfig(ui):
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -326,6 +326,8 @@ class compressionengine(formatvariant):
     @classmethod
     def fromrepo(cls, repo):
         for req in repo.requirements:
+            if req.startswith('zstd-revlog'):
+                return 'zstd'
             if req.startswith('exp-compression-'):
                 return req.split('-', 2)[2]
         return 'zlib'
diff --git a/tests/test-repo-compengines.t b/tests/test-repo-compengines.t
--- a/tests/test-repo-compengines.t
+++ b/tests/test-repo-compengines.t
@@ -44,12 +44,12 @@ A requirement specifying an unknown comp
   $ cd zstd
   $ cat .hg/requires
   dotencode
-  exp-compression-zstd
   fncache
   generaldelta
   revlogv1
   sparserevlog
   store
+  zstd-revlog
   testonly-simplestore (reposimplestore !)
 
   $ touch foo


More information about the Mercurial-devel mailing list