Patchwork [6,of,6] upgrade: register compression as a format variants

login
register
mail settings
Submitter Boris Feld
Date Dec. 8, 2017, 10:58 a.m.
Message ID <924805347f2fa830e2f3.1512730685@FB>
Download mbox | patch
Permalink /patch/26094/
State Accepted
Headers show

Comments

Boris Feld - Dec. 8, 2017, 10:58 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1512661848 -3600
#      Thu Dec 07 16:50:48 2017 +0100
# Node ID 924805347f2fa830e2f371b32f3ba85f01debfee
# Parent  02131064aabbd4b3b686c6005070bf3f6baea27b
# EXP-Topic upgrade
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 924805347f2f
upgrade: register compression as a format variants

Compression is a promising vector for speedup, let us make it easier to check
the compression used and upgrade existing repository.

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -284,6 +284,28 @@  class removecldeltachain(formatvariant):
     def fromconfig(repo):
         return True
 
+@registerformatvariant
+class compressionengine(formatvariant):
+    name = 'compression'
+    default = 'zlib'
+
+    description = _('Compresion algorithm used to compress data. '
+                    'Some engine are faster than other')
+
+    upgrademessage = _('revlog content will be recompressed with the new '
+                       'algorithm.')
+
+    @classmethod
+    def fromrepo(cls, repo):
+        for req in repo.requirements:
+            if req.startswith('exp-compression-'):
+                return req.split('-', 2)[2]
+        return 'zlib'
+
+    @classmethod
+    def fromconfig(cls, repo):
+        return repo.ui.config('experimental', 'format.compression')
+
 def finddeficiencies(repo):
     """returns a list of deficiencies that the repo suffer from"""
     deficiencies = []
diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -60,24 +60,28 @@  An upgrade of a repository created with 
   dotencode:      yes
   generaldelta:   yes
   plain-cl-delta: yes
+  compression:    zlib
   $ hg debugformat --verbose
   format-variant repo config default
   fncache:        yes    yes     yes
   dotencode:      yes    yes     yes
   generaldelta:   yes    yes     yes
   plain-cl-delta: yes    yes     yes
+  compression:    zlib   zlib    zlib
   $ hg debugformat --verbose --config format.usegfncache=no
   format-variant repo config default
   fncache:        yes    yes     yes
   dotencode:      yes    yes     yes
   generaldelta:   yes    yes     yes
   plain-cl-delta: yes    yes     yes
+  compression:    zlib   zlib    zlib
   $ hg debugformat --verbose --config format.usegfncache=no --color=debug
   format-variant repo config default
   [formatvariant.name.uptodate|fncache:       ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
   [formatvariant.name.uptodate|dotencode:     ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
   [formatvariant.name.uptodate|generaldelta:  ][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]
   $ hg debugupgraderepo
   (no feature deficiencies found in existing repository)
   performing an upgrade with "--run" will make the following changes:
@@ -131,24 +135,28 @@  Various sub-optimal detections work
   dotencode:       no
   generaldelta:    no
   plain-cl-delta: yes
+  compression:    zlib
   $ hg debugformat --verbose
   format-variant repo config default
   fncache:         no    yes     yes
   dotencode:       no    yes     yes
   generaldelta:    no    yes     yes
   plain-cl-delta: yes    yes     yes
+  compression:    zlib   zlib    zlib
   $ hg debugformat --verbose --config format.usegeneraldelta=no
   format-variant repo config default
   fncache:         no    yes     yes
   dotencode:       no    yes     yes
   generaldelta:    no     no     yes
   plain-cl-delta: yes    yes     yes
+  compression:    zlib   zlib    zlib
   $ 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.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]
   $ hg debugupgraderepo
   repository lacks features recommended by current config options: