Show More
@@ -12,7 +12,7 b' import util' | |||
|
12 | 12 | import cStringIO, os, stat, tarfile, time, zipfile |
|
13 | 13 | import zlib, gzip |
|
14 | 14 | |
|
15 |
def tidyprefix(dest, |
|
|
15 | def tidyprefix(dest, kind, prefix): | |
|
16 | 16 | '''choose prefix to use for names in archive. make sure prefix is |
|
17 | 17 | safe for consumers.''' |
|
18 | 18 | |
@@ -23,7 +23,7 b' def tidyprefix(dest, prefix, suffixes):' | |||
|
23 | 23 | raise ValueError('dest must be string if no prefix') |
|
24 | 24 | prefix = os.path.basename(dest) |
|
25 | 25 | lower = prefix.lower() |
|
26 |
for sfx in |
|
|
26 | for sfx in exts.get(kind, []): | |
|
27 | 27 | if lower.endswith(sfx): |
|
28 | 28 | prefix = prefix[:-len(sfx)] |
|
29 | 29 | break |
@@ -80,9 +80,7 b' class tarit(object):' | |||
|
80 | 80 | if fname: |
|
81 | 81 | self.fileobj.write(fname + '\000') |
|
82 | 82 | |
|
83 |
def __init__(self, dest, |
|
|
84 | self.prefix = tidyprefix(dest, prefix, ['.tar', '.tar.bz2', '.tar.gz', | |
|
85 | '.tgz', '.tbz2']) | |
|
83 | def __init__(self, dest, mtime, kind=''): | |
|
86 | 84 | self.mtime = mtime |
|
87 | 85 | |
|
88 | 86 | def taropen(name, mode, fileobj=None): |
@@ -104,7 +102,7 b' class tarit(object):' | |||
|
104 | 102 | self.z = taropen(name='', mode='w|', fileobj=dest) |
|
105 | 103 | |
|
106 | 104 | def addfile(self, name, mode, islink, data): |
|
107 |
i = tarfile.TarInfo( |
|
|
105 | i = tarfile.TarInfo(name) | |
|
108 | 106 | i.mtime = self.mtime |
|
109 | 107 | i.size = len(data) |
|
110 | 108 | if islink: |
@@ -143,8 +141,7 b' class zipit(object):' | |||
|
143 | 141 | '''write archive to zip file or stream. can write uncompressed, |
|
144 | 142 | or compressed with deflate.''' |
|
145 | 143 | |
|
146 |
def __init__(self, dest, |
|
|
147 | self.prefix = tidyprefix(dest, prefix, ('.zip',)) | |
|
144 | def __init__(self, dest, mtime, compress=True): | |
|
148 | 145 | if not isinstance(dest, str): |
|
149 | 146 | try: |
|
150 | 147 | dest.tell() |
@@ -156,7 +153,7 b' class zipit(object):' | |||
|
156 | 153 | self.date_time = time.gmtime(mtime)[:6] |
|
157 | 154 | |
|
158 | 155 | def addfile(self, name, mode, islink, data): |
|
159 |
i = zipfile.ZipInfo( |
|
|
156 | i = zipfile.ZipInfo(name, self.date_time) | |
|
160 | 157 | i.compress_type = self.z.compression |
|
161 | 158 | # unzip will not honor unix file modes unless file creator is |
|
162 | 159 | # set to unix (id 3). |
@@ -174,9 +171,7 b' class zipit(object):' | |||
|
174 | 171 | class fileit(object): |
|
175 | 172 | '''write archive as files in directory.''' |
|
176 | 173 | |
|
177 |
def __init__(self, name, |
|
|
178 | if prefix: | |
|
179 | raise util.Abort(_('cannot give prefix when archiving to files')) | |
|
174 | def __init__(self, name, mtime): | |
|
180 | 175 | self.basedir = name |
|
181 | 176 | self.opener = util.opener(self.basedir) |
|
182 | 177 | |
@@ -196,9 +191,9 b' class fileit(object):' | |||
|
196 | 191 | archivers = { |
|
197 | 192 | 'files': fileit, |
|
198 | 193 | 'tar': tarit, |
|
199 |
'tbz2': lambda name, |
|
|
200 |
'tgz': lambda name, |
|
|
201 |
'uzip': lambda name, |
|
|
194 | 'tbz2': lambda name, mtime: tarit(name, mtime, 'bz2'), | |
|
195 | 'tgz': lambda name, mtime: tarit(name, mtime, 'gz'), | |
|
196 | 'uzip': lambda name, mtime: zipit(name, mtime, False), | |
|
202 | 197 | 'zip': zipit, |
|
203 | 198 | } |
|
204 | 199 | |
@@ -218,19 +213,25 b' def archive(repo, dest, node, kind, deco' | |||
|
218 | 213 | |
|
219 | 214 | prefix is name of path to put before every archive member.''' |
|
220 | 215 | |
|
216 | if kind == 'files': | |
|
217 | if prefix: | |
|
218 | raise util.Abort(_('cannot give prefix when archiving to files')) | |
|
219 | else: | |
|
220 | prefix = tidyprefix(dest, kind, prefix) | |
|
221 | ||
|
221 | 222 | def write(name, mode, islink, getdata): |
|
222 | 223 | if matchfn and not matchfn(name): |
|
223 | 224 | return |
|
224 | 225 | data = getdata() |
|
225 | 226 | if decode: |
|
226 | 227 | data = repo.wwritedata(name, data) |
|
227 | archiver.addfile(name, mode, islink, data) | |
|
228 | archiver.addfile(prefix + name, mode, islink, data) | |
|
228 | 229 | |
|
229 | 230 | if kind not in archivers: |
|
230 | 231 | raise util.Abort(_("unknown archive type '%s'") % kind) |
|
231 | 232 | |
|
232 | 233 | ctx = repo[node] |
|
233 |
archiver = archivers[kind](dest |
|
|
234 | archiver = archivers[kind](dest, mtime or ctx.date()[0]) | |
|
234 | 235 | |
|
235 | 236 | if repo.ui.configbool("ui", "archivemeta", True): |
|
236 | 237 | def metadata(): |
General Comments 0
You need to be logged in to leave comments.
Login now