##// END OF EJS Templates
util: implement zstd compression engine...
Gregory Szorc -
r30442:41a81067 default
parent child Browse files
Show More
@@ -3197,5 +3197,50 b' class _noopengine(compressionengine):'
3197
3197
3198 compengines.register(_noopengine())
3198 compengines.register(_noopengine())
3199
3199
3200 class _zstdengine(compressionengine):
3201 def name(self):
3202 return 'zstd'
3203
3204 @propertycache
3205 def _module(self):
3206 # Not all installs have the zstd module available. So defer importing
3207 # until first access.
3208 try:
3209 from . import zstd
3210 # Force delayed import.
3211 zstd.__version__
3212 return zstd
3213 except ImportError:
3214 return None
3215
3216 def available(self):
3217 return bool(self._module)
3218
3219 def bundletype(self):
3220 return 'zstd', 'ZS'
3221
3222 def compressstream(self, it, opts=None):
3223 opts = opts or {}
3224 # zstd level 3 is almost always significantly faster than zlib
3225 # while providing no worse compression. It strikes a good balance
3226 # between speed and compression.
3227 level = opts.get('level', 3)
3228
3229 zstd = self._module
3230 z = zstd.ZstdCompressor(level=level).compressobj()
3231 for chunk in it:
3232 data = z.compress(chunk)
3233 if data:
3234 yield data
3235
3236 yield z.flush()
3237
3238 def decompressorreader(self, fh):
3239 zstd = self._module
3240 dctx = zstd.ZstdDecompressor()
3241 return chunkbuffer(dctx.read_from(fh))
3242
3243 compengines.register(_zstdengine())
3244
3200 # convenient shortcut
3245 # convenient shortcut
3201 dst = debugstacktrace
3246 dst = debugstacktrace
@@ -35,17 +35,21 b' bundle w/o type option'
35
35
36 test bundle types
36 test bundle types
37
37
38 $ for t in "None" "bzip2" "gzip" "none-v2" "v2" "v1" "gzip-v1"; do
38 $ testbundle() {
39 > echo % test bundle type $t
39 > echo % test bundle type $1
40 > hg init t$t
40 > hg init t$1
41 > cd t1
41 > cd t1
42 > hg bundle -t $t ../b$t ../t$t
42 > hg bundle -t $1 ../b$1 ../t$1
43 > f -q -B6 -D ../b$t; echo
43 > f -q -B6 -D ../b$1; echo
44 > cd ../t$t
44 > cd ../t$1
45 > hg debugbundle ../b$t
45 > hg debugbundle ../b$1
46 > hg debugbundle --spec ../b$t
46 > hg debugbundle --spec ../b$1
47 > echo
47 > echo
48 > cd ..
48 > cd ..
49 > }
50
51 $ for t in "None" "bzip2" "gzip" "none-v2" "v2" "v1" "gzip-v1"; do
52 > testbundle $t
49 > done
53 > done
50 % test bundle type None
54 % test bundle type None
51 searching for changes
55 searching for changes
@@ -106,6 +110,38 b' test bundle types'
106 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
110 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
107 gzip-v1
111 gzip-v1
108
112
113 #if zstd
114
115 $ for t in "zstd" "zstd-v2"; do
116 > testbundle $t
117 > done
118 % test bundle type zstd
119 searching for changes
120 1 changesets found
121 HG20\x00\x00 (esc)
122 Stream params: sortdict([('Compression', 'ZS')])
123 changegroup -- "sortdict([('version', '02'), ('nbchanges', '1')])"
124 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
125 zstd-v2
126
127 % test bundle type zstd-v2
128 searching for changes
129 1 changesets found
130 HG20\x00\x00 (esc)
131 Stream params: sortdict([('Compression', 'ZS')])
132 changegroup -- "sortdict([('version', '02'), ('nbchanges', '1')])"
133 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
134 zstd-v2
135
136 #else
137
138 zstd is a valid engine but isn't available
139
140 $ hg -R t1 bundle -a -t zstd irrelevant.hg
141 abort: compression engine zstd could not be loaded
142 [255]
143
144 #endif
109
145
110 test garbage file
146 test garbage file
111
147
General Comments 0
You need to be logged in to leave comments. Login now