Patchwork [1,of,6,V2] changegroup: use a different compression key for BZ in HG10

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 25, 2015, 10:08 p.m.
Message ID <d2f09dec78bd978d52b0.1443218905@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10645/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 25, 2015, 10:08 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1443033210 25200
#      Wed Sep 23 11:33:30 2015 -0700
# Node ID d2f09dec78bd978d52b023b966fd23d11f7e75b6
# Parent  f946c1260035f96aa30052c28e6c68c559677059
changegroup: use a different compression key for BZ in HG10

For "space saving", bundle1 "strip" the first two bytes of the BZ stream since
they always are 'BZ'. So the current code boostrap the uncompressor with 'BZ'.
This hack is impractical in more generic case so we move it in a dedicated
"decompression".

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -161,10 +161,12 @@  class cg1unpacker(object):
         if alg == 'UN':
             alg = None # get more modern without breaking too much
         if not alg in util.decompressors:
             raise util.Abort(_('unknown stream compression type: %s')
                              % alg)
+        if alg == 'BZ':
+            alg = '_truncatedBZ'
         self._stream = util.decompressors[alg](fh)
         self._type = alg
         self.callback = None
     def compressed(self):
         return self._type is not None
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2372,11 +2372,12 @@  def _bz2():
     # we put it back for good measure.
     d.decompress('BZ')
     return d
 
 decompressors = {None: lambda fh: fh,
-                 'BZ': _makedecompressor(_bz2),
+                 '_truncatedBZ': _makedecompressor(_bz2),
+                 'BZ': _makedecompressor(lambda: bz2.BZ2Decompressor()),
                  'GZ': _makedecompressor(lambda: zlib.decompressobj()),
                  }
 # also support the old form by courtesies
 decompressors['UN'] = decompressors[None]