Patchwork D8148: revlog-compression: update the config to be a list

login
register
mail settings
Submitter phabricator
Date Feb. 25, 2020, 11:19 p.m.
Message ID <aa4344f62c2bcb94c405615264fa480f@localhost.localdomain>
Download mbox | patch
Permalink /patch/45319/
State Not Applicable
Headers show

Comments

phabricator - Feb. 25, 2020, 11:19 p.m.
marmoute marked an inline comment as done.
marmoute updated this revision to Diff 20303.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8148?vs=20294&id=20303

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8148/new/

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/helptext/config.txt
  mercurial/localrepo.py
  mercurial/upgrade.py
  tests/test-repo-compengines.t

CHANGE DETAILS




To: marmoute, #hg-reviewers, mharbison72
Cc: mharbison72, pulkit, mercurial-devel

Patch

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
@@ -22,10 +22,15 @@ 
 Unknown compression engine to format.compression aborts
 
   $ hg --config format.revlog-compression=unknown init unknown
-  abort: compression engine unknown defined by format.revlog-compression not available
+  abort: compression engines "unknown" defined by format.revlog-compression not available
   (run "hg debuginstall" to list available compression engines)
   [255]
 
+unknown compression engine in a list with known one works fine
+
+  $ hg --config format.revlog-compression=zlib,unknown init zlib-before-unknow
+  $ hg --config format.revlog-compression=unknown,zlib init unknown-before-zlib
+
 A requirement specifying an unknown compression engine results in bail
 
   $ hg init unknownrequirement
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -449,7 +449,14 @@ 
 
     @classmethod
     def fromconfig(cls, repo):
-        return repo.ui.config(b'format', b'revlog-compression')
+        compengines = repo.ui.configlist(b'format', b'revlog-compression')
+        # return the first valid value as the selection code would do
+        for comp in compengines:
+            if comp in util.compengines:
+                return comp
+
+        # no valide compression found lets display it all for clarity
+        return b','.join(compengines)
 
 
 @registerformatvariant
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -3576,14 +3576,17 @@ 
             if ui.configbool(b'format', b'dotencode'):
                 requirements.add(b'dotencode')
 
-    compengine = ui.config(b'format', b'revlog-compression')
-    if compengine not in util.compengines:
+    compengines = ui.configlist(b'format', b'revlog-compression')
+    for compengine in compengines:
+        if compengine in util.compengines:
+            break
+    else:
         raise error.Abort(
             _(
-                b'compression engine %s defined by '
+                b'compression engines %s defined by '
                 b'format.revlog-compression not available'
             )
-            % compengine,
+            % b', '.join(b'"%s"' % e for e in compengines),
             hint=_(
                 b'run "hg debuginstall" to list available '
                 b'compression engines'
@@ -3591,7 +3594,7 @@ 
         )
 
     # zlib is the historical default and doesn't need an explicit requirement.
-    elif compengine == b'zstd':
+    if compengine == b'zstd':
         requirements.add(b'revlog-compression-zstd')
     elif compengine != b'zlib':
         requirements.add(b'exp-compression-%s' % compengine)
diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt
--- a/mercurial/helptext/config.txt
+++ b/mercurial/helptext/config.txt
@@ -888,7 +888,8 @@ 
     Compression algorithm used by revlog. Supported values are `zlib` and
     `zstd`. The `zlib` engine is the historical default of Mercurial. `zstd` is
     a newer format that is usually a net win over `zlib`, operating faster at
-    better compression rates. Use `zstd` to reduce CPU usage.
+    better compression rates. Use `zstd` to reduce CPU usage. Multiple values
+    can be specified, the first available one will be used.
 
     On some systems, the Mercurial installation may lack `zstd` support.
 
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -756,7 +756,7 @@ 
 coreconfigitem(
     b'format',
     b'revlog-compression',
-    default=b'zlib',
+    default=lambda: [b'zlib'],
     alias=[(b'experimental', b'format.compression')],
 )
 coreconfigitem(