From 9428d1cf40acb90ae2f5f7293668ae72ed191c09 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Tue, 17 Mar 2020 11:04:38 -0700 Subject: [PATCH] delete the custom GzipFileWithTime class Summary: Remove the custom `GzipFileWithTime` class from `mercurial/archival.py` This code was added in 2007. Presumably back then Python's standard `gzip.GzipFile` class did not support the `mtime` argument. However, this argument is present in Python 2.7+, and we don't care about older versions. The custom `GzipFileWithTime` class breaks in Python 3.8 since Python 3.8 added an extra `compresslevel` argument to the internal `_write_gzip_header()` method. Reviewed By: pixelb Differential Revision: D20484845 fbshipit-source-id: 4e381799d8537c97cd1993273c8efd02743531df --- eden/scm/edenscm/mercurial/archival.py | 31 ++------------------------ 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/eden/scm/edenscm/mercurial/archival.py b/eden/scm/edenscm/mercurial/archival.py index 51d00e0fd1..b97628afa7 100644 --- a/eden/scm/edenscm/mercurial/archival.py +++ b/eden/scm/edenscm/mercurial/archival.py @@ -121,33 +121,6 @@ class tarit(object): """write archive to tar file or stream. can write uncompressed, or compress with gzip or bzip2.""" - class GzipFileWithTime(gzip.GzipFile): - def __init__(self, *args, **kw): - timestamp = None - if "timestamp" in kw: - timestamp = kw.pop(r"timestamp") - if timestamp is None: - self.timestamp = time.time() - else: - self.timestamp = timestamp - gzip.GzipFile.__init__(self, *args, **kw) - - def _write_gzip_header(self): - self.fileobj.write(b"\037\213") # magic header - self.fileobj.write(b"\010") # compression method - fname = self.name - if fname and fname.endswith(".gz"): - fname = fname[:-3] - flags = 0 - if fname: - flags = gzip.FNAME - self.fileobj.write(pycompat.encodeutf8(chr(flags))) - gzip.write32u(self.fileobj, int(self.timestamp)) # noqa - self.fileobj.write(b"\002") - self.fileobj.write(b"\377") - if fname: - self.fileobj.write(pycompat.encodeutf8(fname) + b"\000") - def __init__(self, dest, mtime, kind=""): self.mtime = mtime self.fileobj = None @@ -157,8 +130,8 @@ class tarit(object): mode = mode[0] if not fileobj: fileobj = open(name, mode + "b") - gzfileobj = self.GzipFileWithTime( - name, mode + "b", zlib.Z_BEST_COMPRESSION, fileobj, timestamp=mtime + gzfileobj = gzip.GzipFile( + name, mode + "b", zlib.Z_BEST_COMPRESSION, fileobj, mtime=mtime ) self.fileobj = gzfileobj return tarfile.TarFile.taropen(name, mode, gzfileobj)