Mercurial > public > mercurial-scm > hg-stable
diff mercurial/archival.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | eef9a2d67051 |
line wrap: on
line diff
--- a/mercurial/archival.py Sun Oct 06 09:45:02 2019 -0400 +++ b/mercurial/archival.py Sun Oct 06 09:48:39 2019 -0400 @@ -43,7 +43,7 @@ prefix = util.normpath(prefix) else: if not isinstance(dest, bytes): - raise ValueError('dest must be string if no prefix') + raise ValueError(b'dest must be string if no prefix') prefix = os.path.basename(dest) lower = prefix.lower() for sfx in exts.get(kind, []): @@ -52,23 +52,23 @@ break lpfx = os.path.normpath(util.localpath(prefix)) prefix = util.pconvert(lpfx) - if not prefix.endswith('/'): - prefix += '/' + if not prefix.endswith(b'/'): + prefix += b'/' # Drop the leading '.' path component if present, so Windows can read the # zip files (issue4634) - if prefix.startswith('./'): + if prefix.startswith(b'./'): prefix = prefix[2:] - if prefix.startswith('../') or os.path.isabs(lpfx) or '/../' in prefix: - raise error.Abort(_('archive prefix contains illegal components')) + if prefix.startswith(b'../') or os.path.isabs(lpfx) or b'/../' in prefix: + raise error.Abort(_(b'archive prefix contains illegal components')) return prefix exts = { - 'tar': ['.tar'], - 'tbz2': ['.tbz2', '.tar.bz2'], - 'tgz': ['.tgz', '.tar.gz'], - 'zip': ['.zip'], - 'txz': ['.txz', '.tar.xz'], + b'tar': [b'.tar'], + b'tbz2': [b'.tbz2', b'.tar.bz2'], + b'tgz': [b'.tgz', b'.tar.gz'], + b'zip': [b'.zip'], + b'txz': [b'.txz', b'.tar.xz'], } @@ -108,22 +108,22 @@ repo = ctx.repo() opts = { - 'template': repo.ui.config( - 'experimental', 'archivemetatemplate', _defaultmetatemplate + b'template': repo.ui.config( + b'experimental', b'archivemetatemplate', _defaultmetatemplate ) } out = util.stringio() - fm = formatter.formatter(repo.ui, out, 'archive', opts) + fm = formatter.formatter(repo.ui, out, b'archive', opts) fm.startitem() fm.context(ctx=ctx) fm.data(root=_rootctx(repo).hex()) if ctx.rev() is None: - dirty = '' + dirty = b'' if ctx.dirty(missing=True): - dirty = '+' + dirty = b'+' fm.data(dirty=dirty) fm.end() @@ -146,33 +146,33 @@ gzip.GzipFile.__init__(self, *args, **kw) def _write_gzip_header(self): - self.fileobj.write('\037\213') # magic header - self.fileobj.write('\010') # compression method + self.fileobj.write(b'\037\213') # magic header + self.fileobj.write(b'\010') # compression method fname = self.name - if fname and fname.endswith('.gz'): + if fname and fname.endswith(b'.gz'): fname = fname[:-3] flags = 0 if fname: flags = gzip.FNAME self.fileobj.write(pycompat.bytechr(flags)) gzip.write32u(self.fileobj, int(self.timestamp)) - self.fileobj.write('\002') - self.fileobj.write('\377') + self.fileobj.write(b'\002') + self.fileobj.write(b'\377') if fname: - self.fileobj.write(fname + '\000') + self.fileobj.write(fname + b'\000') - def __init__(self, dest, mtime, kind=''): + def __init__(self, dest, mtime, kind=b''): self.mtime = mtime self.fileobj = None - def taropen(mode, name='', fileobj=None): - if kind == 'gz': + def taropen(mode, name=b'', fileobj=None): + if kind == b'gz': mode = mode[0:1] if not fileobj: - fileobj = open(name, mode + 'b') + fileobj = open(name, mode + b'b') gzfileobj = self.GzipFileWithTime( name, - pycompat.sysstr(mode + 'b'), + pycompat.sysstr(mode + b'b'), zlib.Z_BEST_COMPRESSION, fileobj, timestamp=mtime, @@ -185,9 +185,9 @@ return tarfile.open(name, pycompat.sysstr(mode + kind), fileobj) if isinstance(dest, bytes): - self.z = taropen('w:', name=dest) + self.z = taropen(b'w:', name=dest) else: - self.z = taropen('w|', fileobj=dest) + self.z = taropen(b'w|', fileobj=dest) def addfile(self, name, mode, islink, data): name = pycompat.fsdecode(name) @@ -246,7 +246,7 @@ # without this will be extracted with unexpected timestamp, # if TZ is not configured as GMT i.extra += struct.pack( - '<hhBl', + b'<hhBl', 0x5455, # block type: "extended-timestamp" 1 + 4, # size of this block 1, # "modification time is present" @@ -270,7 +270,7 @@ if islink: self.opener.symlink(data, name) return - f = self.opener(name, "w", atomictemp=False) + f = self.opener(name, b"w", atomictemp=False) f.write(data) f.close() destfile = os.path.join(self.basedir, name) @@ -283,13 +283,13 @@ archivers = { - 'files': fileit, - 'tar': tarit, - 'tbz2': lambda name, mtime: tarit(name, mtime, 'bz2'), - 'tgz': lambda name, mtime: tarit(name, mtime, 'gz'), - 'txz': lambda name, mtime: tarit(name, mtime, 'xz'), - 'uzip': lambda name, mtime: zipit(name, mtime, False), - 'zip': zipit, + b'files': fileit, + b'tar': tarit, + b'tbz2': lambda name, mtime: tarit(name, mtime, b'bz2'), + b'tgz': lambda name, mtime: tarit(name, mtime, b'gz'), + b'txz': lambda name, mtime: tarit(name, mtime, b'xz'), + b'uzip': lambda name, mtime: zipit(name, mtime, False), + b'zip': zipit, } @@ -300,7 +300,7 @@ kind, decode=True, match=None, - prefix='', + prefix=b'', mtime=None, subrepos=False, ): @@ -323,12 +323,12 @@ subrepos tells whether to include subrepos. ''' - if kind == 'txz' and not pycompat.ispy3: - raise error.Abort(_('xz compression is only available in Python 3')) + if kind == b'txz' and not pycompat.ispy3: + raise error.Abort(_(b'xz compression is only available in Python 3')) - if kind == 'files': + if kind == b'files': if prefix: - raise error.Abort(_('cannot give prefix when archiving to files')) + raise error.Abort(_(b'cannot give prefix when archiving to files')) else: prefix = tidyprefix(dest, kind, prefix) @@ -339,7 +339,7 @@ archiver.addfile(prefix + name, mode, islink, data) if kind not in archivers: - raise error.Abort(_("unknown archive type '%s'") % kind) + raise error.Abort(_(b"unknown archive type '%s'") % kind) ctx = repo[node] archiver = archivers[kind](dest, mtime or ctx.date()[0]) @@ -347,8 +347,8 @@ if not match: match = scmutil.matchall(repo) - if repo.ui.configbool("ui", "archivemeta"): - name = '.hg_archival.txt' + if repo.ui.configbool(b"ui", b"archivemeta"): + name = b'.hg_archival.txt' if match(name): write(name, 0o644, False, lambda: buildmetadata(ctx)) @@ -360,12 +360,12 @@ repo, [ctx.rev()], scmutil.matchfiles(repo, files) ) progress = repo.ui.makeprogress( - _('archiving'), unit=_('files'), total=total + _(b'archiving'), unit=_(b'files'), total=total ) progress.update(0) for f in files: ff = ctx.flags(f) - write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, ctx[f].data) + write(f, b'x' in ff and 0o755 or 0o644, b'l' in ff, ctx[f].data) progress.increment(item=f) progress.complete() @@ -373,11 +373,11 @@ for subpath in sorted(ctx.substate): sub = ctx.workingsub(subpath) submatch = matchmod.subdirmatcher(subpath, match) - subprefix = prefix + subpath + '/' + subprefix = prefix + subpath + b'/' total += sub.archive(archiver, subprefix, submatch, decode) if total == 0: - raise error.Abort(_('no files match the archive pattern')) + raise error.Abort(_(b'no files match the archive pattern')) archiver.done() return total