compression: display compression level in debugformat
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 02 Apr 2019 11:03:46 -0700
changeset 42045 d7e751ec679e
parent 42044 bb271ec2fbfb
child 42046 4ee906aa7b60
compression: display compression level in debugformat Now that we have options to control the compression level, we teach `hg debugformat` about them. This is a useful information when comparing repositories. Note that we have no trace of the compression level used to store existing deltas. Actually, it would even varies from one delta to another. So we display the currently set value.
mercurial/upgrade.py
tests/test-upgrade-repo.t
--- a/mercurial/upgrade.py	Wed Mar 27 18:35:59 2019 +0100
+++ b/mercurial/upgrade.py	Tue Apr 02 11:03:46 2019 -0700
@@ -334,6 +334,39 @@
     def fromconfig(cls, repo):
         return repo.ui.config('experimental', 'format.compression')
 
+@registerformatvariant
+class compressionlevel(formatvariant):
+    name = 'compression-level'
+    default = 'default'
+
+    description = _('compression level')
+
+    upgrademessage = _('revlog content will be recompressed')
+
+    @classmethod
+    def fromrepo(cls, repo):
+        comp = compressionengine.fromrepo(repo)
+        level = None
+        if comp == 'zlib':
+            level = repo.ui.configint('storage', 'revlog.zlib.level')
+        elif comp == 'zstd':
+            level = repo.ui.configint('storage', 'revlog.zstd.level')
+        if level is None:
+            return 'default'
+        return bytes(level)
+
+    @classmethod
+    def fromconfig(cls, repo):
+        comp = compressionengine.fromconfig(repo)
+        level = None
+        if comp == 'zlib':
+            level = repo.ui.configint('storage', 'revlog.zlib.level')
+        elif comp == 'zstd':
+            level = repo.ui.configint('storage', 'revlog.zstd.level')
+        if level is None:
+            return 'default'
+        return bytes(level)
+
 def finddeficiencies(repo):
     """returns a list of deficiencies that the repo suffer from"""
     deficiencies = []
--- a/tests/test-upgrade-repo.t	Wed Mar 27 18:35:59 2019 +0100
+++ b/tests/test-upgrade-repo.t	Tue Apr 02 11:03:46 2019 -0700
@@ -52,37 +52,41 @@
   $ hg init empty
   $ cd empty
   $ hg debugformat
-  format-variant repo
-  fncache:        yes
-  dotencode:      yes
-  generaldelta:   yes
-  sparserevlog:   yes
-  plain-cl-delta: yes
-  compression:    zlib
+  format-variant    repo
+  fncache:           yes
+  dotencode:         yes
+  generaldelta:      yes
+  sparserevlog:      yes
+  plain-cl-delta:    yes
+  compression:       zlib
+  compression-level: default
   $ hg debugformat --verbose
-  format-variant repo config default
-  fncache:        yes    yes     yes
-  dotencode:      yes    yes     yes
-  generaldelta:   yes    yes     yes
-  sparserevlog:   yes    yes     yes
-  plain-cl-delta: yes    yes     yes
-  compression:    zlib   zlib    zlib
+  format-variant    repo config default
+  fncache:           yes    yes     yes
+  dotencode:         yes    yes     yes
+  generaldelta:      yes    yes     yes
+  sparserevlog:      yes    yes     yes
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
   $ hg debugformat --verbose --config format.usefncache=no
-  format-variant repo config default
-  fncache:        yes     no     yes
-  dotencode:      yes     no     yes
-  generaldelta:   yes    yes     yes
-  sparserevlog:   yes    yes     yes
-  plain-cl-delta: yes    yes     yes
-  compression:    zlib   zlib    zlib
+  format-variant    repo config default
+  fncache:           yes     no     yes
+  dotencode:         yes     no     yes
+  generaldelta:      yes    yes     yes
+  sparserevlog:      yes    yes     yes
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
   $ hg debugformat --verbose --config format.usefncache=no --color=debug
-  format-variant repo config default
-  [formatvariant.name.mismatchconfig|fncache:       ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
-  [formatvariant.name.mismatchconfig|dotencode:     ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|generaldelta:  ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|sparserevlog:  ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|plain-cl-delta:][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|compression:   ][formatvariant.repo.uptodate| zlib][formatvariant.config.default|   zlib][formatvariant.default|    zlib]
+  format-variant    repo config default
+  [formatvariant.name.mismatchconfig|fncache:          ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
+  [formatvariant.name.mismatchconfig|dotencode:        ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|generaldelta:     ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|sparserevlog:     ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|plain-cl-delta:   ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|compression:      ][formatvariant.repo.uptodate| zlib][formatvariant.config.default|   zlib][formatvariant.default|    zlib]
+  [formatvariant.name.uptodate|compression-level:][formatvariant.repo.uptodate| default][formatvariant.config.default| default][formatvariant.default| default]
   $ hg debugformat -Tjson
   [
    {
@@ -120,6 +124,12 @@
     "default": "zlib",
     "name": "compression",
     "repo": "zlib"
+   },
+   {
+    "config": "default",
+    "default": "default",
+    "name": "compression-level",
+    "repo": "default"
    }
   ]
   $ hg debugupgraderepo
@@ -207,37 +217,41 @@
   > EOF
 
   $ hg debugformat
-  format-variant repo
-  fncache:         no
-  dotencode:       no
-  generaldelta:    no
-  sparserevlog:    no
-  plain-cl-delta: yes
-  compression:    zlib
+  format-variant    repo
+  fncache:            no
+  dotencode:          no
+  generaldelta:       no
+  sparserevlog:       no
+  plain-cl-delta:    yes
+  compression:       zlib
+  compression-level: default
   $ hg debugformat --verbose
-  format-variant repo config default
-  fncache:         no    yes     yes
-  dotencode:       no    yes     yes
-  generaldelta:    no    yes     yes
-  sparserevlog:    no    yes     yes
-  plain-cl-delta: yes    yes     yes
-  compression:    zlib   zlib    zlib
+  format-variant    repo config default
+  fncache:            no    yes     yes
+  dotencode:          no    yes     yes
+  generaldelta:       no    yes     yes
+  sparserevlog:       no    yes     yes
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
   $ hg debugformat --verbose --config format.usegeneraldelta=no
-  format-variant repo config default
-  fncache:         no    yes     yes
-  dotencode:       no    yes     yes
-  generaldelta:    no     no     yes
-  sparserevlog:    no     no     yes
-  plain-cl-delta: yes    yes     yes
-  compression:    zlib   zlib    zlib
+  format-variant    repo config default
+  fncache:            no    yes     yes
+  dotencode:          no    yes     yes
+  generaldelta:       no     no     yes
+  sparserevlog:       no     no     yes
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
   $ hg debugformat --verbose --config format.usegeneraldelta=no --color=debug
-  format-variant repo config default
-  [formatvariant.name.mismatchconfig|fncache:       ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.mismatchconfig|dotencode:     ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.mismatchdefault|generaldelta:  ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
-  [formatvariant.name.mismatchdefault|sparserevlog:  ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|plain-cl-delta:][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
-  [formatvariant.name.uptodate|compression:   ][formatvariant.repo.uptodate| zlib][formatvariant.config.default|   zlib][formatvariant.default|    zlib]
+  format-variant    repo config default
+  [formatvariant.name.mismatchconfig|fncache:          ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.mismatchconfig|dotencode:        ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.mismatchdefault|generaldelta:     ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
+  [formatvariant.name.mismatchdefault|sparserevlog:     ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|plain-cl-delta:   ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|compression:      ][formatvariant.repo.uptodate| zlib][formatvariant.config.default|   zlib][formatvariant.default|    zlib]
+  [formatvariant.name.uptodate|compression-level:][formatvariant.repo.uptodate| default][formatvariant.config.default| default][formatvariant.default| default]
   $ hg debugupgraderepo
   repository lacks features recommended by current config options: