Mercurial > hg
comparison mercurial/archival.py @ 48882:640e1cb6a7de
archival: remove GzipFileWithTime
This was required for Python 2 support, which we no longer need to support.
Differential Revision: https://phab.mercurial-scm.org/D12285
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Feb 2022 16:46:05 -0700 |
parents | 6000f5b25c9b |
children | 895085109842 |
comparison
equal
deleted
inserted
replaced
48881:82f1c46cce5c | 48882:640e1cb6a7de |
---|---|
134 | 134 |
135 class tarit(object): | 135 class tarit(object): |
136 """write archive to tar file or stream. can write uncompressed, | 136 """write archive to tar file or stream. can write uncompressed, |
137 or compress with gzip or bzip2.""" | 137 or compress with gzip or bzip2.""" |
138 | 138 |
139 if pycompat.ispy3: | |
140 GzipFileWithTime = gzip.GzipFile # camelcase-required | |
141 else: | |
142 | |
143 class GzipFileWithTime(gzip.GzipFile): | |
144 def __init__(self, *args, **kw): | |
145 timestamp = None | |
146 if 'mtime' in kw: | |
147 timestamp = kw.pop('mtime') | |
148 if timestamp is None: | |
149 self.timestamp = time.time() | |
150 else: | |
151 self.timestamp = timestamp | |
152 gzip.GzipFile.__init__(self, *args, **kw) | |
153 | |
154 def _write_gzip_header(self): | |
155 self.fileobj.write(b'\037\213') # magic header | |
156 self.fileobj.write(b'\010') # compression method | |
157 fname = self.name | |
158 if fname and fname.endswith(b'.gz'): | |
159 fname = fname[:-3] | |
160 flags = 0 | |
161 if fname: | |
162 flags = gzip.FNAME # pytype: disable=module-attr | |
163 self.fileobj.write(pycompat.bytechr(flags)) | |
164 gzip.write32u( # pytype: disable=module-attr | |
165 self.fileobj, int(self.timestamp) | |
166 ) | |
167 self.fileobj.write(b'\002') | |
168 self.fileobj.write(b'\377') | |
169 if fname: | |
170 self.fileobj.write(fname + b'\000') | |
171 | |
172 def __init__(self, dest, mtime, kind=b''): | 139 def __init__(self, dest, mtime, kind=b''): |
173 self.mtime = mtime | 140 self.mtime = mtime |
174 self.fileobj = None | 141 self.fileobj = None |
175 | 142 |
176 def taropen(mode, name=b'', fileobj=None): | 143 def taropen(mode, name=b'', fileobj=None): |
177 if kind == b'gz': | 144 if kind == b'gz': |
178 mode = mode[0:1] | 145 mode = mode[0:1] |
179 if not fileobj: | 146 if not fileobj: |
180 fileobj = open(name, mode + b'b') | 147 fileobj = open(name, mode + b'b') |
181 gzfileobj = self.GzipFileWithTime( | 148 gzfileobj = gzip.GzipFile( |
182 name, | 149 name, |
183 pycompat.sysstr(mode + b'b'), | 150 pycompat.sysstr(mode + b'b'), |
184 zlib.Z_BEST_COMPRESSION, | 151 zlib.Z_BEST_COMPRESSION, |
185 fileobj, | 152 fileobj, |
186 mtime=mtime, | 153 mtime=mtime, |