comparison mercurial/archival.py @ 45942:89a2afe31e82

formating: upgrade to black 20.8b1 This required a couple of small tweaks to un-confuse black, but now it works. Big formatting changes come from: * Dramatically improved collection-splitting logic upstream * Black having a strong (correct IMO) opinion that """ is better than ''' Differential Revision: https://phab.mercurial-scm.org/D9430
author Augie Fackler <raf@durin42.com>
date Fri, 27 Nov 2020 17:03:29 -0500
parents 3a6ec080b521
children 406a7e629946
comparison
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
35 _UNX_IFREG = 0x8000 35 _UNX_IFREG = 0x8000
36 _UNX_IFLNK = 0xA000 36 _UNX_IFLNK = 0xA000
37 37
38 38
39 def tidyprefix(dest, kind, prefix): 39 def tidyprefix(dest, kind, prefix):
40 '''choose prefix to use for names in archive. make sure prefix is 40 """choose prefix to use for names in archive. make sure prefix is
41 safe for consumers.''' 41 safe for consumers."""
42 42
43 if prefix: 43 if prefix:
44 prefix = util.normpath(prefix) 44 prefix = util.normpath(prefix)
45 else: 45 else:
46 if not isinstance(dest, bytes): 46 if not isinstance(dest, bytes):
130 130
131 return out.getvalue() 131 return out.getvalue()
132 132
133 133
134 class tarit(object): 134 class tarit(object):
135 '''write archive to tar file or stream. can write uncompressed, 135 """write archive to tar file or stream. can write uncompressed,
136 or compress with gzip or bzip2.''' 136 or compress with gzip or bzip2."""
137 137
138 if pycompat.ispy3: 138 if pycompat.ispy3:
139 GzipFileWithTime = gzip.GzipFile # camelcase-required 139 GzipFileWithTime = gzip.GzipFile # camelcase-required
140 else: 140 else:
141 141
183 zlib.Z_BEST_COMPRESSION, 183 zlib.Z_BEST_COMPRESSION,
184 fileobj, 184 fileobj,
185 mtime=mtime, 185 mtime=mtime,
186 ) 186 )
187 self.fileobj = gzfileobj 187 self.fileobj = gzfileobj
188 return tarfile.TarFile.taropen( # pytype: disable=attribute-error 188 return (
189 name, pycompat.sysstr(mode), gzfileobj 189 tarfile.TarFile.taropen( # pytype: disable=attribute-error
190 name, pycompat.sysstr(mode), gzfileobj
191 )
190 ) 192 )
191 else: 193 else:
192 try: 194 try:
193 return tarfile.open( 195 return tarfile.open(
194 name, pycompat.sysstr(mode + kind), fileobj 196 name, pycompat.sysstr(mode + kind), fileobj
222 if self.fileobj: 224 if self.fileobj:
223 self.fileobj.close() 225 self.fileobj.close()
224 226
225 227
226 class zipit(object): 228 class zipit(object):
227 '''write archive to zip file or stream. can write uncompressed, 229 """write archive to zip file or stream. can write uncompressed,
228 or compressed with deflate.''' 230 or compressed with deflate."""
229 231
230 def __init__(self, dest, mtime, compress=True): 232 def __init__(self, dest, mtime, compress=True):
231 if isinstance(dest, bytes): 233 if isinstance(dest, bytes):
232 dest = pycompat.fsdecode(dest) 234 dest = pycompat.fsdecode(dest)
233 self.z = zipfile.ZipFile( 235 self.z = zipfile.ZipFile(
314 match=None, 316 match=None,
315 prefix=b'', 317 prefix=b'',
316 mtime=None, 318 mtime=None,
317 subrepos=False, 319 subrepos=False,
318 ): 320 ):
319 '''create archive of repo as it was at node. 321 """create archive of repo as it was at node.
320 322
321 dest can be name of directory, name of archive file, or file 323 dest can be name of directory, name of archive file, or file
322 object to write archive to. 324 object to write archive to.
323 325
324 kind is type of archive to create. 326 kind is type of archive to create.
331 prefix is name of path to put before every archive member. 333 prefix is name of path to put before every archive member.
332 334
333 mtime is the modified time, in seconds, or None to use the changeset time. 335 mtime is the modified time, in seconds, or None to use the changeset time.
334 336
335 subrepos tells whether to include subrepos. 337 subrepos tells whether to include subrepos.
336 ''' 338 """
337 339
338 if kind == b'txz' and not pycompat.ispy3: 340 if kind == b'txz' and not pycompat.ispy3:
339 raise error.Abort(_(b'xz compression is only available in Python 3')) 341 raise error.Abort(_(b'xz compression is only available in Python 3'))
340 342
341 if kind == b'files': 343 if kind == b'files':